Skip to content

Agent Zero AI framework

Block final responses from parallel calls

Alessandroa76b0b5b7d5f
diff --git a/helpers/parallel_tools.py b/helpers/parallel_tools.py
index 0b9c9f72a..b4f978b68 100644
--- a/helpers/parallel_tools.py
+++ b/helpers/parallel_tools.py
@@ -31,7 +31,7 @@ CHILD_PARALLEL_TOOL_NAME_KEY = "parallel_tool_name"
DEFAULT_MAX_CALLS = 8
DEFAULT_TIMEOUT_SECONDS = 300
POLL_INTERVAL_SECONDS = 0.5
-DISALLOWED_PARALLEL_TOOLS = {"document_query"}
+DISALLOWED_PARALLEL_TOOLS = {"document_query", "response"}
TERMINAL_STATES = {"success", "error", "cancelled", "timeout"}
JobState = Literal["pending", "running", "success", "error", "cancelled", "timeout"]
diff --git a/helpers/parallel_tools.py.dox.md b/helpers/parallel_tools.py.dox.md
index d2456f2f2..31d4221f7 100644
--- a/helpers/parallel_tools.py.dox.md
+++ b/helpers/parallel_tools.py.dox.md
@@ -25,7 +25,7 @@
- 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_name` and `tool_args` are present; non-contract planning fields such as `thoughts` or `headline` are ignored.
- `tool_calls` should be an array, but normalization also accepts a valid JSON string encoding of that array to recover provider/model stringification.
-- Normalization rejects `document_query` inside `parallel` because document parsing and Q&A fan out into heavier worker/model paths that must run sequentially.
+- Normalization rejects `document_query` and `response` inside `parallel`: document parsing and Q&A must run sequentially, while `response` must remain top-level so it can end the message loop.
- `call_subordinate` jobs 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, including `parallel`.
- 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.
diff --git a/prompts/agent.system.tool.parallel.md b/prompts/agent.system.tool.parallel.md
index b2bdd9909..f9a40d3eb 100644
--- a/prompts/agent.system.tool.parallel.md
+++ b/prompts/agent.system.tool.parallel.md
@@ -9,6 +9,7 @@ Rules:
- do not use for one simple call, dependent steps, ordered steps, shared mutable state, or state/tool-availability changes that must happen in the parent context
- never nest `parallel`
- Never include `document_query` in `tool_calls`; it is too heavy for parallel workers, so call it sequentially.
+- Call `response` only as a top-level tool so it ends the message loop; never wrap it inside `parallel.tool_calls`.
- `call_subordinate` inside `parallel` starts an isolated child chat under the parent chat, not a scheduler task
- use `wait: false` only when you will collect results later with `job_ids`
- if extras list running or ready parallel jobs, collect them before final synthesis
diff --git a/tests/test_parallel_tool.py b/tests/test_parallel_tool.py
index cb8d2a97e..b6cadf001 100644
--- a/tests/test_parallel_tool.py
+++ b/tests/test_parallel_tool.py
@@ -145,13 +145,14 @@ def test_normalize_parallel_tool_calls_rejects_nested_parallel() -> None:
)
-def test_normalize_parallel_tool_calls_rejects_document_query() -> None:
- with pytest.raises(ValueError, match="document_query.*parallel"):
[email protected]("tool_name", ["document_query", "response"])
+def test_normalize_parallel_tool_calls_rejects_disallowed_tools(tool_name: str) -> None:
+ with pytest.raises(ValueError, match=rf"{tool_name}.*parallel"):
parallel_tools.normalize_parallel_tool_calls(
[
{
- "tool_name": "document_query",
- "tool_args": {"document": "/tmp/report.pdf"},
+ "tool_name": tool_name,
+ "tool_args": {},
}
]
)
diff --git a/tests/test_tool_request_normalization.py b/tests/test_tool_request_normalization.py
index e04b9b889..41e628496 100644
--- a/tests/test_tool_request_normalization.py
+++ b/tests/test_tool_request_normalization.py
@@ -174,3 +174,4 @@ def test_parallel_prompt_encourages_mixed_independent_batches() -> None:
assert "even when they use different tools" in prompt
assert "Do not split by tool type" in prompt
assert "Never include `document_query`" in prompt
+ assert "Call `response` only as a top-level tool" in prompt
diff --git a/tools/parallel.py.dox.md b/tools/parallel.py.dox.md
index e2fcdc511..624ec2040 100644
--- a/tools/parallel.py.dox.md
+++ b/tools/parallel.py.dox.md
@@ -23,6 +23,7 @@
- The tool is intended for independent calls only; dependent operations remain sequential.
- Independent calls should share one batch even when they use different tools; split only for dependencies, ordering, shared mutable state, or parent-context state/tool-availability changes.
- `document_query` is intentionally excluded from wrapped calls because it is too heavy for parallel workers and must be called sequentially.
+- `response` is excluded because a wrapped response cannot end the parent message loop; final responses must be top-level calls.
- `action="start"` starts calls and optionally waits according to `wait`.
- `action="await"` waits for requested job IDs until completion or `timeout`; timeout returns running job handles without canceling them.
- `action="collect"` returns completed job results without waiting.