Skip to main content

ftai-agent-core

FtAi Agent Hub 的核心库 —— 协议定义、WebSocket 连接管理、认证、自动重连、人机交互机制。

这是一个基础包,通常不直接使用,而是由上层 adapter 包依赖:

安装

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)

Metadata

Release files for ftai-agent-core 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ftai-agent-core 0.3.0
File Size Uploaded
ftai_agent_core-0.3.0.tar.gz 9.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ftai-agent-core 0.3.0
File Interpreter ABI Platform
ftai_agent_core-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.4 kB

Release files / ftai_agent_core-0.3.0.tar.gz

Download URL ftai_agent_core-0.3.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3f1b5e89e01c4cd443160d88790c75ffbf8b60ff829e484641353497924d18b2
BLAKE2b-256 checksum
How to use checksums
e9204386e84a2f540ced140f097aed6492328162aef0209a010bb2ee69eeb72a
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / ftai_agent_core-0.3.0-py3-none-any.whl

Download URL ftai_agent_core-0.3.0-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fca97a54df4681a9453e6c641120e30b723a829eccaa5473b9c9db13f2b7ed15
BLAKE2b-256 checksum
How to use checksums
9b96b341784b65f48c621c838d923d54a9f04c844cf917ac3e12d01ee212cb74
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page