cagent
cagent 允許您構建、編排和共享 AI 代理。您可以使用它來定義作為團隊工作的 AI 代理。
cagent 依賴於 根代理 的概念,它充當團隊負責人,並將任務委託給您定義的子代理。每個代理
- 使用您選擇的模型,並帶有您選擇的引數。
- 可以訪問 內建工具 和在 Docker MCP 閘道器 中配置的 MCP 伺服器。
- 在自己的上下文中工作。它們不共享知識。
根代理是您的主要聯絡點。每個代理都有自己的上下文,它們不共享知識。
關鍵特性
- ️具有客戶端隔離和會話管理的多租戶架構。
- 透過模型上下文協議 (MCP) 整合實現豐富的工具生態系統。
- 具有智慧任務委託的分層代理系統。
- 多個介面,包括 CLI、TUI、API 伺服器和 MCP 伺服器。
- 透過 Docker 登錄檔整合進行代理分發。
- 以安全為先的設計,具有適當的客戶端範圍和資源隔離。
- 事件驅動流,用於即時互動。
- 多模型支援(OpenAI、Anthropic、Gemini、DMR、Docker AI Gateway)。
cagent 入門
下載適用於您作業系統的最新版本。
注意您可能需要為二進位制檔案授予可執行許可權。在 macOS 和 Linux 上,執行
chmod +x /path/to/downloads/cagent-linux-<arm/amd>64
注意您也可以從原始碼構建 cagent。請參閱 儲存庫。
可選:根據需要重新命名二進位制檔案並更新您的 PATH 以包含 cagent 的可執行檔案。
設定以下環境變數
# 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
將此示例儲存為
assistant.yaml
來建立一個代理assistant.yamlagents: 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.
使用您的代理開始您的提示
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.
或者,您可以手動編寫配置檔案。例如
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>
命令執行它。
相關頁面
- 有關 cagent 的更多資訊,請參閱 GitHub 儲存庫。
- Docker MCP 閘道器