main
md 63 lines 3.94 KB
Rendered Raw
1 # call_subordinate.py DOX
2
3 ## Purpose
4
5 - Own the `call_subordinate.py` agent tool.
6 - This module delegates work to a subordinate Agent Zero profile and returns its result.
7 - Keep this file-level DOX profile synchronized with `call_subordinate.py` because this directory is intentionally flat.
8
9 ## Ownership
10
11 - `call_subordinate.py` owns the runtime implementation.
12 - `call_subordinate.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation.
13 - Classes:
14 - `Delegation` (`Tool`)
15 - `async execute(self, message=..., reset=..., context_id=..., **kwargs)`
16 - `get_log_object(self)`
17 - Top-level functions:
18 - `_subordinate_profile_labels(agent: Agent) -> dict[str, str]`
19 - `_validate_subordinate_profile(agent: Agent, profile: str) -> str`
20 - `get_or_create_subordinate(...) -> Agent`
21 - `run_subordinate(...) -> str`
22
23 ## Runtime Contracts
24
25 - Tool modules must define `helpers.tool.Tool` subclasses and return `helpers.tool.Response` from `execute(...)`.
26 - Update this file whenever tool arguments, output shape, `break_loop` behavior, intervention handling, prompt instructions, or side effects change.
27 - `Delegation` is a `Tool`.
28 - `Delegation` defines `execute(...)`.
29 - Observed side-effect areas: filesystem writes, settings/state persistence.
30 - `profile`/`agent_profile` values are validated against available profile keys before use; unknown profiles raise `RepairableException` so the agent can retry with a real profile.
31 - Direct and parallel calls use the same creation, continuation, message, history, and persistence functions in this module.
32 - Every fresh child is `Agent(parent.number + 1, ...)` in its own persisted child-chat context, so sibling A1 agents can each create their own A2 descendants without sharing streaming state.
33 - `reset=true` creates a fresh child. `reset=false` continues the caller's default child or the exact child named by `context_id`.
34 - Child context IDs are accepted only when their persisted parent context, parent agent number, and child depth match the caller.
35 - Supplying a different profile for an existing child without creating a fresh child raises `RepairableException` instead of silently changing its profile.
36 - Active parallel children cannot be continued concurrently; await or cancel their job first.
37 - Child contexts inherit the caller's project and selected chat-model override, are saved before execution and again on exit, and remain reusable after model/API failures.
38 - The direct tool result includes `context_id`; parallel job snapshots expose the same stable child ID separately from their per-invocation job ID.
39 - Existing same-context linear subordinates remain reusable for saved-chat compatibility, but new children use child contexts and a private per-parent registry.
40 - Imported dependency areas include: `agent`, `extensions.python.hist_add_tool_result`, `helpers`, `helpers.errors`, `helpers.tool`.
41
42 ## Key Concepts
43
44 - Important called helpers/classes observed in the source: `AgentContext.all`, `projects.get_context_project_name`, `projects.activate_project`, `subagents.get_available_agents_dict`, `RepairableException`, `initialize_agent`, `message_queue.log_user_message`, `persist_chat.save_tmp_chat`, `UserMessage`, `subordinate.monologue`, and `subordinate.history.new_topic`.
45 - Keep request/response, tool, or helper semantics documented here at the same time as source changes.
46
47 ## Work Guidance
48
49 - Keep tool output concise, model-readable, and safe for history persistence.
50 - Coordinate argument or behavior changes with prompt tool instructions and skill guidance.
51 - Respect intervention flow for long-running, external, or user-visible operations.
52
53 ## Verification
54
55 - Run targeted tool and prompt-contract tests for changed behavior; smoke-test agent execution when no focused test exists.
56 - Related tests observed by source search:
57 - `tests/test_default_prompt_budget.py`
58 - `tests/test_subagent_profiles.py`
59 - `tests/test_parallel_tool.py`
60
61 ## Child DOX Index
62
63 No child DOX files.