python-codex 0.6.2__py3-none-any.whl → 0.6.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pycodex/agent.py +7 -0
- pycodex/bootstrap.py +8 -0
- pycodex/context.py +14 -8
- pycodex/model.py +32 -7
- pycodex/prompts/models.json +345 -0
- pycodex/utils/compactor.py +5 -2
- pycodex/utils/http_headers.py +25 -0
- {python_codex-0.6.2.dist-info → python_codex-0.6.3.dist-info}/METADATA +4 -1
- {python_codex-0.6.2.dist-info → python_codex-0.6.3.dist-info}/RECORD +20 -19
- responses_server/app.py +2 -0
- responses_server/config.py +4 -1
- responses_server/gemini_api.py +14 -6
- responses_server/messages_api.py +12 -6
- responses_server/payload_processors.py +1 -1
- responses_server/request_translation.py +55 -13
- responses_server/stream_router.py +9 -0
- responses_server/transport.py +12 -6
- {python_codex-0.6.2.dist-info → python_codex-0.6.3.dist-info}/WHEEL +0 -0
- {python_codex-0.6.2.dist-info → python_codex-0.6.3.dist-info}/entry_points.txt +0 -0
- {python_codex-0.6.2.dist-info → python_codex-0.6.3.dist-info}/licenses/LICENSE +0 -0
pycodex/agent.py
CHANGED
|
@@ -113,6 +113,7 @@ class Agent:
|
|
|
113
113
|
self._parallel_tool_calls = parallel_tool_calls
|
|
114
114
|
self.event_handler = event_handler
|
|
115
115
|
self._history: "typing.List[ConversationItem]" = list(initial_history)
|
|
116
|
+
self.history_revision = uuid7_string()
|
|
116
117
|
# Agent identity stays fixed when resume changes the rollout session.
|
|
117
118
|
self.agent_id = session_id
|
|
118
119
|
self.agent_path = agent_path
|
|
@@ -202,6 +203,7 @@ class Agent:
|
|
|
202
203
|
restored_history = list(resumed["history"])
|
|
203
204
|
self._configure_recording(session_id, resumed["rollout_path"], resume=True)
|
|
204
205
|
self._history = restored_history
|
|
206
|
+
self.history_revision = uuid7_string()
|
|
205
207
|
self.context_manager.reset_history_context()
|
|
206
208
|
self._last_total_usage_tokens = None
|
|
207
209
|
self.is_shutdown = False
|
|
@@ -602,6 +604,10 @@ class Agent:
|
|
|
602
604
|
self.history,
|
|
603
605
|
self.model_client,
|
|
604
606
|
self.context_manager,
|
|
607
|
+
self.tool_registry.model_visible_specs(
|
|
608
|
+
self.context_manager.resolve_code_mode_only(),
|
|
609
|
+
),
|
|
610
|
+
self._parallel_tool_calls,
|
|
605
611
|
handle_compact_stream_event,
|
|
606
612
|
prune_tool_results_on_context_error,
|
|
607
613
|
str(recorder.rollout_path) if recorder is not None else None,
|
|
@@ -611,6 +617,7 @@ class Agent:
|
|
|
611
617
|
if recorder is not None:
|
|
612
618
|
recorder.append_compacted_history(compact_result.history, self._history)
|
|
613
619
|
self._history = list(compact_result.history)
|
|
620
|
+
self.history_revision = uuid7_string()
|
|
614
621
|
self.context_manager.reset_history_context()
|
|
615
622
|
self._last_total_usage_tokens = None
|
|
616
623
|
except Exception as exc:
|
pycodex/bootstrap.py
CHANGED
|
@@ -8,6 +8,7 @@ from .model import (
|
|
|
8
8
|
ResponsesProviderConfig,
|
|
9
9
|
)
|
|
10
10
|
from .utils import get_debug_dir
|
|
11
|
+
from .utils.http_headers import build_http_headers
|
|
11
12
|
|
|
12
13
|
if typing.TYPE_CHECKING:
|
|
13
14
|
from responses_server import ManagedResponseServer
|
|
@@ -121,10 +122,14 @@ def build_model(
|
|
|
121
122
|
)
|
|
122
123
|
os.environ.setdefault(LOCAL_RESPONSES_SERVER_API_KEY_ENV, "dummy")
|
|
123
124
|
elif vllm_endpoint is not None or compat_api != "none":
|
|
125
|
+
headers = build_http_headers(
|
|
126
|
+
provider_config.http_headers, provider_config.env_http_headers,
|
|
127
|
+
)
|
|
124
128
|
if vllm_endpoint:
|
|
125
129
|
managed_server = launch_chat_completion_compat_server(
|
|
126
130
|
vllm_endpoint,
|
|
127
131
|
model_provider="vllm",
|
|
132
|
+
http_headers=headers,
|
|
128
133
|
)
|
|
129
134
|
else:
|
|
130
135
|
managed_server = launch_chat_completion_compat_server(
|
|
@@ -132,6 +137,7 @@ def build_model(
|
|
|
132
137
|
provider_config.api_key_env,
|
|
133
138
|
model_provider=provider_config.provider_name,
|
|
134
139
|
outcomming_api=compat_api,
|
|
140
|
+
http_headers=headers,
|
|
135
141
|
)
|
|
136
142
|
url, key_env = (
|
|
137
143
|
managed_server.base_url,
|
|
@@ -143,6 +149,8 @@ def build_model(
|
|
|
143
149
|
provider_config,
|
|
144
150
|
base_url=url,
|
|
145
151
|
api_key_env=key_env,
|
|
152
|
+
http_headers={} if uses_local_responses_compat else provider_config.http_headers,
|
|
153
|
+
env_http_headers={} if uses_local_responses_compat else provider_config.env_http_headers,
|
|
146
154
|
responses_lite_override=(
|
|
147
155
|
False
|
|
148
156
|
if uses_local_responses_compat
|
pycodex/context.py
CHANGED
|
@@ -10,7 +10,7 @@ from xml.sax.saxutils import escape
|
|
|
10
10
|
import yaml
|
|
11
11
|
|
|
12
12
|
from .utils.codex_config import read_codex_config
|
|
13
|
-
from .utils.model_metadata import model_metadata
|
|
13
|
+
from .utils.model_metadata import load_models_by_slug, model_metadata
|
|
14
14
|
from .protocol import (
|
|
15
15
|
ContextMessage, ConversationItem, JSONDict, Prompt, ToolCall, ToolResult, ToolSpec, UserMessage,
|
|
16
16
|
)
|
|
@@ -88,8 +88,13 @@ class ContextConfig:
|
|
|
88
88
|
multi_agent_hint: "typing.Union[str, None]" = None
|
|
89
89
|
code_mode_only: "typing.Union[bool, None]" = None
|
|
90
90
|
include_environment_context: "bool" = True
|
|
91
|
+
model_slug: "typing.Union[str, None]" = None
|
|
91
92
|
|
|
92
93
|
def __post_init__(self):
|
|
94
|
+
if self.model_slug is not None and (
|
|
95
|
+
not isinstance(self.model_slug, str) or self.model_slug not in load_models_by_slug()
|
|
96
|
+
):
|
|
97
|
+
raise ValueError("model_slug must name an entry in models.json")
|
|
93
98
|
if self.code_mode_only is not None and not isinstance(self.code_mode_only, bool):
|
|
94
99
|
raise ValueError("code_mode_only must be a boolean")
|
|
95
100
|
if (
|
|
@@ -156,6 +161,7 @@ class ContextConfig:
|
|
|
156
161
|
codex_home=codex_home,
|
|
157
162
|
project_doc_max_bytes=_normalize_int(selected.get("project_doc_max_bytes")),
|
|
158
163
|
model=_normalize_text(selected.get("model")),
|
|
164
|
+
model_slug=selected.get("model_slug"),
|
|
159
165
|
model_context_window=_normalize_int(selected.get("model_context_window")),
|
|
160
166
|
model_auto_compact_token_limit=_normalize_int(
|
|
161
167
|
selected.get("model_auto_compact_token_limit")
|
|
@@ -393,11 +399,11 @@ class ContextManager:
|
|
|
393
399
|
def resolve_code_mode_only(self) -> "bool":
|
|
394
400
|
if self.config.code_mode_only is not None:
|
|
395
401
|
return self.config.code_mode_only
|
|
396
|
-
metadata = model_metadata(self.config.model)
|
|
402
|
+
metadata = model_metadata(self.config.model_slug or self.config.model)
|
|
397
403
|
return metadata is not None and metadata.get("tool_mode") == "code_mode_only"
|
|
398
404
|
|
|
399
405
|
def resolve_model_max_context_window(self) -> "typing.Union[int, None]":
|
|
400
|
-
metadata = model_metadata(self.config.model)
|
|
406
|
+
metadata = model_metadata(self.config.model_slug or self.config.model)
|
|
401
407
|
context_window = self.config.model_context_window
|
|
402
408
|
if context_window is None and metadata is not None:
|
|
403
409
|
context_window = _normalize_int(metadata.get("context_window"))
|
|
@@ -407,7 +413,7 @@ class ContextManager:
|
|
|
407
413
|
context_window = self.resolve_model_max_context_window()
|
|
408
414
|
if context_window is None:
|
|
409
415
|
return None
|
|
410
|
-
metadata = model_metadata(self.config.model)
|
|
416
|
+
metadata = model_metadata(self.config.model_slug or self.config.model)
|
|
411
417
|
effective_percent = None
|
|
412
418
|
if metadata is not None:
|
|
413
419
|
effective_percent = _normalize_int(
|
|
@@ -434,7 +440,7 @@ class ContextManager:
|
|
|
434
440
|
if self.config.model_auto_compact_token_limit is not None:
|
|
435
441
|
return self.config.model_auto_compact_token_limit
|
|
436
442
|
|
|
437
|
-
model_slug = self.config.model
|
|
443
|
+
model_slug = self.config.model_slug or self.config.model
|
|
438
444
|
if model_slug is None:
|
|
439
445
|
return None
|
|
440
446
|
metadata = model_metadata(model_slug)
|
|
@@ -443,7 +449,7 @@ class ContextManager:
|
|
|
443
449
|
return _normalize_int(metadata.get("auto_compact_token_limit"))
|
|
444
450
|
|
|
445
451
|
def _resolve_model_instructions(self) -> "typing.Union[str, None]":
|
|
446
|
-
model_slug = self.config.model
|
|
452
|
+
model_slug = self.config.model_slug or self.config.model
|
|
447
453
|
if model_slug is None:
|
|
448
454
|
return None
|
|
449
455
|
metadata = model_metadata(model_slug)
|
|
@@ -493,7 +499,7 @@ class ContextManager:
|
|
|
493
499
|
)
|
|
494
500
|
|
|
495
501
|
def _model_message(self, *keys):
|
|
496
|
-
metadata = model_metadata(self.config.model)
|
|
502
|
+
metadata = model_metadata(self.config.model_slug or self.config.model)
|
|
497
503
|
value = metadata.get("model_messages") if metadata is not None else None
|
|
498
504
|
for key in keys:
|
|
499
505
|
if value is None:
|
|
@@ -630,7 +636,7 @@ class ContextManager:
|
|
|
630
636
|
skill.path_to_skill_md.relative_to(skill.root).as_posix(),
|
|
631
637
|
)
|
|
632
638
|
lines.append(f"- {skill.name}: {skill.description} (file: {path_str})")
|
|
633
|
-
metadata = model_metadata(self.config.model)
|
|
639
|
+
metadata = model_metadata(self.config.model_slug or self.config.model)
|
|
634
640
|
if metadata is None or metadata.get("include_skills_usage_instructions", True):
|
|
635
641
|
lines.append("### How to use skills")
|
|
636
642
|
lines.extend(SKILLS_GUIDANCE.splitlines())
|
pycodex/model.py
CHANGED
|
@@ -17,6 +17,7 @@ from urllib3.exceptions import ReadTimeoutError
|
|
|
17
17
|
|
|
18
18
|
from .utils.compat import Protocol
|
|
19
19
|
from .utils.codex_config import DEFAULT_CODEX_CONFIG_PATH, read_codex_config
|
|
20
|
+
from .utils.http_headers import build_http_headers
|
|
20
21
|
|
|
21
22
|
from .events import (
|
|
22
23
|
AssistantDeltaEvent,
|
|
@@ -26,7 +27,7 @@ from .events import (
|
|
|
26
27
|
TokenCountEvent,
|
|
27
28
|
ToolCalledEvent,
|
|
28
29
|
)
|
|
29
|
-
from .utils.model_metadata import model_metadata
|
|
30
|
+
from .utils.model_metadata import load_models_by_slug, model_metadata
|
|
30
31
|
from .protocol import (
|
|
31
32
|
AssistantMessage,
|
|
32
33
|
JSONDict,
|
|
@@ -113,8 +114,22 @@ class ResponsesProviderConfig:
|
|
|
113
114
|
fallback_cooldown_seconds: "int" = 900
|
|
114
115
|
stream_first_data_timeout_ms: "typing.Union[int, None]" = None
|
|
115
116
|
compat_api: "str" = "none"
|
|
117
|
+
model_slug: "typing.Union[str, None]" = None
|
|
118
|
+
http_headers: "typing.Dict[str, str]" = field(default_factory=dict, repr=False)
|
|
119
|
+
env_http_headers: "typing.Dict[str, str]" = field(default_factory=dict)
|
|
116
120
|
|
|
117
121
|
def __post_init__(self):
|
|
122
|
+
for name in ("http_headers", "env_http_headers"):
|
|
123
|
+
headers = getattr(self, name)
|
|
124
|
+
if not isinstance(headers, dict) or any(
|
|
125
|
+
not isinstance(key, str) or not isinstance(value, str)
|
|
126
|
+
for key, value in headers.items()
|
|
127
|
+
):
|
|
128
|
+
raise ValueError(name + " must be a table of strings")
|
|
129
|
+
if self.model_slug is not None and (
|
|
130
|
+
not isinstance(self.model_slug, str) or self.model_slug not in load_models_by_slug()
|
|
131
|
+
):
|
|
132
|
+
raise ValueError("model_slug must name an entry in models.json")
|
|
118
133
|
if self.compat_api not in ("none", "chat_completions", "messages", "gemini"):
|
|
119
134
|
raise ValueError("compat_api must be none, chat_completions, messages or gemini")
|
|
120
135
|
cooldown = self.fallback_cooldown_seconds
|
|
@@ -186,9 +201,12 @@ class ResponsesProviderConfig:
|
|
|
186
201
|
raise ValueError("fallback_models must be an array of non-empty model IDs")
|
|
187
202
|
return cls(
|
|
188
203
|
model=selected["model"],
|
|
204
|
+
model_slug=selected.get("model_slug"),
|
|
189
205
|
provider_name=provider_name,
|
|
190
206
|
base_url=provider["base_url"],
|
|
191
207
|
api_key_env=api_key_env,
|
|
208
|
+
http_headers=provider.get("http_headers", {}),
|
|
209
|
+
env_http_headers=provider.get("env_http_headers", {}),
|
|
192
210
|
compat_api=compat_api,
|
|
193
211
|
wire_api=wire_api,
|
|
194
212
|
query_params=query_params,
|
|
@@ -228,7 +246,7 @@ class ResponsesProviderConfig:
|
|
|
228
246
|
return max(int(self.stream_idle_timeout_ms), 1) / 1000.0
|
|
229
247
|
|
|
230
248
|
def metadata(self) -> "typing.Union[JSONDict, None]":
|
|
231
|
-
return model_metadata(self.model)
|
|
249
|
+
return model_metadata(self.model_slug or self.model)
|
|
232
250
|
|
|
233
251
|
def use_responses_lite(self) -> "bool":
|
|
234
252
|
if self.responses_lite_override is not None:
|
|
@@ -447,6 +465,9 @@ class ResponsesModelClient:
|
|
|
447
465
|
openai_subagent: "typing.Union[str, None]" = None,
|
|
448
466
|
) -> "None":
|
|
449
467
|
self._config = config
|
|
468
|
+
self._provider_headers = build_http_headers(
|
|
469
|
+
config.http_headers, config.env_http_headers,
|
|
470
|
+
)
|
|
450
471
|
self._timeout_seconds = timeout_seconds
|
|
451
472
|
self._session_id = session_id or uuid7_string()
|
|
452
473
|
self.recording_metadata = ModelRecordingMetadata(originator, config.provider_name)
|
|
@@ -804,7 +825,7 @@ class ResponsesModelClient:
|
|
|
804
825
|
session_id = self._session_id if prompt.session_id is None else prompt.session_id
|
|
805
826
|
use_responses_lite = self._config.use_responses_lite()
|
|
806
827
|
input_items = [item.serialize() for item in prompt.input]
|
|
807
|
-
_filter_audio_inputs(input_items,
|
|
828
|
+
_filter_audio_inputs(input_items, self._config.metadata())
|
|
808
829
|
if use_responses_lite:
|
|
809
830
|
_strip_image_details(input_items)
|
|
810
831
|
|
|
@@ -936,12 +957,15 @@ class ResponsesModelClient:
|
|
|
936
957
|
session_id = self._session_id if prompt.session_id is None else prompt.session_id
|
|
937
958
|
headers = {
|
|
938
959
|
"content-type": "application/json",
|
|
939
|
-
"accept": "text/event-stream",
|
|
940
|
-
"x-client-request-id": session_id,
|
|
941
|
-
"session_id": session_id,
|
|
942
960
|
"originator": self.recording_metadata.originator,
|
|
943
961
|
"user-agent": self._user_agent,
|
|
944
962
|
}
|
|
963
|
+
headers.update(self._provider_headers)
|
|
964
|
+
headers.update({
|
|
965
|
+
"accept": "text/event-stream",
|
|
966
|
+
"x-client-request-id": session_id,
|
|
967
|
+
"session_id": session_id,
|
|
968
|
+
})
|
|
945
969
|
api_key = self._config.api_key()
|
|
946
970
|
if api_key is not None:
|
|
947
971
|
headers["authorization"] = f"Bearer {api_key}"
|
|
@@ -960,10 +984,11 @@ class ResponsesModelClient:
|
|
|
960
984
|
|
|
961
985
|
def _build_model_list_headers(self) -> "typing.Dict[str, str]":
|
|
962
986
|
headers = {
|
|
963
|
-
"accept": "application/json",
|
|
964
987
|
"originator": self.recording_metadata.originator,
|
|
965
988
|
"user-agent": self._user_agent,
|
|
966
989
|
}
|
|
990
|
+
headers.update(self._provider_headers)
|
|
991
|
+
headers["accept"] = "application/json"
|
|
967
992
|
api_key = self._config.api_key()
|
|
968
993
|
if api_key is not None:
|
|
969
994
|
headers["authorization"] = f"Bearer {api_key}"
|