Stop harness sub-agents from returning `DeferredToolRequests` to a parent that cannot resolve them
Written by Claude (Douwe's coding agent) at Douwe's request.
Closes #10493
Why we make these changes
A sub-agent whose output_type includes DeferredToolRequests can end its run early so its caller approves tools or supplies deferred results and resumes it. A DynamicWorkflow script or a SubAgents parent cannot do either, but both handed the marker back as if it were output: DynamicWorkflow advertised the marker's schema in the sub-agent signature and returned it to the script as a dict, and SubAgents returned its str() repr to the parent model.
New public surface
None.
User-visible behavior
DynamicWorkflowleavesDeferredToolRequestsout of the sub-agent return types it renders (top-level list/union members only; nested specs and output-mode wrappers are kept as they are). A sub-agent run that ends with it raisesRuntimeErrorin the script, like any other sub-agent failure, with a message naming the sub-agent and why it stopped (sub-agent 'approver' ended with `DeferredToolRequests` because it needs tool approval or deferred tool results; a workflow script cannot resume it, so do the task another way, or without this sub-agent).SubAgentstreats it as a soft outcome, like a timeout or an exhausted budget: the delegation returns a steering message naming the sub-agent and the reason as a normal tool result (not aModelRetry, since delegating the same task again would most likely stop on the same approval), or the delegate'son_failuremessage when set.DelegationEndEvent.outcomeisfailed.- A sub-agent that resolves its own deferred calls (e.g. with
HandleDeferredToolCalls) is unaffected and returns its output as before.
The marker types live in one mapping (_RESUMABLE_OUTPUT_REASONS in pydantic_ai_harness/_sub_agent_output.py), so PendingModelResponse from #10187 is a one-line addition there (type plus reason) for whichever PR merges second.
Verification
tests/harness/dynamic_workflow/test_dynamic_workflow.py:test_signature_leaves_out_deferred_tool_requests(list, union, structured),test_sub_agent_ending_with_deferred_tool_requests_fails_the_call,..._can_be_caught_in_sandbox,test_sub_agent_resolving_its_own_deferred_tool_calls_returns_its_outputtests/harness/subagents/test_subagents.py:test_deferred_tool_requests_returns_steering,test_deferred_tool_requests_with_on_failure_returns_steering,test_deferred_tool_calls_resolved_by_the_sub_agent_return_its_outputtests/harness/subagents/test_events.py:test_deferred_tool_requests_is_failed
The new marker tests fail on main; the HandleDeferredToolCalls tests pin that resolved runs are unaffected.
What changes for existing users
A sub-agent run ending with DeferredToolRequests now fails the workflow call (DynamicWorkflow) or returns a steering message (SubAgents) instead of handing back the marker as a value; nothing else changes.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
- PR title is fit for the release changelog.
š¤ Generated with Claude Code