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.
- pycodex/__init__.py +18 -8
- pycodex/agent.py +89 -74
- pycodex/bootstrap.py +27 -239
- pycodex/cli.py +19 -14
- pycodex/config.py +36 -0
- pycodex/context.py +369 -51
- pycodex/events.py +13 -186
- pycodex/model.py +181 -88
- 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 +1069 -140
- pycodex/protocol.py +78 -15
- pycodex/runtime.py +370 -226
- pycodex/tools/__init__.py +100 -7
- 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 +2 -181
- pycodex/tools/code_mode_manager.py +165 -246
- pycodex/tools/exec_command_tool.py +0 -18
- pycodex/tools/exec_runtime.py +381 -0
- pycodex/tools/exec_tool.py +78 -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/request_user_input_tool.py +3 -23
- 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 +2 -2
- pycodex/utils/doctor.py +5 -4
- pycodex/utils/event_helpers.py +143 -13
- pycodex/utils/history.py +33 -0
- pycodex/utils/session_persist.py +78 -36
- {python_codex-0.5.2.dist-info → python_codex-0.6.0.dist-info}/METADATA +117 -27
- python_codex-0.6.0.dist-info/RECORD +106 -0
- responses_server/__init__.py +2 -0
- responses_server/app.py +7 -6
- responses_server/config.py +0 -11
- responses_server/payload_processors.py +4 -4
- responses_server/request_translation.py +480 -0
- responses_server/server.py +31 -24
- responses_server/stream_events.py +124 -0
- responses_server/stream_router.py +33 -830
- responses_server/tools/custom_adapter.py +29 -29
- responses_server/transport.py +332 -0
- pycodex/tools/close_agent_tool.py +0 -60
- pycodex/tools/exec_runtime.js +0 -161
- pycodex/tools/resume_agent_tool.py +0 -54
- pycodex/tools/send_input_tool.py +0 -110
- python_codex-0.5.2.dist-info/RECORD +0 -90
- {python_codex-0.5.2.dist-info → python_codex-0.6.0.dist-info}/WHEEL +0 -0
- {python_codex-0.5.2.dist-info → python_codex-0.6.0.dist-info}/entry_points.txt +0 -0
- {python_codex-0.5.2.dist-info → python_codex-0.6.0.dist-info}/licenses/LICENSE +0 -0
pycodex/tools/clock_tool.py
CHANGED
|
@@ -5,20 +5,9 @@ clock starts counting only after the Agent completes a reply. Every new turn
|
|
|
5
5
|
cancels the pending countdown, and every successful reply starts a fresh one.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
import asyncio
|
|
9
|
-
import math
|
|
10
|
-
import typing
|
|
11
|
-
from datetime import datetime, timedelta
|
|
12
|
-
|
|
13
|
-
from ..events import (
|
|
14
|
-
CompactCompletedEvent,
|
|
15
|
-
CompactStartedEvent,
|
|
16
|
-
Event,
|
|
17
|
-
TurnCompletedEvent,
|
|
18
|
-
TurnStartedEvent,
|
|
19
|
-
)
|
|
20
8
|
from ..protocol import JSONDict, JSONValue
|
|
21
9
|
from .base_tool import BaseTool, ToolContext
|
|
10
|
+
from .clock_manager import ClockManager
|
|
22
11
|
|
|
23
12
|
CLOCK_STATE_OUTPUT_SCHEMA = {
|
|
24
13
|
"type": "object",
|
|
@@ -40,154 +29,8 @@ CLOCK_STATE_OUTPUT_SCHEMA = {
|
|
|
40
29
|
}
|
|
41
30
|
|
|
42
31
|
|
|
43
|
-
def _current_time() -> "str":
|
|
44
|
-
return datetime.now().astimezone().isoformat(timespec="seconds")
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
class ClockManager:
|
|
48
|
-
def __init__(self, seconds_per_minute: "float" = 60.0) -> "None":
|
|
49
|
-
self._seconds_per_minute = seconds_per_minute
|
|
50
|
-
self._period_m: "typing.Union[float, None]" = None
|
|
51
|
-
self._timer_task: "typing.Union[asyncio.Task, None]" = None
|
|
52
|
-
self._generation = 0
|
|
53
|
-
self._next_fire_at = None
|
|
54
|
-
self._state_listener = None
|
|
55
|
-
self._notify_hook: "typing.Union[typing.Callable[[typing.Dict[str, object]], typing.Awaitable[typing.Any]], None]" = (None)
|
|
56
|
-
|
|
57
|
-
def set_notify_hook(
|
|
58
|
-
self,
|
|
59
|
-
callback: "typing.Union[typing.Callable[[typing.Dict[str, object]], typing.Awaitable[typing.Any]], None]",
|
|
60
|
-
) -> "None":
|
|
61
|
-
self._notify_hook = callback
|
|
62
|
-
|
|
63
|
-
def set_state_listener(self, listener):
|
|
64
|
-
self._state_listener = listener
|
|
65
|
-
|
|
66
|
-
def _state_changed(self):
|
|
67
|
-
if self._state_listener is not None:
|
|
68
|
-
self._state_listener()
|
|
69
|
-
|
|
70
|
-
def background_snapshot(self):
|
|
71
|
-
return dict(
|
|
72
|
-
self.snapshot(),
|
|
73
|
-
kind="clock",
|
|
74
|
-
next_fire_at=self._next_fire_at,
|
|
75
|
-
status=(
|
|
76
|
-
"armed" if self._next_fire_at is not None
|
|
77
|
-
else "paused" if self.enabled else "disabled"
|
|
78
|
-
),
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
def set_period(self, value: "object") -> "JSONDict":
|
|
82
|
-
self._cancel_pending()
|
|
83
|
-
if value is None:
|
|
84
|
-
self._period_m = None
|
|
85
|
-
self._state_changed()
|
|
86
|
-
return self.snapshot()
|
|
87
|
-
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
|
88
|
-
raise ValueError("period_m must be a positive finite number or null")
|
|
89
|
-
period_m = float(value)
|
|
90
|
-
if not math.isfinite(period_m) or period_m <= 0:
|
|
91
|
-
raise ValueError("period_m must be a positive finite number or null")
|
|
92
|
-
self._period_m = period_m
|
|
93
|
-
self._state_changed()
|
|
94
|
-
return self.snapshot()
|
|
95
|
-
|
|
96
|
-
def snapshot(self) -> "JSONDict":
|
|
97
|
-
return {
|
|
98
|
-
"enabled": self.enabled,
|
|
99
|
-
"period_m": self._period_m,
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
@property
|
|
103
|
-
def enabled(self) -> "bool":
|
|
104
|
-
return self._period_m is not None
|
|
105
|
-
|
|
106
|
-
@property
|
|
107
|
-
def armed(self) -> "bool":
|
|
108
|
-
return self._next_fire_at is not None
|
|
109
|
-
|
|
110
|
-
def turn_started(self) -> "None":
|
|
111
|
-
self._cancel_pending()
|
|
112
|
-
self._state_changed()
|
|
113
|
-
|
|
114
|
-
def arm_after_reply(self) -> "None":
|
|
115
|
-
self._cancel_pending()
|
|
116
|
-
period_m = self._period_m
|
|
117
|
-
if period_m is None or self._notify_hook is None:
|
|
118
|
-
self._state_changed()
|
|
119
|
-
return
|
|
120
|
-
generation = self._generation
|
|
121
|
-
self._next_fire_at = (
|
|
122
|
-
datetime.now().astimezone()
|
|
123
|
-
+ timedelta(seconds=period_m * self._seconds_per_minute)
|
|
124
|
-
).isoformat()
|
|
125
|
-
self._timer_task = asyncio.create_task(
|
|
126
|
-
self._wait_and_notify(generation, period_m)
|
|
127
|
-
)
|
|
128
|
-
self._timer_task.add_done_callback(
|
|
129
|
-
lambda task: None if task.cancelled() else task.exception()
|
|
130
|
-
)
|
|
131
|
-
self._state_changed()
|
|
132
|
-
|
|
133
|
-
def cancel(self) -> "None":
|
|
134
|
-
self.set_period(None)
|
|
135
|
-
|
|
136
|
-
def _cancel_pending(self) -> "None":
|
|
137
|
-
self._generation += 1
|
|
138
|
-
task = self._timer_task
|
|
139
|
-
self._timer_task = None
|
|
140
|
-
self._next_fire_at = None
|
|
141
|
-
if task is not None and not task.done():
|
|
142
|
-
task.cancel()
|
|
143
|
-
|
|
144
|
-
async def _wait_and_notify(self, generation: "int", period_m: "float") -> "None":
|
|
145
|
-
from ..agent import TurnInterrupted
|
|
146
|
-
|
|
147
|
-
try:
|
|
148
|
-
await asyncio.sleep(period_m * self._seconds_per_minute)
|
|
149
|
-
except asyncio.CancelledError:
|
|
150
|
-
return
|
|
151
|
-
if generation != self._generation or period_m != self._period_m:
|
|
152
|
-
return
|
|
153
|
-
|
|
154
|
-
self._timer_task = None
|
|
155
|
-
self._next_fire_at = None
|
|
156
|
-
self._state_changed()
|
|
157
|
-
callback = self._notify_hook
|
|
158
|
-
if callback is None:
|
|
159
|
-
return
|
|
160
|
-
try:
|
|
161
|
-
started = await callback(
|
|
162
|
-
{
|
|
163
|
-
"type": "clock_tick",
|
|
164
|
-
"period_m": period_m,
|
|
165
|
-
"current_time": _current_time(),
|
|
166
|
-
}
|
|
167
|
-
)
|
|
168
|
-
except TurnInterrupted:
|
|
169
|
-
# The next successful reply will arm the clock after a steer.
|
|
170
|
-
return
|
|
171
|
-
except asyncio.CancelledError:
|
|
172
|
-
raise
|
|
173
|
-
except Exception as exc:
|
|
174
|
-
asyncio.get_running_loop().call_exception_handler(
|
|
175
|
-
{
|
|
176
|
-
"message": "Clock notification failed",
|
|
177
|
-
"exception": exc,
|
|
178
|
-
}
|
|
179
|
-
)
|
|
180
|
-
return
|
|
181
|
-
|
|
182
|
-
if (
|
|
183
|
-
not started
|
|
184
|
-
and generation == self._generation
|
|
185
|
-
and period_m == self._period_m
|
|
186
|
-
):
|
|
187
|
-
self.arm_after_reply()
|
|
188
|
-
|
|
189
|
-
|
|
190
32
|
class ClockTool(BaseTool):
|
|
33
|
+
exec_only = False
|
|
191
34
|
name = "clock"
|
|
192
35
|
description = (
|
|
193
36
|
"Set a periodic clock in minutes, or cancel it with null. After each "
|
|
@@ -214,28 +57,6 @@ class ClockTool(BaseTool):
|
|
|
214
57
|
def __init__(self, manager: "ClockManager") -> "None":
|
|
215
58
|
self._manager = manager
|
|
216
59
|
|
|
217
|
-
def bind_agent(self, agent) -> "None":
|
|
218
|
-
self._manager.set_notify_hook(agent.maybe_invoke)
|
|
219
|
-
|
|
220
|
-
def handle_agent_event(self, event: "Event") -> "None":
|
|
221
|
-
if isinstance(event, (TurnStartedEvent, CompactStartedEvent)):
|
|
222
|
-
self._manager.turn_started()
|
|
223
|
-
elif isinstance(event, (TurnCompletedEvent, CompactCompletedEvent)):
|
|
224
|
-
self._manager.arm_after_reply()
|
|
225
|
-
|
|
226
|
-
def shutdown(self) -> "None":
|
|
227
|
-
self._manager.cancel()
|
|
228
|
-
self._manager.set_notify_hook(None)
|
|
229
|
-
|
|
230
|
-
def background_work_count(self, after_reply: "bool") -> "int":
|
|
231
|
-
return int(self._manager.enabled if after_reply else self._manager.armed)
|
|
232
|
-
|
|
233
|
-
def background_work_snapshot(self):
|
|
234
|
-
return [self._manager.background_snapshot()]
|
|
235
|
-
|
|
236
|
-
def set_state_listener(self, listener):
|
|
237
|
-
self._manager.set_state_listener(listener)
|
|
238
|
-
|
|
239
60
|
async def run(self, context: "ToolContext", args: "JSONDict") -> "JSONValue":
|
|
240
61
|
del context
|
|
241
62
|
if not isinstance(args, dict) or "period_m" not in args:
|