How thesyart/claude-agent-examples works
Purpose and Entry Points
This is a Python teaching repository that incrementally builds a Claude-based AI agent, not a production application. Each standalone script preserves prior behavior and adds one architectural capability. Start with build-agent-example/code/step01_single_call.py; the complete teaching runtime is build-agent-example/code/step12_hooks.py. Dependencies and Anthropic credentials/model configuration are supplied through requirements.txt and .env.example.
Cumulative Agent Runtime
The core control loop evolves from one model request into a conversational, tool-executing agent. Conversation state is introduced as replayed message history, then role constraints via a system prompt, then repeated model/tool-result turns:
• build-agent-example/code/step03_history.py
• build-agent-example/code/step05_tool_use.py
• build-agent-example/code/step12_hooks.py
The Anthropic model API is the primary external service. Scripts are intended for local Python execution and terminal interaction.
Prompt, Skills, and Tools Boundary
System prompts define agent behavior; tools are explicit callable capabilities exposed to the model; skills are Markdown knowledge/SOP packages loaded only when selected. This keeps skill content out of the default prompt and separates model decisions from local capability execution.
• build-agent-example/code/step06_skills.py
• skills/ddg-web-search-1.0.0/SKILL.md
• skills/github/SKILL.md
The appendix demonstrates the relationship: MCP receives/provides capabilities, skills supply procedure, and tools perform actions.
• build-agent-example/code/sp_mcp-skill-tool.py
Persistent Memory and Context Compaction
From step 7 onward, the agent persists raw conversation, situational notes, durable memory, and a user profile. Durable memory is injected into prompts; a compaction prompt summarizes older context to control prompt size. The runtime creates missing storage defaults rather than overwriting existing data.
• build-agent-example/code/step07_memory_system.py
• templates/USER.md
• templates/agent/compact_prompt.md
The README describes runtime-created memory/ files, although that directory is not present in the supplied tree.
Planning and Delegated Work
Task execution gains an update_todos planning interface, then isolated subagents with distinct identities and concurrent dispatch, followed by a persistent agent-team model with shared team state and inbox-style communication.
• build-agent-example/code/step08_plan_todolist.py
• build-agent-example/code/step09_subagent.py
• build-agent-example/code/step10_agent_team.py
Subagent role definitions are external prompt assets, creating a boundary between orchestration logic and persona/task specialization.
• templates/subagents/general.md
• templates/subagents/researcher.md
MCP Integration
MCP extends the local tool surface through external servers over stdio transport. Server launch/configuration is separated from agent orchestration: the client stage loads server definitions, while the included time server is a local reference provider.
• build-agent-example/code/step11_mcp.py
• mcp_servers.json
• build-agent-example/mcp_server_time.py
The default MCP configuration assumes the local virtual environment’s Python executable.
Lifecycle Governance and Supporting Material
The final runtime adds before/after hooks around agent operations for interception, modification, and auditing—an execution-policy boundary applied after all core capabilities are assembled.
• build-agent-example/code/step12_hooks.py
• build-agent-example/doc/step12_hooks.md
• tests/test_step12_hooks.py
Documentation, slides, and transcripts support the curriculum but are outside the executable runtime: build-agent-example/doc/, ppt/, and bilibili-transcripts/.
Main entry points: step11_mcp.py MCP client stage · step06_skills.py Skills-enabled agent · step07_memory_system.py Persistent memory · step12_hooks.py Hooked agent runtime
Components 20
Teaching Runtime
Standalone cumulative Python agent examples.
- Single model call · Curriculum entry point.
build-agent-example/code/step01_single_call.py - Conversation history · Replays prior messages to the model.
build-agent-example/code/step03_history.py - Tool-use loop · Repeats model and tool-result turns.
build-agent-example/code/step05_tool_use.py - Hooked agent runtime · Complete teaching runtime with lifecycle hooks.
build-agent-example/code/step12_hooks.py - Local terminal user
Capabilities
Prompt assets, skills, tools, and delegated work.
- Skills-enabled agent · Loads knowledge packages only when selected.
build-agent-example/code/step06_skills.py - Skill packages · Procedures kept outside the default prompt.
skills/ddg-web-search-1.0.0/SKILL.md - GitHub skill
skills/github/SKILL.md - Todo planning · Exposes an update_todos planning interface.
build-agent-example/code/step08_plan_todolist.py - Concurrent subagents · Dispatches isolated specialist agents.
build-agent-example/code/step09_subagent.py - Persistent agent team · Adds shared team state and inbox communication.
build-agent-example/code/step10_agent_team.py - Subagent roles · External persona and task specializations.
templates/subagents/general.md - MCP / skill / tool guide · Explains capabilities, procedures, and actions.
build-agent-example/code/sp_mcp-skill-tool.py
State & Context
Persistent memory and context management.
- Persistent memory · Creates and preserves conversation, notes, memory, and profile state.
build-agent-example/code/step07_memory_system.py - User profile template
templates/USER.md - Compaction prompt · Summarizes older context to control prompt size.
templates/agent/compact_prompt.md
External Integration
Model and MCP service boundaries.
- Anthropic model API
- MCP client stage · Loads external tool servers over stdio.
build-agent-example/code/step11_mcp.py - MCP server config
mcp_servers.json - Reference time server · Local capability provider.
build-agent-example/mcp_server_time.py
Connections 21
- Single model call → Conversation history: adds history
- Conversation history → Tool-use loop: adds tool loop
- Tool-use loop → Skills-enabled agent: adds skill selection
- Skills-enabled agent → Persistent memory: adds persistence
- Persistent memory → Todo planning: adds planning
- Todo planning → Concurrent subagents: adds delegation
- Concurrent subagents → Persistent agent team: adds shared team state
- Persistent agent team → MCP client stage: adds MCP tools
- MCP client stage → Hooked agent runtime: assembled into final runtime
- Local terminal user → Hooked agent runtime: interactive input
- Hooked agent runtime → Anthropic model API: model requests
- Skills-enabled agent → Skill packages: selects and loads
- Skills-enabled agent → GitHub skill: selects and loads
- Persistent memory → User profile template: initializes from
- Persistent memory → Compaction prompt: uses for compaction
- Concurrent subagents → Subagent roles: loads roles
- Persistent agent team → Subagent roles: uses personas
- MCP client stage → MCP server config: reads definitions
- MCP server config → Reference time server: launches via stdio
- MCP / skill / tool guide → MCP client stage: documents capability boundary
- Hooked agent runtime → MCP client stage: uses external tools