Core library for FtAi Agent Hub clients: protocol, connection management, and reconnection
Project description
ftai-agent-core
FtAi Agent Hub 的核心库 —— 协议定义、WebSocket 连接管理、认证、自动重连、人机交互机制。
这是一个基础包,通常不直接使用,而是由上层 adapter 包依赖:
ftai-langchain— LangChain / LangGraph 通用适配器ftai-deep-agent— DeepAgent 瘦包装
安装
uv add ftai-agent-core
模块结构
ftai_agent_core/
├── protocol.py # 协议常量、JSON 编解码、消息构建函数(纯函数,无 I/O)
├── client.py # BaseAgentHubClient 抽象基类
└── errors.py # AuthError 异常
编写自定义 Adapter
继承 BaseAgentHubClient,实现 _process_chat() 方法:
from ftai_agent_core import BaseAgentHubClient
from ftai_agent_core import protocol
class MyClient(BaseAgentHubClient):
async def _process_chat(self, request_id: str, messages: list[dict]) -> None:
# 1. 将 OpenAI 格式的 messages 转换为你的框架格式
# 2. 流式调用你的 Agent
# 3. 通过 self._send() 发送响应
for chunk in my_agent.stream(messages):
await self._send(protocol.stream_text(request_id, chunk))
# base class 会自动发送 message_end
BaseAgentHubClient 已内置:
| 能力 | 说明 |
|---|---|
| 认证 | WebSocket 连接后自动发送 auth,处理 auth_ok / auth_error |
| 自动重连 | 指数退避(2s → 4s → ... → 60s),认证成功后重置 |
| 并发聊天 | 每个 chat_request 独立 asyncio.Task,互不阻塞 |
| 取消 | 收到 cancel 时自动 task.cancel() |
| 人机交互 | self._request_hil(prompt) / self.human_in_loop_tool |
| 发送序列化 | asyncio.Lock 保证并发 task 的 WebSocket 写入不交叉 |
| 错误处理 | 异常自动发送 error 帧,取消自动发送 message_end(cancel) |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ftai_agent_core-0.3.0.tar.gz
(9.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ftai_agent_core-0.3.0.tar.gz.
File metadata
- Download URL: ftai_agent_core-0.3.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f1b5e89e01c4cd443160d88790c75ffbf8b60ff829e484641353497924d18b2
|
|
| MD5 |
adc4c5506b88d3df98eaecd025607874
|
|
| BLAKE2b-256 |
e9204386e84a2f540ced140f097aed6492328162aef0209a010bb2ee69eeb72a
|
File details
Details for the file ftai_agent_core-0.3.0-py3-none-any.whl.
File metadata
- Download URL: ftai_agent_core-0.3.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fca97a54df4681a9453e6c641120e30b723a829eccaa5473b9c9db13f2b7ed15
|
|
| MD5 |
e96a59f4df07963c4f83884e794860c2
|
|
| BLAKE2b-256 |
9b96b341784b65f48c621c838d923d54a9f04c844cf917ac3e12d01ee212cb74
|