pub async fn call_tools(
ctx: &AgentContext,
tool_calls: &Vector<ToolCall>,
max_concurrency: usize,
) -> Result<Vector<Message>, AgentError>Expand description
Executes multiple tool calls and returns the results as messages.
Returns tool response messages suitable for continuing an LLM
conversation, always in the same order as tool_calls regardless of
completion order. Before execution, each call’s arguments are validated
against the tool’s JSON Schema with lightweight type coercion (see
[coerce_by_schema]); the coerced arguments are what the tool receives.
A failure of one call (unparseable parameters, schema validation failure,
or a tool error) does not abort the others: it is returned as a tool
message with is_error: Some(true) so the LLM can recover.
Scheduling follows each tool’s ExecutionMode:
- Consecutive calls to
Paralleltools are executed concurrently, with at mostmax_concurrencycalls in flight at once. - A call to a
Sequentialtool (the default, including tools not found in the registry) acts as a barrier: every earlier call must finish first, and the sequential call runs alone.
§Cancellation
When ctx carries a cancellation token (see
AgentContext::cancel_token) and it fires mid-execution, in-flight
calls are dropped and every call without a real result receives a
synthetic is_error tool message with content "Operation aborted",
carrying the original tool_call id. Calls that already completed keep
their real result. This keeps the message history consistent: the model
sees a result for every call it issued, and finished side effects are
not misreported as aborted.
§Arguments
ctx- The agent context for the invocationstool_calls- The tool calls to executemax_concurrency- Upper bound on concurrently runningParallelcalls; values below 1 are treated as 1
§Returns
A vector of tool response messages, one for each tool call, in input order.