Loading...
    • 构建
    • 管理
    • 模型与定价
    • 客户端 SDK
    • API 参考
    Search...
    ⌘K
    管理
    Admin API 概览工作区数据驻留API 与数据保留
    监控
    Claude Code 分析 API用量与费用 API
    第三方平台
    Amazon BedrockMicrosoft FoundryVertex AI
    Console
    Log in
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...

    Solutions

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

    Partners

    • Amazon Bedrock
    • Google Cloud's Vertex AI

    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

    Learn

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

    Help and security

    • Availability
    • Status
    • Support
    • Discord

    Terms and policies

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

    会话追踪

    使用 Console 时间线和原始事件视图监控和调试您的会话。

    Was this page helpful?

    • Console 可观测性

    Claude Managed Agents 在 Claude Console 中提供可观测性工具,帮助您监控、调试和了解您的 Agent 会话。

    Console 可观测性

    Console 提供 Agent 会话的可视化时间线视图。在 Console 中导航到 Claude Managed Agents 部分,您可以看到:

    • 会话列表 - 所有会话及其状态、创建时间和模型
    • 追踪视图 - 会话中事件(内容、时间戳、Token 用量)的时间顺序视图。这些内容仅对开发者和管理员可见。
    • 工具执行 - 每次工具调用及其结果的详细信息

    原始事件

    如需以编程方式进行调试,可通过 API 获取原始事件:

    curl -fsSL "https://api.anthropic.com/v1/sessions/$SESSION_ID/events" \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01" \
    | jq -r '
      .data[]
      | "Type: \(.type)",
        "Processed: \(.processed_at)",
        ( if .type | IN("user.message", "agent.message") then
            .content[]
            | "  Block: \(.type)",
              (select(.type == "text") | "  Text: \(.text[:100])...")
          elif .type | IN("agent.tool_use", "agent.custom_tool_use", "agent.mcp_tool_use") then
            "  Tool: \(.name)"
          else empty end ),
        "---"
    '

    使用相同的事件流来显示错误并追踪 Token 消耗:

    调试技巧

    • 检查会话事件 - 会话错误通过 session.error 事件传递
    • 查看工具结果 - 工具执行失败通常能解释 Agent 的意外行为
    • 追踪 Token 用量 - 监控 Token 消耗以优化提示词并降低成本
    • 使用系统提示词 - 在系统提示词中添加日志记录指令,使 Agent 解释其推理过程
    curl -fsSL "https://api.anthropic.com/v1/sessions/$SESSION_ID/events" \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01" \
    | jq -r '
      (.data[] | select(.type == "session.error") | "[\(.error.type)] \(.error.message)"),
      (reduce (.data[] | select(.type == "span.model_request_end") | .model_usage) as $u
         ({input: 0, output: 0}; .input += $u.input_tokens | .output += $u.output_tokens)
       | "Total input tokens: \(.input), output tokens: \(.output)")
    '