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