Implement #6: Building Tool Chains and Complex Workflows#39
Merged
Conversation
Chapter 6 plus its examples/06-tool-chains/ samples: the hand-written agent loop (branch on stop_reason, run until end_turn), sequential chaining, parallel tool_use via Promise.all, tool_choice and the forcing/termination gotcha, and a reusable Map-based runner with a maxIterations cap and is_error recovery - also wired to stream + finalMessage. Wires the chapter into the sidebar and README. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6
Chapter 6 turns Chapter 5's single tool round-trip into the core agent engine: a loop that drives
client.messages.createuntilend_turn, handling sequential chains, parallel tool calls,tool_choice, and a reusable runner. Authored single-pass (per the updated skill) and verified end-to-end.Definition of done
chapters/06-tool-chains.md,<=120lines,<=4main-line H2s plus a closerbun run, imported via<<< @/examples/06-tool-chains/file.ts@anthropic-ai/sdksurface (verified against the SDK.d.ts); ASCII punctuation onlybetaZodTool+toolRunner) lives in a Going-deeper:::detailsaside, not a main-line H2README.mdand the.vitepress/config.tssidebar;bun x vitepress buildpassesMapregistry +Anthropic.Tool[]+maxIterations+is_error, drop-in for the Ch.3 Telegram surface)38-69lines, above the issue's stated<=35- see note belowVerification (run live against an Anthropic-compatible gateway)
Chapter budget:
wc -l-> 65 (<=120);grep -c '^## '-> 4.Samples (all
<=100lines, comment:code<=0.40, one statement per line):bunx tsc --noEmitclean;bun x vitepress buildpasses (all six snippets resolve). Each sample was run, not just typechecked:find_user({"name":"Ada Lovelace"}) -> u_42, thenget_balance({"userId":"u_42"}), then "balance is 1200.50 USD" - the dependent call serialized across turns by the model.running 3 tool call(s) for this turn(Paris/Tokyo/Cairo emitted in one turn, resolved together withPromise.all).19 + 23 = 42, then+ 100 = 142.stream+finalMessage().auto/any/tool/none; see gateway note below.Notes / honesty flags
tool_choiceforcing on this gateway: the GLM gateway used for the live run does not honor forcedtool_choice- all four modes returnedstop_reason=end_turn, called_tool=falsefor the "just say hello" prompt. On Anthropic direct,anyand{ type: 'tool' }would force a call and returnstop_reason=tool_use, which is exactly the must-keep gotcha the chapter teaches (a forced turn never reportsend_turn, so the loop must keep its exit onend_turnand force only when it wants a call). The sample code is correct against the Anthropic API.<=35: agent-loop samples don't fit35readable lines, so these run38-69lines under the skill's current100-line budget. That issue-DoD line is the place to reconcile.Review flags
None.
🤖 Generated with Claude Code