Skills2026年4月6日·1 分钟阅读

Claude Agent SDK Demos — 8 Official Example Projects

Official demo collection by Anthropic showcasing the Claude Agent SDK: email agent, research agent, resume generator, chat app, Excel processing, and more. MIT license, 2,100+ stars.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 66/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Community
入口
Claude Agent SDK Demos — 8 Official Example Projects
先审查命令
npx -y tokrepo@latest install 5e902544-bf5c-4d78-85e9-85f4c2fe281e --target codex

先 dry-run,确认写入项后再运行此命令。

TL;DR
Eight official Anthropic demos showing Claude Agent SDK patterns for email, research, and more.
§01

What it is

This is the official demo collection by Anthropic showcasing the Claude Agent SDK. It includes eight example projects: an email agent, a research agent, a resume generator, a chat application, an Excel processing agent, and more. Each demo demonstrates a different SDK pattern for building production AI agents.

The collection targets developers learning the Claude Agent SDK who want working reference implementations rather than documentation alone.

§02

How it saves time or tokens

Starting from a working demo eliminates the blank-page problem. Each example includes the agent loop, tool definitions, error handling, and state management patterns that you would otherwise build from scratch. Copy the closest example, modify it for your use case, and deploy.

The demos also serve as integration tests for the SDK. They demonstrate patterns that are verified to work, reducing debugging time.

§03

How to use

  1. Clone the repository: git clone https://github.com/anthropics/anthropic-cookbook
  2. Navigate to the agent SDK demos directory
  3. Install dependencies: pip install anthropic
  4. Run any demo: python email_agent.py
§04

Example

# Simplified research agent pattern from the demos
import anthropic

client = anthropic.Anthropic()

def research_agent(query: str) -> str:
    tools = [
        {
            'name': 'web_search',
            'description': 'Search the web for information',
            'input_schema': {
                'type': 'object',
                'properties': {
                    'query': {'type': 'string', 'description': 'Search query'}
                },
                'required': ['query']
            }
        }
    ]

    messages = [{'role': 'user', 'content': query}]

    while True:
        response = client.messages.create(
            model='claude-sonnet-4-20250514',
            max_tokens=4096,
            tools=tools,
            messages=messages
        )
        if response.stop_reason == 'end_turn':
            return response.content[0].text
        # Handle tool use and continue the loop
        messages.append({'role': 'assistant', 'content': response.content})
        # Process tool calls...
§05

Related on TokRepo

§06

Common pitfalls

  • Demos use hardcoded API keys in some examples; replace with environment variables before deploying
  • The agent loop pattern requires proper stop condition handling; infinite loops occur if tool results are not formatted correctly
  • Some demos depend on external services (email, web search); configure those services before running

常见问题

What is the Claude Agent SDK?+

The Claude Agent SDK is Anthropic's official library for building AI agents that use Claude. It provides tool use, multi-turn conversations, and agent loop patterns. The SDK is available in Python and TypeScript.

Which demo should I start with?+

Start with the chat application demo for the simplest agent loop. Move to the research agent for tool use patterns. The email agent demonstrates multi-step workflows with real external service integration.

Do the demos work with Claude Sonnet or Opus?+

Yes. The demos work with any Claude model. Specify the model ID in the API call. Sonnet is recommended for most agent tasks due to its balance of quality and cost.

Can I use these patterns in production?+

Yes. The patterns demonstrated in the demos (agent loops, tool handling, error recovery) are production-grade. Add authentication, logging, and rate limiting for your specific deployment.

Are the demos open source?+

Yes. The demos are released under the MIT license. You can use, modify, and distribute the code freely.

引用来源 (3)
🙏

来源与感谢

Created by Anthropic. Licensed under MIT.

claude-agent-sdk-demos — ⭐ 2,100+

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产