agentica-server
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAgentica Server + Claude Proxy Setup
Agentica Server + Claude Proxy 搭建指南
Complete reference for running Agentica SDK with a local Claude proxy. This enables Python agents to use Claude CLI as their inference backend.
这是一份使用本地Claude Proxy运行Agentica SDK的完整参考文档,它能让Python Agent将Claude CLI作为推理后端。
When to Use
使用场景
Use this skill when:
- Starting Agentica development with Claude proxy
- Debugging connection issues between SDK, server, and proxy
- Setting up a fresh Agentica environment
- Troubleshooting agent tool access or hallucination issues
在以下场景中使用本指南:
- 开始基于Claude Proxy的Agentica开发
- 调试SDK、服务器与Proxy之间的连接问题
- 搭建全新的Agentica环境
- 排查Agent工具访问或幻觉问题
Architecture
架构设计
Agentica SDK (client code)
| S_M_BASE_URL=http://localhost:2345
v
ClientSessionManager
|
v
Agentica Server (agentica-server)
| INFERENCE_ENDPOINT_URL=http://localhost:8080/v1/chat/completions
v
Claude Proxy (claude_proxy.py)
|
v
Claude CLI (claude -p)Agentica SDK (client code)
| S_M_BASE_URL=http://localhost:2345
v
ClientSessionManager
|
v
Agentica Server (agentica-server)
| INFERENCE_ENDPOINT_URL=http://localhost:8080/v1/chat/completions
v
Claude Proxy (claude_proxy.py)
|
v
Claude CLI (claude -p)Environment Variables
环境变量
| Variable | Set By | Used By | Purpose |
|---|---|---|---|
| Human | agentica-server | Where server sends LLM inference requests |
| Human | Agentica SDK client | Where SDK connects to session manager |
KEY: These are NOT the same endpoint!
- SDK connects to server (port 2345)
- Server connects to proxy (port 8080)
| 变量名 | 设置方 | 使用方 | 用途 |
|---|---|---|---|
| 人工配置 | agentica-server | 服务器发送LLM推理请求的地址 |
| 人工配置 | Agentica SDK客户端 | SDK连接会话管理器的地址 |
**重点提示:**这两个端点并不相同!
- SDK连接服务器(端口2345)
- 服务器连接Proxy(端口8080)
Startup Sequence
启动流程
Must start in this order (each in a separate terminal):
必须按以下顺序启动(每个步骤在单独终端中执行):
Terminal 1: Claude Proxy
终端1:启动Claude Proxy
bash
uv run python scripts/agentica/claude_proxy.py --port 8080bash
uv run python scripts/agentica/claude_proxy.py --port 8080Terminal 2: Agentica Server
终端2:启动Agentica Server
MUST run from its directory:
bash
cd workspace/agentica-research/agentica-server
INFERENCE_ENDPOINT_URL=http://localhost:8080/v1/chat/completions uv run agentica-server --port 2345必须在其所在目录下运行:
bash
cd workspace/agentica-research/agentica-server
INFERENCE_ENDPOINT_URL=http://localhost:8080/v1/chat/completions uv run agentica-server --port 2345Terminal 3: Your Agent Script
终端3:运行你的Agent脚本
bash
S_M_BASE_URL=http://localhost:2345 uv run python scripts/agentica/your_script.pybash
S_M_BASE_URL=http://localhost:2345 uv run python scripts/agentica/your_script.pyHealth Checks
健康检查
bash
undefinedbash
undefinedClaude proxy health
检查Claude Proxy健康状态
Agentica server health
检查Agentica Server健康状态
undefinedundefinedCommon Errors & Fixes
常见错误与修复方案
1. APIConnectionError after agent spawn
1. Agent启动后出现APIConnectionError
Symptom: Agent spawns successfully but fails on first call with connection error.
Cause: Claude proxy returning plain JSON instead of SSE format.
Fix: Proxy must return Server-Sent Events format:
data: {"choices": [...]}\n\n**症状:**Agent成功启动,但首次调用时出现连接错误。
**原因:**Claude Proxy返回的是普通JSON格式,而非SSE格式。
**修复:**Proxy必须返回Server-Sent Events格式:
data: {"choices": [...]}\n\n2. ModuleNotFoundError for agentica-server
2. agentica-server模块找不到(ModuleNotFoundError)
Symptom:
ModuleNotFoundError: No module named 'agentica_server'Cause: Running from wrong directory.
uv run agentica-serverFix: Must first.
cd workspace/agentica-research/agentica-server**症状:**出现错误
ModuleNotFoundError: No module named 'agentica_server'**原因:**在错误的目录下执行命令。
uv run agentica-server**修复:**必须先进入目录
workspace/agentica-research/agentica-server3. Agent can't use Read/Write/Edit tools
3. Agent无法使用读/写/编辑工具
Symptom: Agent asks for file contents instead of reading them.
Cause: Missing in claude_proxy.py CLI call.
--allowedToolsFix: Proxy must pass tool permissions:
bash
claude -p ... --allowedTools Read Write Edit Bash**症状:**Agent询问文件内容而非直接读取。
**原因:**claude_proxy.py的CLI调用中缺少参数。
--allowedTools**修复:**Proxy必须传递工具权限:
bash
claude -p ... --allowedTools Read Write Edit Bash4. Agent claims success but didn't do task
4. Agent声称任务成功但未实际执行
Symptom: Agent says "I've created the file" but file doesn't exist.
Cause: Hallucination - agent describing intended actions without executing.
Fix: Added emphatic anti-hallucination prompt in REPL_BASELINE:
CRITICAL: Use ACTUAL tools. Never DESCRIBE using tools.**症状:**Agent说“我已创建文件”但文件实际不存在。
**原因:**幻觉问题 - Agent描述了预期操作但并未实际执行。
**修复:**在REPL_BASELINE中添加明确的反幻觉提示:
CRITICAL: Use ACTUAL tools. Never DESCRIBE using tools.5. Timeout on agent.call()
5. agent.call()请求超时
Symptom: Call hangs for 30+ seconds then times out.
Cause: Claude CLI taking too long or stuck in a loop.
Fix: Check proxy logs for the actual CLI output. May need to simplify prompt.
**症状:**调用卡住30秒以上后超时。
**原因:**Claude CLI处理时间过长或陷入循环。
**修复:**查看Proxy日志中的CLI实际输出,可能需要简化提示词。
Key Files
关键文件
| File | Purpose |
|---|---|
| OpenAI-compatible proxy with SSE streaming |
| Local agentica-server installation |
| Multi-agent pattern documentation |
| 文件路径 | 用途 |
|---|---|
| 支持SSE流式传输的OpenAI兼容Proxy |
| 本地agentica-server安装目录 |
| 多Agent模式文档 |
Quick Verification
快速验证
Test the full stack:
bash
undefined测试完整链路:
bash
undefined1. Verify proxy responds
1. 验证Proxy响应
2. Verify server responds
2. 验证Server响应
3. Test inference through proxy
3. 通过Proxy测试推理功能
curl http://localhost:8080/v1/chat/completions
-H "Content-Type: application/json"
-d '{"model":"claude","messages":[{"role":"user","content":"Say hello"}]}'
-H "Content-Type: application/json"
-d '{"model":"claude","messages":[{"role":"user","content":"Say hello"}]}'
undefinedcurl http://localhost:8080/v1/chat/completions
-H "Content-Type: application/json"
-d '{"model":"claude","messages":[{"role":"user","content":"Say hello"}]}'
-H "Content-Type: application/json"
-d '{"model":"claude","messages":[{"role":"user","content":"Say hello"}]}'
undefinedChecklist
检查清单
Before running agents:
- Claude proxy running on port 8080
- Agentica server running on port 2345 (from its directory)
- set for client scripts
S_M_BASE_URL - set for server
INFERENCE_ENDPOINT_URL - Both health checks return 200
运行Agent前请确认:
- Claude Proxy已在端口8080启动
- Agentica Server已在端口2345启动(需在对应目录下运行)
- 客户端脚本已设置
S_M_BASE_URL - 服务器已设置
INFERENCE_ENDPOINT_URL - 两项健康检查均返回200状态码