{"version":"2.0.32","anchor":"automated-tool-execution-api-betatoolrunner","canonical_anchor":"automated-tool-execution-api-betatoolrunner","heading":"Automated Tool Execution API (BetaToolRunner)","tier":null,"area":null,"scope":null,"heads_up":null,"url":"https:\/\/changelogs.core-directive.com\/v\/2.0.32\/e\/automated-tool-execution-api-betatoolrunner","release_url":"https:\/\/changelogs.core-directive.com\/v\/2.0.32","markdown":"### Automated Tool Execution API (BetaToolRunner)\n\n**What:** A new `toolRunner()` method in the Messages API that automatically executes tools in an agentic loop, eliminating the need to manually handle tool_use\/tool_result message cycles.\n\n**How to use:**\n\n`const runner = client.beta.messages.toolRunner({ model: \"claude-sonnet-4-20250514\", max_tokens: 1024, max_iterations: 10, \/\/ Limit agentic loops tools: [ { name: \"get_weather\", run: async (input) => { \/\/ Your tool implementation return \"Sunny, 72\u00b0F\"; } } ], messages: [{ role: \"user\", content: \"What's the weather?\" }] }); \/\/ Stream each iteration for await (const messageStream of runner) { \/\/ Handle streaming response } \/\/ Or wait for completion const finalMessage = await runner.done();` **Details:**\n\n- Automatically detects `tool_use` blocks in assistant responses and executes matching tools\n- Supports both streaming and non-streaming modes\n- Configurable iteration limits via `max_iterations` parameter\n- Tools must implement a `run()` method that returns results\n- Optional `parse()` method for input validation\/transformation\n- Returns properly formatted `tool_result` messages with error handling\n- Can be controlled manually via `generateToolResponse()` and `pushMessages()` methods\n- **Evidence**: Class `TYA` at line 82603, function `bh9()` at line 82564, variable `uZ1` at line 82604, new `toolRunner()` method at line 82828"}