cagent

可用性: 实验性

cagent 允许您构建、编排和共享 AI 代理。您可以使用它来定义作为团队工作的 AI 代理。

cagent 依赖于 根代理 的概念,它充当团队负责人,并将任务委托给您定义的子代理。每个代理

  • 使用您选择的模型,并带有您选择的参数。
  • 可以访问 内置工具 和在 Docker MCP 网关 中配置的 MCP 服务器。
  • 在自己的上下文中工作。它们不共享知识。

根代理是您的主要联系点。每个代理都有自己的上下文,它们不共享知识。

关键特性

  • ️具有客户端隔离和会话管理的多租户架构。
  • 通过模型上下文协议 (MCP) 集成实现丰富的工具生态系统。
  • 具有智能任务委托的分层代理系统。
  • 多个接口,包括 CLI、TUI、API 服务器和 MCP 服务器。
  • 通过 Docker 注册表集成进行代理分发。
  • 以安全为先的设计,具有适当的客户端范围和资源隔离。
  • 事件驱动流,用于实时交互。
  • 多模型支持(OpenAI、Anthropic、Gemini、DMR、Docker AI Gateway)。

cagent 入门

  1. 下载适用于您操作系统的最新版本

    注意

    您可能需要为二进制文件授予可执行权限。在 macOS 和 Linux 上,运行

    chmod +x /path/to/downloads/cagent-linux-<arm/amd>64
    
    注意

    您也可以从源代码构建 cagent。请参阅 存储库

  2. 可选:根据需要重命名二进制文件并更新您的 PATH 以包含 cagent 的可执行文件。

  3. 设置以下环境变量

    # If using the Docker AI Gateway, set this environment variable or use
    # the `--models-gateway <url_to_docker_ai_gateway>` CLI flag
    
    export CAGENT_MODELS_GATEWAY=<url_to_docker_ai_gateway>
    
    # Alternatively, set keys for remote inference services.
    # These are not needed if you are using Docker AI Gateway.
    
    export OPENAI_API_KEY=<your_api_key_here>    # For OpenAI models
    export ANTHROPIC_API_KEY=<your_api_key_here> # For Anthropic models
    export GOOGLE_API_KEY=<your_api_key_here>    # For Gemini models
  4. 将此示例保存为 assistant.yaml 来创建一个代理

    assistant.yaml
    agents:
      root:
        model: openai/gpt-5-mini
        description: A helpful AI assistant
        instruction: |
          You are a knowledgeable assistant that helps users with various tasks.
          Be helpful, accurate, and concise in your responses.
  5. 使用您的代理开始您的提示

    cagent run assistant.yaml

创建一个智能代理团队

您可以使用 AI 提示通过 cagent new 命令生成一个代理团队

$ cagent new

For any feedback, visit: https://docker.qualtrics.com/jfe/form/SV_cNsCIg92nQemlfw

Welcome to cagent! (Ctrl+C to exit)

What should your agent/agent team do? (describe its purpose):

> I need a cross-functional feature team. The team owns a specific product
  feature end-to-end. Include the key responsibilities of each of the roles
  involved (engineers, designer, product manager, QA). Keep the description
  short, clear, and focused on how this team delivers value to users and the business.

或者,您可以手动编写配置文件。例如

agentic-team.yaml
agents:
  root:
    model: claude
    description: "Main coordinator agent that delegates tasks and manages workflow"
    instruction: |
      You are the root coordinator agent. Your job is to:
      1. Understand user requests and break them down into manageable tasks.
      2. Delegate appropriate tasks to your helper agent.
      3. Coordinate responses and ensure tasks are completed properly.
      4. Provide final responses to the user.
      When you receive a request, analyze what needs to be done and decide whether to:
      - Handle it yourself if it's simple.
      - Delegate to the helper agent if it requires specific assistance.
      - Break complex requests into multiple sub-tasks.
    sub_agents: ["helper"]

  helper:
    model: claude
    description: "Assistant agent that helps with various tasks as directed by the root agent"
    instruction: |
      You are a helpful assistant agent. Your role is to:
      1. Complete specific tasks assigned by the root agent.
      2. Provide detailed and accurate responses.
      3. Ask for clarification if tasks are unclear.
      4. Report back to the root agent with your results.

      Focus on being thorough and helpful in whatever task you're given.

models:
  claude:
    provider: anthropic
    model: claude-sonnet-4-0
    max_tokens: 64000

请参阅参考文档.

内置工具

cagent 包含一组内置工具,可增强您的代理功能。您无需配置任何外部 MCP 工具即可使用它们。

agents:
  root:
    # ... other config
    toolsets:
      - type: todo
      - type: transfer_task

思考工具

思考工具允许代理一步一步地推理问题

agents:
  root:
    # ... other config
    toolsets:
      - type: think

待办工具

待办工具帮助代理管理任务列表

agents:
  root:
    # ... other config
    toolsets:
      - type: todo

记忆工具

记忆工具提供持久存储

agents:
  root:
    # ... other config
    toolsets:
      - type: memory
        path: "./agent_memory.db"

任务转移工具

任务转移工具是一个内部工具,允许代理将任务委托给子代理。为防止代理委托工作,请确保其配置中没有定义子代理。

通过 Docker MCP 网关使用工具

如果您使用 Docker MCP 网关,您可以配置您的代理与网关交互并使用其中配置的 MCP 服务器。请参阅 docker mcp gateway run

例如,要使代理能够通过 MCP 网关使用 Duckduckgo

toolsets:
  - type: mcp
    command: docker
    args: ["mcp", "gateway", "run", "--servers=duckduckgo"]

CLI 交互式命令

在与代理的 CLI 会话期间,您可以使用以下 CLI 命令

命令描述
/exit退出程序
/reset清除会话历史记录
/eval保存当前对话以供评估
/compact压缩当前会话

分享您的代理

代理配置可以通过 Docker Hub 打包和共享。在开始之前,请确保您有一个 Docker 存储库

要推送代理

cagent push ./<agent-file>.yaml <namespace>/<reponame>

要将代理拉取到当前目录

cagent pull <namespace>/<reponame>

代理的配置文件名为 <namespace>_<reponame>.yaml。使用 cagent run <filename> 命令运行它。

© . This site is unofficial and not affiliated with Kubernetes or Docker Inc.