reglow-agent-client(Python)
Reglow Agent 运行时薄 SDK:DTO + HTTP 客户端 + 错误映射。 不实现执行循环、不缓存状态、不自动重试非幂等请求。
适用于独立部署的 reglow-agent-service,也支持任意同契约的运行时实现。
安装
pip install reglow-agent-client
本地开发(仓库内):
cd reglow-library/reglow-agent-client/python
pip install -e ".[dev]"
pytest tests
快速开始
from reglow_agent_client import AgentClient
with AgentClient(
"http://localhost:7000",
tenant_id=1, # 对应 X-Tenant-Id
token="<platform-token>",
) as client:
definition = client.definitions.create(
key="cs_agent",
name="客服 Agent",
spec={"model_policy": {"primary": "deepseek/flash"}},
eval_suite="eval://cs/default",
)
client.definitions.publish(definition.id)
run = client.runs.create(agent_key="cs_agent", input={"q": "退款政策"})
for event in client.runs.iter_events(run.id):
print(event.seq, event.event_type)
能力
| 组 | 主要方法 |
|---|---|
chat |
chat(POST /chat,一次性对话) |
definitions |
list/create/get/update/publish/versions/ensure/delete |
tools |
list/register/update/delete/discover_mcp |
workflows |
list/create/get/update/delete/publish/versions/ensure/disable/enable/run |
runs |
create/get/list/cancel/events/iter_events/stream_events/timeline/diff/resume/rework/compensate/replay |
approvals |
list/approve/reject/modify |
sessions |
create/get/list/messages/append/summarize/context/close |
memory |
list/write/delete/purge |
blackboard |
list/get/put/delete(乐观锁 expected_version) |
knowledge |
search/citations |
eval |
suites/cases/upsert_case/delete_case/run/runs/get_run/regression/gate |
feedback |
submit/list/summary/sample_reviews/reviews/decide_review/review_summary/failure_clusters |
audit |
list/verify(审计哈希链校验) |
配置
| 参数 | 默认 | 说明 |
|---|---|---|
base_url |
必填 | 运行时地址 |
tenant_id |
0 |
写入 X-Tenant-Id |
app_id |
None |
写入 X-Agent-App(缺省不发送) |
token |
None |
Authorization: Bearer |
timeout |
30 |
秒 |
admin_prefix |
/admin/api/v1/agent |
管理端前缀 |
headers |
None |
追加请求头 |
transport |
None |
httpx transport(测试可注入 MockTransport) |
token_provider |
None |
每次请求动态返回 token(优先于 token) |
tenant_provider |
None |
每次请求动态返回租户(优先于 tenant_id) |
app_provider |
None |
每次请求动态返回产品线(优先于 app_id) |
错误处理
from reglow_agent_client import ApiError
try:
client.runs.cancel(1)
except ApiError as exc:
print(exc.code, exc.http_status, exc.message, exc.payload)
智能工坊桥接
SdkStudioAgentBridge 是投影模式参考实现,宿主注入基础库注册表即可:
from reglow.modules.studio.agent_bridge import set_agent_bridge
from reglow_agent_client import AgentClient, SdkStudioAgentBridge
set_agent_bridge(SdkStudioAgentBridge(AgentClient(
"http://localhost:8000", tenant_id=1, token=token,
)))
覆盖:工作流 get-or-create + 发布、启动运行、timeline 同步、审批/恢复/取消。
若使用 reglow 基础库(Python),推荐直接配置服务变量自动接入,无需手写注入:
pip install "reglow[agent]"
AGENT_SERVICE_URL=http://localhost:7000
AGENT_SERVICE_SERVICE_ACCOUNT_ID=1 # 无请求上下文时自动签发短时 token
认证优先级:请求 Authorization → 服务账号自动签发 → 静态 AGENT_SERVICE_TOKEN。
未配置 AGENT_SERVICE_URL 时工坊保持本地引擎;配置后启动即自动注册本桥接。
发布
当前版本:1.0.0(2026-11-30,首个正式稳定版)。发布窗口、凭证与四语言顺序见 RELEASING.md。
python -m build
twine upload --repository testpypi dist/* # 预发(可选)
twine upload dist/* # 正式(~/.pypirc 或 TWINE_* 凭证)
说明
- 运行时需独立部署(或 Python 宿主 embedded 方式挂载)。
- 事件推送需按
seq游标轮询,SDK 不维持后台连接。 - 版本与
contract/agent.json对齐,升级时同步运行时与 SDK。
Metadata
Release files for reglow-agent-client 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| reglow_agent_client-1.0.0.tar.gz | 37.7 kB | Without provenance | Details for reglow_agent_client-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| reglow_agent_client-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for reglow_agent_client-1.0.0-py3-none-any.whl |
Total release size: 64.8 kB
Release files / reglow_agent_client-1.0.0.tar.gz
| Download URL | reglow_agent_client-1.0.0.tar.gz |
|---|---|
| Size | 37.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0bbaeedf2817041ebfdf363b342e92f1c3d7ec7ecaec757ab7779f57afe456c3
|
|
BLAKE2b-256 checksum How to use checksums |
cdc11d47ad937b79732c57130e458d32daa9ed4476c6b179cb5ce47913f511b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / reglow_agent_client-1.0.0-py3-none-any.whl
| Download URL | reglow_agent_client-1.0.0-py3-none-any.whl |
|---|---|
| Size | 27.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
96533b43e41d465305ed65db2d27e130dec8297a53bf69be616a6ad9b4dc8040
|
|
BLAKE2b-256 checksum How to use checksums |
7b04310c32f5f9ba0eecd8ee469238d649f88d21bab20e623d4f63d791060893
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for reglow-agent-client 1.0.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.