Log at info level changedagents-and-tools/tool-use/tool-runner
Nearest release: v2.1.309, published 3 hours before 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+52added
Lines−50removed
From line
396
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits18to this page, all time
The whole hunk
from line 396, old and new numbered
/
from line 396
396396
397397 // The lambda can use weatherService.
398398 BetaRunnableTool getWeather = BetaRunnableTool.of(
399 GetWeather.class,
400 input -> BetaToolResultBlockParam.Content.ofString(
401 weatherService.currentWeather(input.location, input.unit)));
399 GetWeather.class,
400 input -> BetaToolResultBlockParam.Content.ofString(
401 weatherService.currentWeather(input.location, input.unit)));
402402
403403 BetaRunnableTool calculateSum = BetaRunnableTool.of(
404 CalculateSum.class,
405 input -> BetaToolResultBlockParam.Content.ofString(
406 String.valueOf(input.a + input.b)));
404 CalculateSum.class,
405 input -> BetaToolResultBlockParam.Content.ofString(
406 String.valueOf(input.a + input.b)));
407407
408408 BetaToolRunner runner = client.beta()
409 .messages()
410 .toolRunner(MessageCreateParams.builder()
411 .model(Model.CLAUDE_OPUS_5_5)
412 .maxTokens(1024)
413 .addBeta("structured-outputs-2025-11-13")
414 .addUserMessage("What's the weather like in Paris? Also, what's 15 + 27?")
415 .addTool(getWeather)
416 .addTool(calculateSum)
417 .build());
409 .messages()
410 .toolRunner(MessageCreateParams.builder()
411 .model(Model.CLAUDE_OPUS_5_5)
412 .maxTokens(1024)
413 .addBeta("structured-outputs-2025-11-13")
414 .addUserMessage("What's the weather like in Paris? Also, what's 15 + 27?")
415 .addTool(getWeather)
416 .addTool(calculateSum)
417 .build());
418418
419419 for (BetaMessage message : runner) {
420420 IO.println(message);
from line 706
706706 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
707707
708708 BetaToolRunner runner = client.beta()
709 .messages()
710 .toolRunner(MessageCreateParams.builder()
711 .model(Model.CLAUDE_OPUS_5_5)
712 .maxTokens(1024)
713 .addBeta("structured-outputs-2025-11-13")
714 .addUserMessage("What's the weather like in Paris? Also, what's 15 + 27?")
715 .addTool(getWeather)
716 .addTool(calculateSum)
717 .build());
709 .messages()
710 .toolRunner(MessageCreateParams.builder()
711 .model(Model.CLAUDE_OPUS_5_5)
712 .maxTokens(1024)
713 .addBeta("structured-outputs-2025-11-13")
714 .addUserMessage("What's the weather like in Paris? Also, what's 15 + 27?")
715 .addTool(getWeather)
716 .addTool(calculateSum)
717 .build());
718718
719719 BetaMessage finalMessage = null;
720720 for (BetaMessage message : runner) {
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. The SDK supports `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`) in all seven languages.
818818
819819<Tabs exclude="shell">
820820 <Tab title="Python">
from line 985
985985
986986 ```java
987987 BetaToolRunner runner = client.beta()
988 .messages()
989 .toolRunner(ToolRunnerCreateParams.builder()
990 .initialMessageParams(MessageCreateParams.builder()
991 .model(Model.CLAUDE_OPUS_5_5)
992 .maxTokens(1024)
993 .addBeta("structured-outputs-2025-11-13")
994 .addUserMessage("Give me a detailed weather report for every major US city.")
995 .addTool(getWeather)
996 .build())
997 .maxIterations(10L)
998 .build());
988 .messages()
989 .toolRunner(ToolRunnerCreateParams.builder()
990 .initialMessageParams(MessageCreateParams.builder()
991 .model(Model.CLAUDE_OPUS_5_5)
992 .maxTokens(1024)
993 .addBeta("structured-outputs-2025-11-13")
994 .addUserMessage("Give me a detailed weather report for every major US city.")
995 .addTool(getWeather)
996 .build())
997 .maxIterations(10L)
998 .build());
999999
10001000 long ceiling = 8192;
10011001
from line 1012
10121012 // Calling setNextParams() flags this turn as user-managed: the runner
10131013 // does NOT auto-append the truncated message, so the next iteration
10141014 // re-sends the same conversation prefix with the larger budget.
1015 runner.setNextParams(runner.params().toBuilder().maxTokens(doubled).build());
1015 runner.setNextParams(runner.params().toBuilder()
1016 .maxTokens(doubled)
1017 .build());
10161018 }
10171019 // No mutation on a normal turn: the runner auto-appends and continues.
10181020 }
from line 1472
14701472 BetaRunnableTool searchDocuments = BetaRunnableTool.of(SearchDocuments.class, input -> {
14711473 String largeResult = "..."; // a long document worth caching
14721474 return BetaToolResultBlockParam.Content.ofBlocks(List.of(
1473 BetaToolResultBlockParam.Content.Block.ofText(
1474 BetaTextBlockParam.builder()
1475 .text(largeResult)
1476 .cacheControl(BetaCacheControlEphemeral.builder().build())
1477 .build())));
1475 BetaToolResultBlockParam.Content.Block.ofText(
1476 BetaTextBlockParam.builder()
1477 .text(largeResult)
1478 .cacheControl(BetaCacheControlEphemeral.builder().build())
1479 .build())));
14781480 });
14791481 ```
14801482 </Tab>
from line 1714
17121714 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
17131715
17141716 BetaToolRunner runner = client.beta()
1715 .messages()
1716 .toolRunner(MessageCreateParams.builder()
1717 .model(Model.CLAUDE_OPUS_5_5)
1718 .maxTokens(1024)
1719 .addBeta("structured-outputs-2025-11-13")
1720 .addUserMessage("What is 15 + 27?")
1721 .addTool(calculateSum)
1722 .build());
1717 .messages()
1718 .toolRunner(MessageCreateParams.builder()
1719 .model(Model.CLAUDE_OPUS_5_5)
1720 .maxTokens(1024)
1721 .addBeta("structured-outputs-2025-11-13")
1722 .addUserMessage("What is 15 + 27?")
1723 .addTool(calculateSum)
1724 .build());
17231725
17241726 for (StreamResponse<BetaRawMessageStreamEvent> stream : runner.streaming()) {
17251727 try (stream) {
No line in this hunk matches that.