mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-07-09 17:08:29 +00:00
Skip persisted tool-result files for BACKGROUND contexts, remove ephemeral direct parallel worker chat folders during cleanup, and ignore chat directories without chat.json during startup loading. Add focused regressions for background output persistence, parallel worker cleanup, and orphan directory loading.
3.4 KiB
3.4 KiB
parallel_tools.py DOX
Purpose
- Own the shared runtime for parallel tool-call jobs.
- Normalize wrapped tool-call payloads, start background jobs, await or cancel jobs, and render prompt extras for active parallel work.
- Keep this file-level DOX profile synchronized with
parallel_tools.pybecause this directory is intentionally flat.
Ownership
parallel_tools.pyowns the runtime implementation.parallel_tools.py.dox.mdowns durable notes about responsibilities, contracts, side effects, and verification for that implementation.- Public concepts:
NormalizedToolCallParallelJobstart_parallel_jobs(...)await_parallel_jobs(...)cancel_parallel_jobs(...)build_parallel_jobs_extras(...)format_parallel_results(...)
Runtime Contracts
- Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together.
- Wrapped tool-call items must use the same shape as normal tool calls: a tool name plus arguments.
- Normalization accepts full agent-reply-shaped objects when
tool_nameandtool_argsare present; non-contract planning fields such asthoughtsorheadlineare ignored. - Normalization rejects
document_queryinsideparallelbecause document parsing and Q&A fan out into heavier worker/model paths that must run sequentially. call_subordinatejobs run in isolated child chat contexts tagged with parent-chat metadata; they must not be added to the scheduler task list and may use normal child-chat tools, includingparallel.- Direct tool jobs run in isolated background contexts and are blocked from recursively invoking
parallel. - Direct tool background context cleanup removes both the in-memory context and any transient chat folder left on disk.
- Parent-visible child log items are created for each wrapped call so the WebUI can inspect concurrent children separately while the wrapper result remains model-history-only.
- Child tool logs mirror normal tool-call visible args; job ids remain available through wrapper results and prompt extras rather than visible process-step args.
- Job IDs are stable handles for later await, collect, or cancel operations.
- Prompt extras must stay bounded and expose only job IDs, tool names, status, and compact result/error summaries.
Key Concepts
- The parent context stores in-flight jobs under a private data key; collected terminal jobs are removed from that registry.
wait=Truestarts jobs and awaits them before returning until all requested jobs finish or the wait timeout is reached; the timeout stops waiting but does not cancel running jobs.collectreturns already-finished job results without waiting;awaitwaits for requested job IDs.- Canceled jobs should be marked terminal and should stop their background
DeferredTaskwhen cancellation is possible.
Work Guidance
- Keep normalization compatible with provider tool-call envelopes and direct JSON objects.
- Avoid importing heavy runtime modules at import time unless startup behavior is verified.
- Coordinate argument, output, or status changes with
tools/parallel.py, prompt instructions, and tests.
Verification
- Run targeted tests for normalization, recursion guard, prompt extras, and tool result formatting.
- Run a live Agent Zero chat when changing parallel execution, child chat metadata, or subordinate task behavior.
Child DOX Index
No child DOX files.