Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

5 Commits

Repository files navigation

Claude Advisor Pattern

Buy me a coffee

Sonnet executes, Opus advises. A Python implementation of the advisor pattern for the Anthropic Claude API using standard custom tools.

The Claude API doesn't have a native advisor tool type. This library implements the same behavior: the executor model (Sonnet) autonomously decides when to consult a senior advisor (Opus) during task execution, using a standard tool-use loop.

How It Works

User Task
│
▼
┌─────────────────────────────────────────────┐
│ Executor (Sonnet 4.6) │
│ │
│ "I need creative direction for this..." │
│ │ │
│ ▼ ask_advisor() │
│ ┌─────────────────┐ │
│ │ Advisor (Opus) │ │
│ │ "Focus on │ │
│ │ contrast and │ │
│ │ emotional arc" │ │
│ └────────┬────────┘ │
│ │ │
│ "Got it, here's the refined plan..." │
│ │
└─────────────────────┬───────────────────────┘
│
▼
Final Output

The executor decides when to consult (not every turn), what to ask, and how to incorporate the advice. The advisor budget (max_advisor_calls) prevents overuse.

Quick Start

pip install anthropic
export ANTHROPIC_API_KEY="sk-ant-..."# CLI
python advisor.py "Design a go-to-market strategy for an AI video tool" --max-calls 3
# With JSON output
python advisor.py "..." --json

Python API

fromadvisorimportAdvisorClientclient=AdvisorClient()
result=client.run(
"Create a 3-shot video storyboard for a smartphone ad",
executor="claude-sonnet-4-6", # fast, cheap — does the workadvisor="claude-opus-4-6", # smart, expensive — gives directionmax_advisor_calls=3, # budget: max 3 consultations
)
print(result.text) # final outputprint(result.advisor_calls) # how many times Sonnet asked Opusprint(result.advisor_log) # full Q&A logprint(result.total_input_tokens) # combined token usage

When Sonnet Consults Opus

The executor autonomously decides when to use the advisor. Typical patterns:

SituationSonnet's behavior
Creative direction neededAsks advisor before generating content
Ambiguous requirementsAsks advisor to clarify strategy
Quality reviewAsks advisor to evaluate a draft
Trade-off decisionAsks advisor to weigh options
Routine executionProceeds without consulting

Buy me a coffee

Configuration

client=AdvisorClient(
api_key="sk-ant-...", # or set ANTHROPIC_API_KEY env varadvisor_system="You are a senior creative director..."# customize advisor persona
)
result=client.run(
prompt="...",
executor="claude-sonnet-4-6", # any Claude modeladvisor="claude-opus-4-6", # any Claude model (usually more capable)max_advisor_calls=3, # budget controlmax_turns=10, # loop safety limitmax_tokens=4096, # per-turn output limitsystem="You are a marketing expert", # executor system promptextra_tools=[...], # additional tools for executor
)

Examples

Video Storyboard (integrated with ai-video-studio)

result=client.run(
"Create a storyboard for a 15-second product video. ""The product is a wireless earbuds called 'AirPulse'. ""Target audience: young professionals. ""Output as JSON with shots array.",
system="You are a video production assistant. Output storyboards as JSON.",
max_advisor_calls=2,
)
# Sonnet will consult Opus on creative direction, then produce JSON storyboard

Code Review

result=client.run(
f"Review this code for bugs and security issues:\n```python\n{code}\n```",
advisor_system="You are a senior security engineer. Focus on OWASP top 10.",
max_advisor_calls=1, # one strategic review, then Sonnet details the findings
)

Strategic Planning

result=client.run(
"Create a 90-day launch plan for entering the Japanese market ""with our B2B SaaS product (CRM for small businesses).",
max_advisor_calls=3, # budget for strategy, positioning, and risk review
)

Cost Optimization

ModelInput (per 1M tokens)Output (per 1M tokens)
Sonnet 4.6$3$15
Opus 4.6$15$75

With max_advisor_calls=3, a typical task costs:

  • ~90% Sonnet tokens (cheap execution)
  • ~10% Opus tokens (expensive but targeted advice)

Net effect: ~80% cheaper than running everything on Opus, with comparable quality on strategic decisions.

AdvisorResult

@dataclassclassAdvisorResult:
text: str# final output textadvisor_calls: int# times advisor was consultedadvisor_log: list[dict] # [{call, question, context, advice}, ...]total_input_tokens: int# combined across all modelstotal_output_tokens: intturns: int# conversation turns

License

MIT

Built With

Buy me a coffee

About

Sonnet executes, Opus advises. Python implementation of the advisor pattern for Claude API — multi-model orchestration via custom tools.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages