python-codex 0.5.1__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 (72) 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 +28 -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 +461 -203
  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 -29
  24. pycodex/tools/clock_manager.py +182 -0
  25. pycodex/tools/clock_tool.py +2 -139
  26. pycodex/tools/code_mode_manager.py +165 -246
  27. pycodex/tools/exec_command_tool.py +0 -12
  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 +124 -408
  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 +52 -34
  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 +106 -33
  52. python_codex-0.6.0.dist-info/METADATA +352 -0
  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.1.dist-info/METADATA +0 -235
  69. python_codex-0.5.1.dist-info/RECORD +0 -90
  70. {python_codex-0.5.1.dist-info → python_codex-0.6.0.dist-info}/WHEEL +0 -0
  71. {python_codex-0.5.1.dist-info → python_codex-0.6.0.dist-info}/entry_points.txt +0 -0
  72. {python_codex-0.5.1.dist-info → python_codex-0.6.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,138 +1,19 @@
1
1
  import asyncio
2
- import json
3
- import random
4
2
  import typing
5
3
  from dataclasses import dataclass
6
- from typing import TYPE_CHECKING, Awaitable, Callable
7
-
8
- from ..events import (
9
- CompactCompletedEvent,
10
- CompactFailedEvent,
11
- CompactStartedEvent,
12
- Event,
13
- TurnCompletedEvent,
14
- TurnFailedEvent,
15
- TurnInterruptedEvent,
16
- TurnStartedEvent,
17
- )
18
- from ..protocol import ConversationItem, ToolCall, ToolResult, UserMessage
19
- from ..utils import uuid7_string
20
- from ..utils.compat import Literal
4
+ from typing import Awaitable, Callable
21
5
 
22
- if TYPE_CHECKING:
23
- from ..runtime import AgentRuntime
6
+ from ..events import CompactStartedEvent, TerminalEvent, TurnStartedEvent
7
+ from ..utils.compat import Literal
8
+ from .clock_manager import ClockManager
9
+ from .goal_manager import GoalManager
24
10
 
25
11
  PlanStatus = Literal["pending", "in_progress", "completed"]
26
- AgentStatus = typing.Union[
27
- Literal["pending_init", "running", "shutdown", "not_found"],
28
- typing.Dict[str, typing.Union[str, None]],
29
- ]
30
12
  PlanListener = Callable[[typing.Dict[str, object]], None]
31
- AgentRuntimeBuilder = Callable[
32
- [
33
- typing.Union[str, None],
34
- typing.Union[str, None],
35
- typing.Tuple[ConversationItem, ...],
36
- str,
37
- ],
38
- "AgentRuntime",
39
- ]
40
13
  AsyncJSONHandler = Callable[
41
14
  [typing.Dict[str, object]], Awaitable[typing.Union[typing.Dict[str, object], None]]
42
15
  ]
43
16
 
44
- DEFAULT_AGENT_NICKNAME_CANDIDATES = (
45
- "Bacon",
46
- "Descartes",
47
- "Pascal",
48
- "Fermat",
49
- "Huygens",
50
- "Leibniz",
51
- "Newton",
52
- "Halley",
53
- "Euler",
54
- "Lagrange",
55
- "Laplace",
56
- "Volta",
57
- "Gauss",
58
- "Ampere",
59
- "Faraday",
60
- "Darwin",
61
- "Lovelace",
62
- "Boole",
63
- "Pasteur",
64
- "Maxwell",
65
- "Mendel",
66
- "Curie",
67
- "Planck",
68
- "Tesla",
69
- "Poincare",
70
- "Noether",
71
- "Hilbert",
72
- "Einstein",
73
- "Raman",
74
- "Bohr",
75
- "Turing",
76
- "Hubble",
77
- "Feynman",
78
- "Franklin",
79
- "McClintock",
80
- "Meitner",
81
- "Herschel",
82
- "Linnaeus",
83
- "Wegener",
84
- "Chandrasekhar",
85
- "Sagan",
86
- "Goodall",
87
- "Carson",
88
- "Carver",
89
- "Socrates",
90
- "Plato",
91
- "Aristotle",
92
- "Epicurus",
93
- "Cicero",
94
- "Confucius",
95
- "Mencius",
96
- "Zeno",
97
- "Locke",
98
- "Hume",
99
- "Kant",
100
- "Hegel",
101
- "Kierkegaard",
102
- "Mill",
103
- "Nietzsche",
104
- "Peirce",
105
- "James",
106
- "Dewey",
107
- "Russell",
108
- "Popper",
109
- "Sartre",
110
- "Beauvoir",
111
- "Arendt",
112
- "Rawls",
113
- "Singer",
114
- "Anscombe",
115
- "Parfit",
116
- "Kuhn",
117
- "Boyle",
118
- "Hooke",
119
- "Harvey",
120
- "Dalton",
121
- "Helmholtz",
122
- "Gibbs",
123
- "Lorentz",
124
- "Schrodinger",
125
- "Heisenberg",
126
- "Pauli",
127
- "Dirac",
128
- "Bernoulli",
129
- "Godel",
130
- "Nash",
131
- "Banach",
132
- "Ramanujan",
133
- "Erdos",
134
- )
135
-
136
17
 
137
18
  @dataclass(
138
19
  frozen=True,
@@ -209,297 +90,132 @@ class RequestPermissionsManager:
209
90
  return await handler(payload)
210
91
 
211
92
 
212
- @dataclass
213
- class ManagedAgent:
214
- agent_id: "str"
215
- runtime: '"AgentRuntime"'
216
- nickname: "typing.Union[str, None]" = None
217
- last_status: "AgentStatus" = "pending_init"
218
-
219
-
220
- class SubAgentManager:
93
+ class AgentRuntimeEnvironment:
221
94
  def __init__(self) -> "None":
222
- self._runtime_builder: "typing.Union[AgentRuntimeBuilder, None]" = None
223
- self._agents: "typing.Dict[str, ManagedAgent]" = {}
224
- self._pending_notifications: "typing.List[UserMessage]" = []
225
- self._condition = None
226
- self._available_nicknames: "typing.List[str]" = []
227
- self._nickname_random = random.Random()
228
-
229
- def _get_condition(self):
230
- if self._condition is None:
231
- self._condition = asyncio.Condition()
232
- return self._condition
233
-
234
- def set_runtime_builder(
235
- self, builder: "typing.Union[AgentRuntimeBuilder, None]"
236
- ) -> "None":
237
- self._runtime_builder = builder
238
-
239
- def take_pending_notifications(self) -> "typing.Tuple[UserMessage, ...]":
240
- messages = tuple(self._pending_notifications)
241
- self._pending_notifications.clear()
242
- return messages
243
-
244
- async def spawn_agent(
245
- self,
246
- message: "typing.Union[str, None]",
247
- items: "typing.Union[typing.List[typing.Dict[str, object]], None]",
248
- agent_type: "typing.Union[str, None]",
249
- fork_context: "bool",
250
- model: "typing.Union[str, None]",
251
- reasoning_effort: "typing.Union[str, None]",
252
- history: "typing.Tuple[ConversationItem, ...]",
253
- ) -> "typing.Dict[str, object]":
254
- builder = self._runtime_builder
255
- if builder is None:
256
- raise RuntimeError(
257
- "spawn_agent is unavailable before runtime initialization"
258
- )
259
-
260
- initial_history = _fork_context_history(history) if fork_context else ()
261
- agent_id = uuid7_string()
262
- runtime = builder(model, reasoning_effort, initial_history, agent_id)
263
- await runtime.start()
264
- nickname = self._next_nickname()
265
- managed = ManagedAgent(
266
- agent_id=agent_id,
267
- runtime=runtime,
268
- nickname=nickname,
269
- )
270
- runtime.event_handler = lambda event: self._handle_agent_event(managed, event)
271
- async with self._get_condition():
272
- self._agents[agent_id] = managed
273
- self._condition.notify_all()
274
-
275
- initial_prompt = self._compose_prompt(message, items)
276
- if initial_prompt:
277
- await self.send_input(agent_id, initial_prompt, interrupt=False)
278
-
95
+ self.clock_manager = ClockManager()
96
+ self.goal_manager = GoalManager()
97
+ self.plan_store = PlanStore()
98
+ self.request_user_input_manager = RequestUserInputManager()
99
+ self.request_permissions_manager = RequestPermissionsManager()
100
+ self._resources = {}
101
+ self._restart_handlers = []
102
+ self._close_handlers = []
103
+ self._event_handlers = []
104
+ self._bindings = None
105
+
106
+ def register_resource(self, name, manager, restart=None, close=None, observer=None):
107
+ """Register one shared manager, independently of its callable tools."""
108
+ if name in self._resources or manager in self._resources.values():
109
+ raise ValueError("resource already registered: " + name)
110
+ self._resources[name] = manager
111
+ for handler, handlers in (
112
+ (restart, self._restart_handlers), (close, self._close_handlers),
113
+ (observer, self._event_handlers),
114
+ ):
115
+ if handler is not None:
116
+ handlers.append(handler)
117
+
118
+ def bind(self, invoke, output, changed, request_input, request_permissions):
119
+ self._bindings = (invoke, output, lambda: changed("background_work"))
120
+ self.request_user_input_manager.set_handler(request_input)
121
+ self.request_permissions_manager.set_handler(request_permissions)
122
+ self.plan_store.set_listener(lambda _plan: changed("plan"))
123
+ for manager in self._resources.values():
124
+ manager.bind(*self._bindings)
125
+
126
+ def restart(self):
127
+ for restart in self._restart_handlers:
128
+ restart()
129
+ if self._bindings is not None:
130
+ for manager in self._resources.values():
131
+ manager.bind(*self._bindings)
132
+
133
+ def set_state_listener(self, listener):
134
+ for manager in self._resources.values():
135
+ manager.set_state_listener(listener)
136
+
137
+ def background_work_count(self, after_reply):
138
+ return sum(manager.background_work_count(after_reply) for manager in self._resources.values())
139
+
140
+ def background_work_snapshot(self):
141
+ return [
142
+ dict(item, tool=name)
143
+ for name, manager in self._resources.items()
144
+ for item in manager.background_work_snapshot()
145
+ ]
146
+
147
+ def event_observers(self, event):
148
+ return self._event_handlers if isinstance(
149
+ event, (TerminalEvent, TurnStartedEvent, CompactStartedEvent),
150
+ ) else []
151
+
152
+ def dump_state(self):
153
+ managers = {"clock": self.clock_manager.dump_state()}
154
+ goal = self.goal_manager.dump_state()
155
+ if goal is not None:
156
+ managers["goal"] = goal
279
157
  return {
280
- "agent_id": agent_id,
281
- "nickname": nickname,
158
+ "version": 1,
159
+ "managers": managers,
282
160
  }
283
161
 
284
- async def send_input(
285
- self,
286
- agent_id: "str",
287
- prompt_text: "str",
288
- interrupt: "bool",
289
- ) -> "typing.Dict[str, object]":
290
- managed = self._agents.get(agent_id)
291
- if managed is None:
292
- raise RuntimeError(f"unknown agent: {agent_id}")
293
- if managed.runtime.agent.is_shutdown:
294
- raise RuntimeError(f"agent is shutdown: {agent_id}")
295
-
296
- submission_id, future = await managed.runtime.enqueue_user_turn(
297
- prompt_text,
298
- queue="steer" if interrupt else "enqueue",
162
+ def validate_state(self, state):
163
+ if state is not None:
164
+ if state["version"] != 1:
165
+ raise ValueError("unsupported environment state version")
166
+ self.clock_manager.validate_state(state["managers"]["clock"])
167
+ self.goal_manager.validate_state(state["managers"].get("goal"))
168
+
169
+ def restore_state(self, state):
170
+ self.validate_state(state)
171
+ self.clock_manager.restore_state(
172
+ {"period_m": None} if state is None else state["managers"]["clock"]
299
173
  )
300
- future.add_done_callback(self._submission_finished)
301
- async with self._get_condition():
302
- self._condition.notify_all()
303
- return {"submission_id": submission_id}
304
-
305
- async def resume_agent(self, agent_id: "str") -> "typing.Dict[str, object]":
306
- managed = self._agents.get(agent_id)
307
- if managed is None:
308
- return {"status": "not_found"}
309
- if managed.runtime.agent.is_shutdown:
310
- managed.runtime.resume()
311
- managed.last_status = "pending_init"
312
- await managed.runtime.start()
313
- async with self._get_condition():
314
- self._condition.notify_all()
315
- return {"status": self._status_payload(managed)}
316
-
317
- async def close_agent(self, agent_id: "str") -> "typing.Dict[str, object]":
318
- managed = self._agents.get(agent_id)
319
- if managed is None:
320
- return {"previous_status": "not_found"}
321
- previous_status = self._status_payload(managed)
322
- await managed.runtime.close()
323
- async with self._get_condition():
324
- self._condition.notify_all()
325
- return {"previous_status": previous_status}
326
-
327
- async def shutdown(self) -> "None":
328
- errors = []
329
- for agent_id in tuple(self._agents):
330
- try:
331
- await self.close_agent(agent_id)
332
- except Exception as exc:
333
- errors.append(exc)
334
- if errors:
335
- for error in errors[1:]:
336
- asyncio.get_running_loop().call_exception_handler(
337
- {
338
- "message": "Sub-agent close failed",
339
- "exception": error,
340
- }
341
- )
342
- raise errors[0]
343
-
344
- def _next_nickname(self) -> "str":
345
- if not self._available_nicknames:
346
- self._available_nicknames = list(DEFAULT_AGENT_NICKNAME_CANDIDATES)
347
- self._nickname_random.shuffle(self._available_nicknames)
348
- return self._available_nicknames.pop()
349
-
350
- async def wait_agents(
351
- self,
352
- agent_ids: "typing.List[str]",
353
- timeout_ms: "int" = 30_000,
354
- ) -> "typing.Dict[str, object]":
355
- timeout_seconds = max(timeout_ms, 1) / 1000.0
356
- loop = asyncio.get_running_loop()
357
- deadline = loop.time() + timeout_seconds
358
-
359
- async with self._get_condition():
360
- while True:
361
- snapshot = {
362
- agent_id: self._status_payload(self._agents.get(agent_id))
363
- for agent_id in agent_ids
364
- }
365
- if any(self._is_final_status(status) for status in snapshot.values()):
366
- return {"status": snapshot, "timed_out": False}
367
- remaining = deadline - loop.time()
368
- if remaining <= 0:
369
- return {"status": {}, "timed_out": True}
370
- waiter = asyncio.create_task(self._condition.wait())
371
- try:
372
- done, _pending = await asyncio.wait({waiter}, timeout=remaining)
373
- if not done:
374
- return {"status": {}, "timed_out": True}
375
- await waiter
376
- finally:
377
- if not waiter.done():
378
- waiter.cancel()
379
- # Condition.wait() must reacquire the lock before we leave
380
- # the context. Python 3.6 wait_for() does not await that.
381
- try:
382
- await waiter
383
- except asyncio.CancelledError:
384
- pass
385
-
386
- def _submission_finished(self, future: "asyncio.Future") -> "None":
387
- if not future.cancelled():
388
- future.exception()
389
- asyncio.create_task(self._notify_waiters())
390
-
391
- def _handle_agent_event(self, managed: "ManagedAgent", event: "Event") -> "None":
392
- if isinstance(event, TurnCompletedEvent):
393
- managed.last_status = {"completed": event.output_text}
394
- elif isinstance(event, CompactCompletedEvent):
395
- managed.last_status = {"completed": None}
396
- elif isinstance(event, (TurnFailedEvent, CompactFailedEvent)):
397
- managed.last_status = {
398
- "errored": "{0}: {1}".format(
399
- event.error_type,
400
- event.error,
401
- )
402
- }
403
- elif isinstance(event, TurnInterruptedEvent):
404
- managed.last_status = {"errored": "TurnInterrupted: turn interrupted"}
405
- elif isinstance(event, (TurnStartedEvent, CompactStartedEvent)):
406
- asyncio.create_task(self._notify_waiters())
407
- return
408
- else:
409
- return
410
- self._pending_notifications.append(
411
- UserMessage(
412
- text=(
413
- "<subagent_notification>\n"
414
- + json.dumps(
415
- {
416
- "agent_id": managed.agent_id,
417
- "status": managed.last_status,
418
- },
419
- ensure_ascii=False,
420
- separators=(",", ":"),
421
- )
422
- + "\n</subagent_notification>"
423
- )
424
- )
174
+ self.goal_manager.restore_state(
175
+ None if state is None else state["managers"].get("goal")
425
176
  )
426
- asyncio.create_task(self._notify_waiters())
427
-
428
- async def _notify_waiters(self) -> "None":
429
- async with self._get_condition():
430
- self._condition.notify_all()
431
177
 
432
- def _compose_prompt(
433
- self,
434
- message: "typing.Union[str, None]",
435
- items: "typing.Union[typing.List[typing.Dict[str, object]], None]",
436
- ) -> "str":
437
- parts: "typing.List[str]" = []
438
- if message:
439
- parts.append(message.strip())
440
- for item in items or []:
441
- item_type = str(item.get("type", ""))
442
- if item_type == "text":
443
- text = str(item.get("text", "")).strip()
444
- if text:
445
- parts.append(text)
446
- elif item_type == "image":
447
- image_url = str(item.get("image_url", "")).strip()
448
- if image_url:
449
- parts.append(f"[image] {image_url}")
450
- else:
451
- parts.append(json.dumps(item, ensure_ascii=False))
452
- return "\n\n".join(part for part in parts if part)
453
-
454
- def _status_payload(
455
- self, managed: "typing.Union[ManagedAgent, None]"
456
- ) -> "AgentStatus":
457
- if managed is None:
458
- return "not_found"
459
- agent = managed.runtime.agent
460
- if agent.is_shutdown:
461
- return "shutdown"
462
- if managed.runtime.is_busy:
463
- return "running"
464
- status = managed.last_status
465
- return dict(status) if isinstance(status, dict) else status
466
-
467
- def _is_final_status(self, status: "AgentStatus") -> "bool":
468
- if isinstance(status, str):
469
- return status in {"shutdown", "not_found"}
470
- if isinstance(status, dict):
471
- return "completed" in status or "errored" in status
472
- return False
473
-
474
-
475
- def _fork_context_history(
476
- history: "typing.Tuple[ConversationItem, ...]",
477
- ) -> "typing.Tuple[ConversationItem, ...]":
478
- call_ids = set()
479
- result_ids = set()
480
- for item in history:
481
- if isinstance(item, ToolCall):
482
- call_ids.add(item.call_id)
483
- elif isinstance(item, ToolResult):
484
- result_ids.add(item.call_id)
485
-
486
- paired_call_ids = call_ids & result_ids
487
- filtered = []
488
- for item in history:
489
- if isinstance(item, ToolCall) and item.call_id not in paired_call_ids:
490
- continue
491
- if isinstance(item, ToolResult) and item.call_id not in paired_call_ids:
492
- continue
493
- filtered.append(item)
494
- return tuple(filtered)
495
-
496
-
497
- class AgentRuntimeEnvironment:
498
- def __init__(self) -> "None":
499
- self.plan_store = PlanStore()
500
- self.subagent_manager = SubAgentManager()
501
- self.request_user_input_manager = RequestUserInputManager()
502
- self.request_permissions_manager = RequestPermissionsManager()
178
+ def start(self):
179
+ self.clock_manager.arm_after_reply()
180
+ self.goal_manager.start()
181
+
182
+ def handle_agent_event(self, event):
183
+ self.goal_manager.handle_agent_event(event)
184
+
185
+ def tool_completed(self):
186
+ self.goal_manager.account()
187
+
188
+ def follow_up_messages(self):
189
+ return self.goal_manager.follow_up_messages()
190
+
191
+ def take_continuation(self):
192
+ return self.goal_manager.take_continuation()
193
+
194
+ def shutdown(self, save_state):
195
+ try:
196
+ self.goal_manager.shutdown()
197
+ save_state()
198
+ finally:
199
+ for manager in self._resources.values():
200
+ manager.shutdown()
201
+
202
+ async def close(self):
203
+ await close_resources(self._close_handlers)
204
+
205
+
206
+ async def close_resources(handlers):
207
+ errors = []
208
+ for handler in handlers:
209
+ try:
210
+ await handler()
211
+ except Exception as exc:
212
+ errors.append(exc)
213
+ if errors:
214
+ for error in errors[1:]:
215
+ asyncio.get_running_loop().call_exception_handler(
216
+ {"message": "Session close handler failed", "exception": error}
217
+ )
218
+ raise errors[0]
503
219
 
504
220
 
505
221
  def create_agent_runtime_environment() -> "AgentRuntimeEnvironment":
@@ -0,0 +1,42 @@
1
+ """Deliver a MultiAgentV2 message without starting an idle agent."""
2
+
3
+ from .base_tool import BaseTool
4
+
5
+
6
+ class SendMessageTool(BaseTool):
7
+ name = "send_message"
8
+ namespace = "collaboration"
9
+ namespace_description = "Tools for spawning and managing sub-agents."
10
+ exec_only = False
11
+ description = (
12
+ "Send a message to an existing agent. The message will be delivered "
13
+ "promptly. Does not trigger a new turn."
14
+ )
15
+ input_schema = {
16
+ "type": "object",
17
+ "properties": {
18
+ "target": {
19
+ "type": "string",
20
+ "description": "Relative or canonical task name to message (from spawn_agent).",
21
+ },
22
+ "message": {
23
+ "type": "string",
24
+ "encrypted": True,
25
+ "description": "Message text to queue on the target agent.",
26
+ },
27
+ },
28
+ "required": ["target", "message"],
29
+ "additionalProperties": False,
30
+ }
31
+ supports_parallel = False
32
+
33
+ def __init__(self, agents_manager):
34
+ self._agents_manager = agents_manager
35
+
36
+ async def run(self, context, args):
37
+ if set(args) != {"target", "message"}:
38
+ raise ValueError("expected target and message")
39
+ return await self._agents_manager.send_message(
40
+ context.agent_id, args["target"], args["message"],
41
+ encrypted=context.encrypted_messages,
42
+ )