What's wrong with this entry?
Anonymous. No account, no email.
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.
How to use:
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°F";
}
}
],
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:
- Automatically detects
tool_useblocks in assistant responses and executes matching tools - Supports both streaming and non-streaming modes
- Configurable iteration limits via
max_iterationsparameter - Tools must implement a
run()method that returns results - Optional
parse()method for input validation/transformation - Returns properly formatted
tool_resultmessages with error handling - Can be controlled manually via
generateToolResponse()andpushMessages()methods - Evidence: Class
TYAat line 82603, functionbh9()at line 82564, variableuZ1at line 82604, newtoolRunner()method at line 82828