Log at info level changedagents-and-tools/tool-use/tool-runner
Nearest release: v2.1.307, published an hour after this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Recorded here
Lines+6added
Lines−6removed
From line
83
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits15to this page, all time
The whole hunk
from line 83, old and new numbered
/
from line 83
8383
8484 TypeScript offers two approaches for defining tools:
8585
86 **Using Zod (recommended)** - Use `betaZodTool()` for type-safe tool definitions with Zod validation (requires Zod 3.25.0 or higher):
86 **Using Zod (recommended):** Use `betaZodTool()` for type-safe tool definitions with Zod validation (requires Zod 3.25.0 or higher):
8787
8888 ```typescript
8989 import Anthropic from "@anthropic-ai/sdk";
from line 118
118118 }
119119 ```
120120
121 **Using JSON Schema** - Use `betaTool()` for type-safe tool definitions without Zod:
121 **Using JSON Schema:** Use `betaTool()` for type-safe tool definitions without Zod:
122122
123123 <Note>
124124 The input generated by Claude is not validated at runtime. Perform validation inside the `run` function if needed.
from line 814
814814
815815You take over by modifying the runner's messages from inside the loop body. The exact method depends on the SDK. See the per-language tabs that follow.
816816
817When you take over for an iteration, the runner does not append the assistant message or tool results from that turn. You become responsible for keeping the conversation valid: append the assistant message and a tool result yourself (if you want the turn to count), modify state conditionally so the loop can still exit when there are no tool calls, and pass `max_iterations` (csharp, java, php: `maxIterations`; go: `MaxIterations`) to bound the loop. All seven SDKs support `max_iterations` (csharp, java, php: `maxIterations`; go: `MaxIterations`).
817When you take over for an iteration, the runner does not append the assistant message or tool results from that turn. You become responsible for keeping the conversation valid: append the assistant message and a tool result yourself (if you want the turn to count), modify state conditionally so the loop can still exit when there are no tool calls, and pass `max_iterations` (csharp, java, php: `maxIterations`; go: `MaxIterations`) to bound the loop. The SDK supports `max_iterations` (csharp, java, php: `maxIterations`; go: `MaxIterations`).
818818
819819<Tabs exclude="shell">
820820 <Tab title="Python">
from line 979
979979 </Tab>
980980
981981 <Tab title="Java">
982 Use `runner.params()` to read the current parameters and `runner.setNextParams()` to replace them for the next iteration. When you call `setNextParams()` inside the loop, the runner skips its automatic append. The just-yielded message is discarded, and the next iteration sends your new params unchanged.
982 Use `runner.params()` to read the current parameters and `runner.setNextParams()` to replace them for the next iteration. When you call `setNextParams()` inside the loop, the runner skips its automatic append. The just-yielded message is discarded, and the next iteration sends your new parameters unchanged.
983983
984984 The following example retries a turn that hit the token limit by doubling `max_tokens`. Mutating only on the `max_tokens` branch keeps the loop converging: turns that complete normally fall through, and the runner auto-appends and exits when there are no more tool calls.
985985
from line 1114
11141114
11151115### Intercepting tool errors
11161116
1117By default, tool errors are passed back to Claude, which can then respond appropriately. However, you might want to detect errors and handle them differently, for example, to stop execution early or implement custom error handling.
1117By default, the tool runner passes tool errors back to Claude, which can then respond appropriately. However, you might want to detect errors and handle them differently, for example, to stop execution early or implement custom error handling.
11181118
11191119<Tabs exclude="shell">
11201120 <Tab title="Python">
from line 1705
17051705 </Tab>
17061706
17071707 <Tab title="Java">
1708 Call `runner.streaming()` to get a stream for each turn. Each `StreamResponse` must be closed after use.
1708 Call `runner.streaming()` to get a stream for each turn. Close each `StreamResponse` after use.
17091709
17101710 ```java
17111711 void main() {
No line in this hunk matches that.