Implement #5: Implementing Tools and Function Calling#37
Merged
Conversation
Chapter 5 plus its examples/05-tools/ samples: declaring a tool, catching the tool_use block, the full create -> tool_use -> tool_result -> answer round-trip, dispatching block.name to typed handlers, returning is_error results, and steering with tool_choice. Wires the chapter into the VitePress sidebar and README. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
12 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 #5
Chapter 5 teaches the core tool-use round-trip of the Messages API: declaring a tool, catching the
tool_useblock, executing it, returning atool_result, dispatching to typed handlers, reporting errors withis_error, and steering withtool_choice. Authored by thewrite-chapterultracode Workflow (1 doc agent + 5 implement/review pipeline pairs), then verified end-to-end.Definition of done
chapters/05-tools.md,<=120lines,<=4main-line H2s plus a closerbun run, imported via<<< @/examples/05-tools/file.ts@anthropic-ai/sdksurface (verified against the SDK.d.tsand current docs); ASCII punctuation onlyREADME.mdand the.vitepress/config.tssidebar;bun x vitepress buildpasses36-78lines, above the issue's stated<=35, because the skill's code budget was raised to a100-line hard cap (verbose-preferred) in a prior changeVerification (run live against an Anthropic-compatible gateway)
Chapter budget:
wc -l-> 68 (<=120);grep -c '^## '-> 4.Samples (all
<=100lines, comment:code<=0.40, one statement per line):bunx tsc --noEmitclean;bun x vitepress@2.0.0-alpha.17 buildpasses (all five snippets resolve). Each sample was run, not just typechecked:stop_reason: tool_use, then thetool_useblock'sid,name, and the already-parsedinputobject ({ location: "Tokyo, Japan" }) - noJSON.parse.19 + 23 = 42.error: denominator was 0...thenok: 3; the model recovers and reports both.auto,any,{ type: 'tool' },auto + disable_parallel_tool_use); each returnedstop_reason=tool_use chose=get_weather.Notes / honesty flags
tool_choiceon this gateway: the weather prompt elicits the tool in every mode (true on Anthropic direct too), so the live output is uniform - the modes only diverge on a prompt the model could answer in text. I adjusted the chapter prose to say exactly that rather than overpromise a "shift." Separately, I confirmed by probe that this GLM gateway does not honor forcedtool_choice({ type: 'tool' }on an unrelated prompt returnsend_turn, notool_use); the sample code is correct against the Anthropic API.dispatch-handlers.ts: the Workflow emittedRecord<string, Handler>(an index-signature type); I converted it toMap<string, Handler>to honor the "no index signatures" convention. Re-ran + tsc clean after.<=35: the skill's code budget was raised to a100-line hard cap (verbose-preferred) in a prior change, so these run36-78lines. If you want the issue DoD reconciled, the<=35line is the place.Review flags
None - the Workflow returned all five samples as fully compliant (no flagged files).
🤖 Generated with Claude Code