Skip to content
← Back to activity

Immutable solution version

Output tools and function tools are not executed in parallel tool call order when end strategy is exhaustive

Version 1Sign in to save

Complete solution

How EndStrategy behaves in pydantic-ai (documented from the implementing PR). 'early' (default): if the model returns text plus tool calls, the text is captured as the final output and no tools run; if it returns tool calls ending in an output tool, only the output tool runs and everything else is skipped on success.

Output tools and function tools are not executed in parallel tool call order when end strategy is exhaustive

How EndStrategy behaves in pydantic-ai (documented from the implementing PR). 'early' (default): if the model returns text plus tool calls, the text is captured as the final output and no tools run; if it returns tool calls ending in an output tool, only the output tool runs and everything else is skipped on success. 'exhaustive': text is still returned as final output but the tool calls also run; for a sequence like tool1 -> tool2 -> outputA -> tool3 -> deferredB -> tool4, everything up to the first deferred tool runs (tool1, tool2, outputA, tool3), then execution stops at deferred_B.

Context from the issue

gh:pydantic/pydantic-ai#3791: Issue pydantic/pydantic-ai#3791 (closed, 42 comments): ### Description The EndStrategy parameter controls how the final result tool is handled. It supports two possible values, early and exhaustive. https://github.com/pydantic/pydantic-ai/blob/ad5ba4f17834aaf1469bae8f87c7cb5316e65094/pydanticaislim/pydanticai/agent/init.py#L122-L127 https://github.com/pydantic/pydantic-ai/blob/ad5ba4f17834aaf1469bae8f87c7cb5316e65094/pydanticaislim/pydanticai/agentgraph.py#L865-L866 Both options run output tools before all the other tools. This didn't match with my intuition of how things should work.

Evidence

Issue gh:pydantic/pydantic-ai#3791: the reporter asked: Issue pydantic/pydantic-ai#3791 (closed, 42 comments): ### Description The EndStrategy parameter controls how the final result tool is handled. It supports two possible values, early and exhaustive. https://github.com/pydantic/pydantic-ai/blob/ad5ba4f17834aaf1469bae8f87c7cb5316e65094/pydanticaislim/pydanticai/agent/init.py#L122-L127 https://github.com/pydantic/pydantic-ai/blob/ad5ba4f17834aaf1469bae8f87c7cb5316e65094/pydanticaislim/pydanticai/agentgraph.py#L865-L866 Both options run output tools before all the other tools. This didn't match with my intuition of how things should work. The verified answer was: How EndStrategy behaves in pydantic-ai (documented from the implementing PR). 'early' (default): if the model returns text plus tool calls, the text is captured as the final output and no tools run; if it returns tool calls ending in an output tool, only the output tool runs and everything else is skipped on success. 'exhaustive': text is still returned as final output but the tool calls also run; for a sequence like tool1 -> tool2 -> outputA -> tool3 -> deferredB -> tool4, everything up to the first deferred tool runs (tool1, tool2, outputA, tool3), then execution stops at deferred_B. Evidence thread: https://github.com/pydantic/pydantic-ai/issues/3791

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_K3l8s-jup6j9HrHsq-ElXg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Output tools and function tools are not executed in parallel tool call order when end strategy is exhaustive <span>— Vectle</span></a>

Output tools and function tools are not executed in parallel tool call order when end strategy is exhaustive | Vectle