Skip to content

Implement #7: Advanced Agent Patterns#43

Merged
yagop merged 1 commit into
mainfrom
issue-7-07-advanced-patterns
Jun 17, 2026
Merged

Implement #7: Advanced Agent Patterns#43
yagop merged 1 commit into
mainfrom
issue-7-07-advanced-patterns

Conversation

@yagop

@yagop yagop commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Closes #7

Chapter 7 adds the advanced patterns on top of the Chapter 5/6 loop: a budgeted autonomous loop, extended thinking, self-critique, structured output, error recovery, and subagent orchestration. Authored single-pass; the cutoff-sensitive thinking shape was verified against the installed SDK and a live probe.

Definition of done

  • Chapter at chapters/07-advanced-patterns.md, <=120 lines, <=4 main-line H2s plus a closer
  • Every sample runnable with bun run, imported via <<< @/examples/07-advanced-patterns/file.ts
  • One-home rule held (the reflection-as-user-turn gotcha and the thinking shape live in prose, not code comments); reader addressed as "you"; intro + sections open warm
  • Samples use only real @anthropic-ai/sdk surface; ASCII punctuation only
  • Optional material (token guardrails, planning tool) lives in Going-deeper :::details asides, not main-line H2s
  • Linked from README.md and the .vitepress/config.ts sidebar; bun x vitepress build passes
  • thinking parameter shape verified - see below
  • Sample line budget: samples are 24-66 lines, above the issue's stated <=35 (skill budget is <=100)

thinking shape verification (cutoff-sensitive)

Checked against the installed @anthropic-ai/sdk .d.ts and a live probe on the gateway:

  • ThinkingConfigParam = { type: 'adaptive', display? } | { type: 'enabled', budget_tokens, display? } | { type: 'disabled' }
  • ThinkingBlock = { signature: string; thinking: string; type: 'thinking' }
  • Live probe: thinking: { type: 'adaptive' } -> returned [thinking, text] blocks (2803 thinking chars, signature present); { type: 'enabled', budget_tokens: 1024 } also works.
  • The sample uses adaptive (current form); an :::info callout documents the enabled/budget_tokens form for models 4.6 and earlier.

Verification (run live)

Chapter budget: wc -l -> 69; grep -c '^## ' -> 4. tsc --noEmit clean; vitepress build passes (all six snippets resolve). Each sample run:

autonomous-loop.ts    46   extended-thinking.ts  26   reflection.ts    24
structured-output.ts  38   error-recovery.ts     66   orchestrator.ts  53
  • autonomous-loop -> 2 steps (tool_use -> end_turn), prints running token total, answers correctly.
  • extended-thinking -> a real [thinking] block (the bat-and-ball riddle reasoning) printed separately from [answer].
  • reflection -> draft -> plain-user critique turn -> revised tagline.
  • structured-output -> forced emit_result returned label: positive, confidence: 0.95 (the gateway honored forcing for this tool-eliciting prompt).
  • error-recovery -> read notes.txt (ok) and config.txt (is_error -> missing); the model recovered and reported both.
  • orchestrator -> coordinator's summarize_text call dispatched to the summarize() helper subagent (its own create), returning the one-sentence summary.

Notes

  • Only extended-thinking.ts enables thinking, keeping it clear of the forced-tool_choice and thinking-block-preservation constraints that apply when thinking is combined with tools.
  • Sample sizes (24-66 lines) follow the skill's 100-line budget rather than the issue's older <=35.

Review flags

None.

🤖 Generated with Claude Code

Chapter 7 plus its examples/07-advanced-patterns/ samples: the autonomous
loop with a maxSteps budget and token tracking, extended thinking
(thinking: { type: 'adaptive' }) reading thinking blocks, a reflection
pass via a plain user turn, structured output via a forced tool, error
recovery (RateLimitError backoff + is_error results), and a coordinator
delegating subtasks to a helper subagent. Wired into the sidebar and
README.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yagop yagop mentioned this pull request Jun 17, 2026
14 tasks
@yagop yagop merged commit 36ebe12 into main Jun 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chapter 7: Advanced Agent Patterns

1 participant