Loading...
    • 开发者指南
    • API 参考
    • MCP
    • 资源
    • 发布说明
    Search...
    ⌘K

    第一步

    Claude 简介快速开始

    模型与定价

    模型概览选择模型Claude 4.5 的新功能迁移到 Claude 4.5模型弃用定价

    使用 Claude 构建

    功能概览使用 Messages API上下文窗口提示词最佳实践

    功能

    提示词缓存上下文编辑扩展思考流式消息批处理引用多语言支持Token 计数嵌入向量视觉PDF 支持Files API搜索结果Google Sheets 插件

    工具

    概述如何实现工具使用令牌高效的工具使用细粒度工具流式传输Bash 工具代码执行工具计算机使用工具文本编辑器工具Web fetch 工具网络搜索工具记忆工具

    代理技能

    概述在 API 中开始使用 Agent Skills技能创作最佳实践通过 API 使用 Agent Skills

    Agent SDK

    概览TypeScript SDKPython SDK

    指南

    流式输入处理权限会话管理托管 Agent SDK修改系统提示词SDK 中的 MCP自定义工具SDK 中的子代理SDK 中的斜杠命令SDK 中的代理技能跟踪成本和使用情况待办事项列表SDK 中的插件

    API 中的 MCP

    MCP 连接器远程 MCP 服务器

    Claude 在第三方平台上

    Amazon BedrockVertex AI

    提示词工程

    概述提示词生成器使用提示模板提示词改进器保持清晰和直接使用示例(多示例提示)让 Claude 思考(思维链)使用XML标签给Claude分配角色(系统提示)预填充 Claude 的响应链式复杂提示长文本技巧扩展思考技巧

    测试与评估

    定义成功标准开发测试用例使用评估工具减少延迟

    加强防护措施

    减少幻觉提高输出一致性缓解越狱handle-streaming-refusals减少提示词泄露保持Claude的角色特征

    管理和监控

    Admin API 概述使用量和成本 APIClaude Code 分析 API
    Console
    提示词工程

    通过系统提示给Claude分配角色

    While these tips apply broadly to all Claude models, you can find prompting tips specific to extended thinking models here.

    使用Claude时,您可以通过使用system参数为其分配角色来显著提高其性能。这种技术称为角色提示,是使用系统提示与Claude配合的最强大方式。

    正确的角色可以将Claude从通用助手转变为您的虚拟领域专家!

    系统提示提示:使用system参数设置Claude的角色。将其他所有内容(如特定任务的说明)放在user轮次中。

    为什么要使用角色提示?

    • 增强准确性: 在法律分析或财务建模等复杂场景中,角色提示可以显著提升Claude的性能。
    • 定制化语气: 无论您需要首席财务官的简洁性还是文案撰写人的风采,角色提示都可以调整Claude的沟通风格。
    • 改进专注力: 通过设置角色背景,Claude能更好地保持在您任务的具体要求范围内。

    如何给Claude分配角色

    在Messages API中使用system参数来设置Claude的角色:

    import anthropic
    
    client = anthropic.Anthropic()
    
    response = client.messages.create(
        model="claude-sonnet-4-5-20250929",
        max_tokens=2048,
        system="You are a seasoned data scientist at a Fortune 500 company.", # <-- role prompt
        messages=[
            {"role": "user", "content": "Analyze this dataset for anomalies: <dataset>{{DATASET}}</dataset>"}
        ]
    )
    
    print(response.content)
    角色提示提示:尝试不同的角色!数据科学家可能会对相同的数据看到不同的见解,而营销策略师也会如此。专门从事财富500强公司客户洞察分析的数据科学家可能会产生完全不同的结果!

    示例

    示例1:法律合同分析

    没有角色的情况下,Claude可能会遗漏关键问题:

    通过角色提示,Claude能够发现可能造成数百万美元损失的关键问题:

    示例2:财务分析

    没有角色的情况下,Claude的分析缺乏深度:

    通过角色提示,Claude提供可行的洞察:


    提示库

    从为各种任务和用例精选的提示中获得灵感。

    GitHub提示教程

    一个充满示例的教程,涵盖我们文档中的提示工程概念。

    Google Sheets提示教程

    通过交互式电子表格提供的更轻量级版本的提示工程教程。

    • 如何给Claude分配角色
    • 示例1:法律合同分析
    • 示例2:财务分析
    © 2025 ANTHROPIC PBC

    Products

    • Claude
    • Claude Code
    • Max plan
    • Team plan
    • Enterprise plan
    • Download app
    • Pricing
    • Log in

    Features

    • Claude and Slack
    • Claude in Excel

    Models

    • Opus
    • Sonnet
    • Haiku

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Claude Developer Platform

    • Overview
    • Developer docs
    • Pricing
    • Amazon Bedrock
    • Google Cloud’s Vertex AI
    • Console login

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Help and security

    • Availability
    • Status
    • Support center

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy

    Products

    • Claude
    • Claude Code
    • Max plan
    • Team plan
    • Enterprise plan
    • Download app
    • Pricing
    • Log in

    Features

    • Claude and Slack
    • Claude in Excel

    Models

    • Opus
    • Sonnet
    • Haiku

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Claude Developer Platform

    • Overview
    • Developer docs
    • Pricing
    • Amazon Bedrock
    • Google Cloud’s Vertex AI
    • Console login

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Help and security

    • Availability
    • Status
    • Support center

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    © 2025 ANTHROPIC PBC