View Source Anthropic.ToolRunner (anthropic_community v0.5.0)
Drives Anthropic.Messages.create/2 in a loop, executing tool calls the assistant
requests until it produces a final answer (stop_reason other than "tool_use").
Example
client = Anthropic.Client.new(api_key: System.fetch_env!("ANTHROPIC_API_KEY"))
{:ok, message, _history} =
Anthropic.ToolRunner.run(
client,
[model: "claude-opus-4-8", max_tokens: 1024,
messages: [%{role: "user", content: "What's the weather in Paris?"}]],
[MyApp.WeatherTool]
)
Summary
Functions
Runs client/opts through Anthropic.Messages.create/2, executing any requested
tools and feeding results back, until the assistant stops requesting tools (or
max_iterations is exceeded).
Functions
@spec run( Anthropic.Client.t(), Anthropic.Messages.create_opts(), [module()], pos_integer() ) :: {:ok, Anthropic.Messages.Message.t(), [map()]} | {:error, Anthropic.Error.t()}
Runs client/opts through Anthropic.Messages.create/2, executing any requested
tools and feeding results back, until the assistant stops requesting tools (or
max_iterations is exceeded).
Returns {:ok, final_message, messages_history} on success, where messages_history is
the full messages param list (including every assistant tool_use turn and user
tool_result turn) so the caller can continue the conversation. Returns {:error, %Anthropic.Error{}} if the underlying API call fails or the loop exceeds
max_iterations.