fp-acp — FP ACP 通信协议
简介
fp-acp 实现了 FP 的 Agent Communication Protocol(ACP),一个基于 JSON-RPC 2.0 的通信协议。它允许外部进程(IDE 插件、其他 Agent、自动化脚本)通过标准化的 API 与 Agent 交互。
通过
pip install fp-agent[acp]或pip install fp-acp安装。
什么是 ACP?
ACP(Agent Communication Protocol)定义了 Agent 与外部世界之间的标准通信契约。它使得:
- IDE 集成 — VS Code、Neovim、Emacs 等编辑器通过 ACP 调用 Agent 能力
- 跨 Agent 通信 — 多个 Agent 实例通过 ACP 协作完成任务
- 自动化管道 — CI/CD 脚本通过 ACP 集成 Agent 进行代码审查、文档生成等
┌──────────┐ JSON-RPC 2.0 ┌───────────┐
│ IDE │ ◄────────────────► │ ACP │
│ 插件/ │ │ Server │──► fp-core Agent
│ 脚本 │ │ (fp-acp) │
└──────────┘ └───────────┘
安装
pip install fp-acp
要求 Python >= 3.11。
快速使用
默认端口
fp-acp
指定主机和端口
fp-acp --host 127.0.0.1 --port 9090
启动日志:
╭─ FP ACP Server ────────────────╮
│ │
│ 监听地址: tcp://127.0.0.1:9090 │
│ 协议: JSON-RPC 2.0 │
│ │
│ 按 Ctrl+C 停止服务 │
╰───────────────────────────────────────────╯
JSON-RPC 接口
ACP 使用标准的 JSON-RPC 2.0 协议,支持以下方法:
核心方法
| 方法 | 参数 | 返回 | 说明 |
|---|---|---|---|
chat |
{message, session_id?, stream?} |
{response} |
发送消息并获取回复 |
chat_stream |
{message, session_id?} |
SSE 流 | 流式聊天(Server-Sent Events) |
tools/list |
{} |
[{name, description, parameters}] |
获取可用工具列表 |
tools/call |
{name, arguments} |
{result} |
直接调用工具 |
sessions/list |
{} |
[{id, created_at, message_count}] |
列出会话 |
sessions/create |
{id?} |
{id} |
创建新会话 |
sessions/delete |
{id} |
{success} |
删除会话 |
sessions/history |
{id, limit?} |
[{role, content}] |
获取会话历史 |
config/get |
{} |
{config} |
获取当前配置 |
config/set |
{key, value} |
{success} |
更新配置项 |
ping |
{} |
{pong} |
健康检查 |
shutdown |
{} |
{success} |
优雅关闭 Server |
调用示例
使用 curl
# 发送聊天消息
curl -X POST http://127.0.0.1:9090 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "chat",
"params": {
"message": "你好,请介绍一下自己",
"session_id": "my-session"
}
}'
响应:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"response": "你好!我是 FP,一个基于生命周期钩子的插件化 Agent。"
}
}
使用 Python
import httpx
rpc_request = {
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {}
}
response = httpx.post("http://127.0.0.1:9090", json=rpc_request)
tools = response.json()["result"]
print(tools)
使用场景
1. VS Code 集成
通过 ACP,VS Code 扩展可以直接调用 Agent 进行代码审查、重构建议、自动补全:
用户选中代码 → 右键 "Ask FP" → ACP Server 返回分析结果
2. 多 Agent 协作
# Agent A 通过 ACP 调用 Agent B 的专业能力
response = httpx.post("http://agent-b:9090", json={
"jsonrpc": "2.0",
"method": "chat",
"params": {"message": "请分析这段代码的安全性: ..."}
})
3. CI/CD 集成
# .github/workflows/code-review.yml
jobs:
review:
steps:
- run: |
curl -X POST http://agent:9090 \
-H "Content-Type: application/json" \
-d '{
"method": "chat",
"params": {
"message": "Review the diff in commit ${{ github.sha }}"
}
}'
安全说明
- ACP Server 默认绑定
127.0.0.1(仅本地访问) - 如果需要远程访问,使用
--host 0.0.0.0并配合防火墙或反向代理 - 生产环境建议添加 TLS 加密和 API 认证
依赖
| 依赖 | 版本 | 用途 |
|---|---|---|
fp-core |
>= 0.1.0 | Agent 核心引擎 |
许可
MIT © zpb
Metadata
Release files for fp-acp 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fp_acp-0.2.1.tar.gz | 25.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fp_acp-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 47.5 kB
Release files / fp_acp-0.2.1.tar.gz
| Download URL | fp_acp-0.2.1.tar.gz |
|---|---|
| Size | 25.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac799bba52337131e281d9843fb92758ca4ed7e5c112ee877d3f804736480665
|
|
BLAKE2b-256 checksum How to use checksums |
56cea2cc41c5f0797dfce9e95e3c3e653f96604081997e79a40e0f32acb8ddd8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.
Transparency logRelease files / fp_acp-0.2.1-py3-none-any.whl
| Download URL | fp_acp-0.2.1-py3-none-any.whl |
|---|---|
| Size | 21.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c246f89a2f1d3e0654fb794ba468efd1bbf040f5f509591bfd9f02e336aa0b6
|
|
BLAKE2b-256 checksum How to use checksums |
82e44fc7023c5da421bab80c6ee53d6119a4315285df2b5e8121789f79337c8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.
Transparency log