python-codex 0.5.2__py3-none-any.whl → 0.6.1__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/__init__.py +22 -12
- pycodex/agent.py +89 -74
- pycodex/bootstrap.py +37 -251
- pycodex/cli.py +19 -28
- pycodex/config.py +36 -0
- pycodex/context.py +368 -51
- pycodex/events.py +14 -187
- pycodex/model.py +197 -95
- pycodex/multi_agents.py +401 -0
- pycodex/portable/__init__.py +8 -6
- pycodex/portable/client.py +24 -39
- pycodex/portable/protocol.py +28 -0
- pycodex/portable/server.py +3 -3
- pycodex/prompts/developer_messages.json +13 -0
- pycodex/prompts/goals/budget_limit.md +19 -0
- pycodex/prompts/goals/continuation.md +56 -0
- pycodex/prompts/models.json +1143 -200
- pycodex/protocol.py +81 -15
- pycodex/runtime.py +370 -226
- pycodex/tools/__init__.py +102 -10
- pycodex/tools/agent_tool_schemas.py +0 -38
- pycodex/tools/apply_patch_tool.py +17 -34
- pycodex/tools/base_tool.py +63 -35
- pycodex/tools/clock_manager.py +182 -0
- pycodex/tools/clock_tool.py +58 -187
- pycodex/tools/code_mode_manager.py +165 -246
- pycodex/tools/exec_command_tool.py +0 -18
- pycodex/tools/exec_runtime.py +332 -0
- pycodex/tools/exec_tool.py +74 -31
- pycodex/tools/followup_task_tool.py +44 -0
- pycodex/tools/goal_manager.py +205 -0
- pycodex/tools/goal_tool.py +126 -0
- pycodex/tools/interrupt_agent_tool.py +48 -0
- pycodex/tools/list_agents_tool.py +66 -0
- pycodex/tools/python_tool_schema.py +141 -0
- pycodex/tools/request_permissions_tool.py +1 -0
- pycodex/tools/runtime_services.py +122 -450
- pycodex/tools/send_message_tool.py +42 -0
- pycodex/tools/spawn_agent_tool.py +55 -94
- pycodex/tools/unified_exec_manager.py +26 -35
- pycodex/tools/wait_agent_tool.py +46 -66
- pycodex/tools/wait_tool.py +24 -13
- pycodex/tools/web_search_tool.py +1 -0
- pycodex/utils/codex_config.py +105 -0
- pycodex/utils/compactor.py +4 -0
- pycodex/utils/compat.py +43 -2
- pycodex/utils/doctor.py +5 -4
- pycodex/utils/dotenv.py +0 -7
- pycodex/utils/event_helpers.py +143 -13
- pycodex/utils/history.py +59 -0
- pycodex/utils/session_persist.py +104 -48
- python_codex-0.6.1.dist-info/METADATA +201 -0
- python_codex-0.6.1.dist-info/RECORD +106 -0
- responses_server/__init__.py +2 -0
- responses_server/app.py +10 -7
- responses_server/config.py +6 -12
- responses_server/gemini_api.py +333 -0
- responses_server/messages_api.py +9 -1
- responses_server/payload_processors.py +4 -4
- responses_server/request_translation.py +486 -0
- responses_server/server.py +31 -24
- responses_server/stream_events.py +124 -0
- responses_server/stream_router.py +48 -830
- responses_server/tools/custom_adapter.py +29 -29
- responses_server/tools/web_search.py +3 -0
- responses_server/transport.py +388 -0
- pycodex/tools/close_agent_tool.py +0 -60
- pycodex/tools/exec_runtime.js +0 -161
- pycodex/tools/request_user_input_tool.py +0 -102
- pycodex/tools/resume_agent_tool.py +0 -54
- pycodex/tools/send_input_tool.py +0 -110
- python_codex-0.5.2.dist-info/METADATA +0 -262
- python_codex-0.5.2.dist-info/RECORD +0 -90
- {python_codex-0.5.2.dist-info → python_codex-0.6.1.dist-info}/WHEEL +0 -0
- {python_codex-0.5.2.dist-info → python_codex-0.6.1.dist-info}/entry_points.txt +0 -0
- {python_codex-0.5.2.dist-info → python_codex-0.6.1.dist-info}/licenses/LICENSE +0 -0
pycodex/protocol.py
CHANGED
|
@@ -25,6 +25,10 @@ JSONValue: "TypeAlias" = Any
|
|
|
25
25
|
JSONDict: "TypeAlias" = typing.Dict[str, Any]
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
def qualified_tool_name(name, namespace):
|
|
29
|
+
return name if namespace in (None, "", "functions") else f"{namespace}.{name}"
|
|
30
|
+
|
|
31
|
+
|
|
28
32
|
@dataclass(
|
|
29
33
|
frozen=True,
|
|
30
34
|
)
|
|
@@ -42,6 +46,8 @@ class ToolSpec:
|
|
|
42
46
|
options: "typing.Union[JSONDict, None]" = None
|
|
43
47
|
output_schema: "typing.Union[JSONDict, None]" = None
|
|
44
48
|
supports_parallel: "bool" = True
|
|
49
|
+
namespace: "typing.Union[str, None]" = None
|
|
50
|
+
namespace_description: "str" = ""
|
|
45
51
|
|
|
46
52
|
def serialize(self) -> "JSONDict":
|
|
47
53
|
if self.tool_type == "web_search":
|
|
@@ -85,6 +91,9 @@ class UserMessage:
|
|
|
85
91
|
text: "str"
|
|
86
92
|
role: 'Literal["user"]' = "user"
|
|
87
93
|
id: "typing.Union[str, None]" = None
|
|
94
|
+
# Local history metadata; serialize() is the model-facing representation.
|
|
95
|
+
name: "str" = "user"
|
|
96
|
+
visible: "bool" = True
|
|
88
97
|
|
|
89
98
|
def serialize(self) -> "JSONDict":
|
|
90
99
|
payload = {
|
|
@@ -97,6 +106,52 @@ class UserMessage:
|
|
|
97
106
|
return payload
|
|
98
107
|
|
|
99
108
|
|
|
109
|
+
@dataclass(frozen=True)
|
|
110
|
+
class AgentMessage:
|
|
111
|
+
"""Agent 间的原生输入;加密内容只透传,不转换成用户文本。"""
|
|
112
|
+
|
|
113
|
+
author: "str"
|
|
114
|
+
recipient: "str"
|
|
115
|
+
content_items: "typing.Tuple[JSONDict, ...]"
|
|
116
|
+
id: "typing.Union[str, None]" = None
|
|
117
|
+
internal_chat_message_metadata_passthrough: "typing.Union[JSONDict, None]" = None
|
|
118
|
+
visible: "bool" = False
|
|
119
|
+
|
|
120
|
+
@property
|
|
121
|
+
def text(self) -> "str":
|
|
122
|
+
"""Only the locally readable parts are available for display."""
|
|
123
|
+
return "\n".join(
|
|
124
|
+
part["text"] for part in self.content_items if part["type"] == "input_text"
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
@classmethod
|
|
128
|
+
def from_response_item(cls, payload: "JSONDict") -> "AgentMessage":
|
|
129
|
+
return cls(
|
|
130
|
+
author=payload["author"],
|
|
131
|
+
recipient=payload["recipient"],
|
|
132
|
+
content_items=tuple(deepcopy(payload["content"])),
|
|
133
|
+
id=payload.get("id"),
|
|
134
|
+
internal_chat_message_metadata_passthrough=deepcopy(
|
|
135
|
+
payload.get("internal_chat_message_metadata_passthrough")
|
|
136
|
+
),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
def serialize(self) -> "JSONDict":
|
|
140
|
+
payload = {
|
|
141
|
+
"type": "agent_message",
|
|
142
|
+
"author": self.author,
|
|
143
|
+
"recipient": self.recipient,
|
|
144
|
+
"content": deepcopy(list(self.content_items)),
|
|
145
|
+
}
|
|
146
|
+
if self.id is not None:
|
|
147
|
+
payload["id"] = self.id
|
|
148
|
+
if self.internal_chat_message_metadata_passthrough is not None:
|
|
149
|
+
payload["internal_chat_message_metadata_passthrough"] = deepcopy(
|
|
150
|
+
self.internal_chat_message_metadata_passthrough
|
|
151
|
+
)
|
|
152
|
+
return payload
|
|
153
|
+
|
|
154
|
+
|
|
100
155
|
@dataclass(
|
|
101
156
|
frozen=True,
|
|
102
157
|
)
|
|
@@ -111,6 +166,7 @@ class AssistantMessage:
|
|
|
111
166
|
id: "typing.Union[str, None]" = None
|
|
112
167
|
phase: "typing.Union[str, None]" = None
|
|
113
168
|
content_items: "typing.Union[typing.Tuple[JSONDict, ...], None]" = None
|
|
169
|
+
visible: "bool" = True
|
|
114
170
|
|
|
115
171
|
@classmethod
|
|
116
172
|
def from_response_item(cls, payload: "JSONDict") -> "AssistantMessage":
|
|
@@ -192,19 +248,27 @@ class ToolCall:
|
|
|
192
248
|
raw_arguments: "typing.Union[str, None]" = None
|
|
193
249
|
namespace: "typing.Union[str, None]" = None
|
|
194
250
|
status: "typing.Union[str, None]" = None
|
|
251
|
+
encrypted_function_args: "typing.Union[typing.List[str], None]" = None
|
|
195
252
|
|
|
196
253
|
def serialize(self) -> "JSONDict":
|
|
254
|
+
name = self.name
|
|
255
|
+
namespace = self.namespace
|
|
256
|
+
if "." in name:
|
|
257
|
+
inferred_namespace, name = name.rsplit(".", 1)
|
|
258
|
+
if namespace is not None and namespace != inferred_namespace:
|
|
259
|
+
raise ValueError("tool call namespace does not match its name")
|
|
260
|
+
namespace = inferred_namespace
|
|
197
261
|
if self.tool_type == "custom":
|
|
198
262
|
payload = {
|
|
199
263
|
"type": "custom_tool_call",
|
|
200
|
-
"name":
|
|
264
|
+
"name": name,
|
|
201
265
|
"input": str(self.arguments),
|
|
202
266
|
"call_id": self.call_id,
|
|
203
267
|
}
|
|
204
268
|
else:
|
|
205
269
|
payload = {
|
|
206
270
|
"type": "function_call",
|
|
207
|
-
"name":
|
|
271
|
+
"name": name,
|
|
208
272
|
"arguments": (
|
|
209
273
|
self.raw_arguments
|
|
210
274
|
if self.raw_arguments is not None
|
|
@@ -218,8 +282,10 @@ class ToolCall:
|
|
|
218
282
|
}
|
|
219
283
|
if self.id is not None:
|
|
220
284
|
payload["id"] = self.id
|
|
221
|
-
if
|
|
222
|
-
payload["namespace"] =
|
|
285
|
+
if namespace is not None:
|
|
286
|
+
payload["namespace"] = namespace
|
|
287
|
+
if self.tool_type == "function" and self.encrypted_function_args is not None:
|
|
288
|
+
payload["encrypted_function_args"] = deepcopy(self.encrypted_function_args)
|
|
223
289
|
if self.tool_type == "custom" and self.status is not None:
|
|
224
290
|
payload["status"] = self.status
|
|
225
291
|
return payload
|
|
@@ -259,7 +325,7 @@ class ToolResult:
|
|
|
259
325
|
"""
|
|
260
326
|
|
|
261
327
|
call_id: "str"
|
|
262
|
-
name: "str"
|
|
328
|
+
name: "typing.Union[str, None]"
|
|
263
329
|
output: "JSONValue"
|
|
264
330
|
content_items: "typing.Union[typing.Tuple[JSONDict, ...], None]" = None
|
|
265
331
|
# Local execution metadata; not part of a Responses API input item.
|
|
@@ -288,7 +354,7 @@ class ToolResult:
|
|
|
288
354
|
def serialize(self) -> "JSONDict":
|
|
289
355
|
payload_output: "JSONValue"
|
|
290
356
|
if self.content_items is not None:
|
|
291
|
-
payload_output = list(self.content_items)
|
|
357
|
+
payload_output = deepcopy(list(self.content_items))
|
|
292
358
|
elif isinstance(self.output, str):
|
|
293
359
|
payload_output = self.output
|
|
294
360
|
else:
|
|
@@ -310,19 +376,18 @@ class ToolResult:
|
|
|
310
376
|
}
|
|
311
377
|
if self.id is not None:
|
|
312
378
|
payload["id"] = self.id
|
|
313
|
-
if self.tool_type == "custom":
|
|
314
|
-
payload["name"] = self.name
|
|
379
|
+
if self.tool_type == "custom" and self.name is not None:
|
|
380
|
+
payload["name"] = self.name.rsplit(".", 1)[-1]
|
|
315
381
|
return payload
|
|
316
382
|
|
|
317
383
|
|
|
318
384
|
ConversationItem: "TypeAlias" = typing.Union[
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
],
|
|
385
|
+
UserMessage,
|
|
386
|
+
AgentMessage,
|
|
387
|
+
AssistantMessage,
|
|
388
|
+
ContextMessage,
|
|
389
|
+
ToolCall,
|
|
390
|
+
ReasoningItem,
|
|
326
391
|
ToolResult,
|
|
327
392
|
]
|
|
328
393
|
ModelOutputItem: "TypeAlias" = typing.Union[
|
|
@@ -345,6 +410,7 @@ class Prompt:
|
|
|
345
410
|
base_instructions: "typing.Union[str, None]" = None
|
|
346
411
|
turn_id: "typing.Union[str, None]" = None
|
|
347
412
|
turn_metadata: "typing.Union[JSONDict, None]" = None
|
|
413
|
+
session_id: "typing.Union[str, None]" = None
|
|
348
414
|
|
|
349
415
|
|
|
350
416
|
@dataclass(
|