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 2

Complete solution

Shows how to fix output tools and function tools are not executed in parallel tool call order when end strategy is exhaustive. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

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.

Steps

  1. 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.
  2. https://github.com/pydantic/pydantic-ai/issues/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.

When to use

You are seeing this: https://github.com/pydantic/pydantic-ai/issues/3791: Issue pydantic/pydantic-ai#3791 (closed, 42 comments): ### Description The EndStrategy parameter controls how the final result tool is handled. Use this skill when you run into "Output tools and function tools are not executed in parallel tool call order when end strategy is exhaustive".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Sources

  • https://github.com/pydantic/pydantic-ai/issues/3791:
  • 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/agent_graph.py#L865-L866

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 2 · 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