Skip to content

Commit bee76e6

Browse files
authored
Document sequential tool execution (#2858)
1 parent fa3dd3b commit bee76e6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

docs/tools-advanced.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,12 @@ Raising `ModelRetry` also generates a `RetryPromptPart` containing the exception
374374
### Parallel tool calls & concurrency
375375

376376
When a model returns multiple tool calls in one response, Pydantic AI schedules them concurrently using `asyncio.create_task`.
377+
If a tool requires sequential/serial execution, you can pass the [`sequential`][pydantic_ai.tools.ToolDefinition.sequential] flag when registering the tool, or wrap the agent run in the [`with agent.sequential_tool_calls()`][pydantic_ai.agent.AbstractAgent.sequential_tool_calls] context manager.
377378

378379
Async functions are run on the event loop, while sync functions are offloaded to threads. To get the best performance, _always_ use an async function _unless_ you're doing blocking I/O (and there's no way to use a non-blocking library instead) or CPU-bound work (like `numpy` or `scikit-learn` operations), so that simple functions are not offloaded to threads unnecessarily.
379380

380381
!!! note "Limiting tool executions"
381-
You can cap tool executions within a run using [`UsageLimits(tool_calls_limit=...)`](agents.md#usage-limits). The counter increments only after a successful tool invocation. Output tools (used for structured output) are not counted in the `tool_calls` metric.
382+
You can cap tool executions within a run using [`UsageLimits(tool_calls_limit=...)`](agents.md#usage-limits). The counter increments only after a successful tool invocation. Output tools (used for [structured output](output.md)) are not counted in the `tool_calls` metric.
382383

383384
## See Also
384385

0 commit comments

Comments
 (0)