Tools
agent sdk wizard.
Step through the options of the Python Claude Agent SDK and watch agent.py rewrite itself, with every changed line marked. Nothing here calls an API.
agent
Pick a model and how hard it works, then what its system prompt starts from.
Families, not dated model IDs: the SDK picks the current model. Leave effort on default unless you have a reason. Adaptive thinking lets recent models decide how much to think; a fixed budget is mainly for older models.
Your text replaces the system prompt completely.
options = ClaudeAgentOptions( model="sonnet", system_prompt="You track developments in our field. Cite every source you use.",)
generated code
import anyiofrom claude_agent_sdk import ClaudeAgentOptions, query, AgentDefinitionfrom claude_agent_sdk import AssistantMessage, ResultMessage, TextBlock, ToolUseBlockoptions = ClaudeAgentOptions( model="sonnet", system_prompt="You track developments in our field. Cite every source you use.", allowed_tools=["WebSearch", "WebFetch", "Read", "Agent"], agents={ "summariser": AgentDefinition( description="Condenses one long source into five bullet points.", prompt="Summarise the source you are given in five bullet points. Keep every number and date exact.", tools=["Read"], model="haiku", ), }, max_turns=12, max_budget_usd=1,)def show(message): if isinstance(message, AssistantMessage): for block in message.content: if isinstance(block, TextBlock): print(block.text) elif isinstance(block, ToolUseBlock): print("->", block.name, block.input) elif isinstance(message, ResultMessage): cost = message.total_cost_usd or 0 print(f"\n[{message.subtype}: {message.num_turns} turns, ${cost:.4f}]")async def main(): async for message in query(prompt="What changed in our field this week?", options=options): show(message)anyio.run(main)
sonnet agent · 4 pre-approved tools · 1 subagent · runs once with query()
- imports
- the SDK pieces this file uses: ClaudeAgentOptions, query, AgentDefinition
- plus the message types that show() reads
- options
- runs on the sonnet model family
- system prompt: “You track developments in our field. Ci…”
- pre-approves WebSearch, WebFetch, Read, Agent — these run without asking
- subagent summariser (haiku, tools Read): Condenses one long source into five bullet points.
- stops after 12 turns or at $1 spend
- show()
- turns each streamed message into readable output
- prints Claude's text and each tool call as -> name and input
- ends with the result: success or error type, turns used, and cost
- main()
- sends the prompt once, passes each message to show() as it streams back
- prompt: “What changed in our field this week?”
- run
- anyio.run(main) starts it
Press Play in the run step to watch a scripted run.
To pick a conversation up later, pass its session_id as resume=. Add fork_session=True to branch from it instead.
The file targets the claude-agent-sdk Python package. Options change between releases, so check the SDK's own documentation before you ship it.