Skip to content

feat: add python_agent driver for Agno, LangGraph and plain-function agents - #1

Merged
ChenCJ-io merged 3 commits into
mainfrom
feat/python-agent-driver
Sep 23, 2026
Merged

ChenCJ-io merged 3 commits into
mainfrom
feat/python-agent-driver

Conversation

@ChenCJ-io

@ChenCJ-io ChenCJ-io commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Why / 动机

测试一个现有的 Agno 或 LangGraph Agent,原来必须先把它改造成一个实现 /chat/stream 协议、把工具执行交给 AgentRig 的服务,这是接入时最大的门槛。这个 PR 让现有 Python Agent 不改代码即可接受 AgentRig 驱动。

What changed / 改动

  • 新增 python_agent Driver 与只依赖标准库的 agentrig.sdk harness:
    • AgentRig 用被测项目自己的解释器启动 python -m agentrig.sdk.harness,通过 PYTHONPATH 提供 SDK 副本,被测环境无需安装 AgentRig,支持 Python 3.10+;
    • Agno Agent/Team:在 tool_hooks 链最内层接管用户声明的工具,Team 递归覆盖成员,委派等框架内置工具照常执行;
    • LangGraph(create_agent、create_react_agent、手写 StateGraph):在每个 ToolNode 的 wrap_tool_call 链最内层接管,用户 middleware 照常运行;
    • 普通函数 Agent:用 @agentrig.sdk.tool 标记工具;
    • harness 上报的工具定义写入 Capability Snapshot;
    • 被测进程只继承基础环境变量,模型 Key 经 credential_env 或 inherit_env 显式传入。
  • subprocess Driver:持续排空 stderr(保留末尾 16 KiB),单行上限 8 MiB,非 JSON 行返回错误事件,观察到的工具结果只保留摘要。
  • DriverPrepareContext 增加 tool_mode,执行器与「对话验证」都会传入。
  • python_agent 支持 conversation_initial_state,「对话验证」可以向 Curator 描述业务世界。
  • Simulation Curator:json_object 模式附上结构 Schema;外壳不合法时按反馈纠正一次(独立提交)。
  • 运行时依赖安全升级:anyio 4.14.1 → 4.15.1,修复 CVE-2026-63374、CVE-2026-64847、CVE-2026-63349(独立提交;main 当前的依赖审计同样会报这三项)。
  • 新增 Python Agent 接入指南,同步总体架构、实现与接入、安全部署、英文快速开始与中英文 README。
  • CI 新增 sdk-frameworks 任务:安装 frameworks 依赖组(Agno、LangChain、LangGraph,仅用于测试,不作为 extra 发布),并提供 Python 3.10 解释器。

Boundaries and risk / 边界与风险

  • 不包含:用例文件与 agentrig test(将另起 RFC)、真实工具结果录制、GitHub Action。
  • 已知限制(指南 §8):MCPTools 接管尚无自动化测试;Agno 需人工确认的工具会暂停运行;LangGraph 只用 ainvoke;工具循环跨多次 run 的 Agent 需要在入口里复刻服务逻辑(指南 §1.2 给出写法)。
  • 兼容性:无数据库迁移;新增 Driver 类型;DriverPrepareContext.tool_mode 为可选字段;subprocess Driver 遇到非 JSON 行时由抛异常改为返回错误事件。
  • 安全:python_agent 的解释器必须精确列入 subprocess_allowlist;被测进程拿不到 AgentRig 自身的 Secret。
  • 后续小项:概览页每 30 秒自动连通检查,对 python_agent 意味着每 30 秒启动一次被测进程,计划改为手动触发或缓存结果。
  • 回滚:revert 这两个提交即可。

Verification / 验证

  • uv run ruff check src tests scripts examples
  • uv run mypy src/agentrig
  • uv run pytest:224 passed,5 skipped(跳过项是需要外部服务的 live 测试与 PostgreSQL 测试)
  • tests/sdk 31 条:运行时语义、标准库边界与 3.10 语法、Driver 协议、stdout/stderr 噪声、observe 模式、环境隔离、Agno Agent/Team 与 LangGraph 适配、Curator 兜底、对话转用例、A/B 纵切
  • 在 Python 3.10 解释器上真实运行 harness
  • 跨版本:Agno 2.5.10 / 2.7.4(现有项目的虚拟环境,未安装 AgentRig)与 3.0.10,LangGraph 1.2.12
  • 真实 Agent 验证:一个生产级 Agno 2.6.11 Agent(38 个工具,客户端工具跨多次 run),真实模型 + Curator 完成「对话验证 → 生成草稿 → 补规则 → 回放 10/10 → A/B 拦截一次提示词回归」,发布门禁 fail、退出码 2
  • Reference Demo 与证据校验:CI 的 Public reference demo 通过;本 PR 的 9 个 CI 任务全部通过
  • 文档与 CHANGELOG 已更新
  • 无 Secret、私有数据、生成缓存或本机路径(仓库卫生扫描通过)
  • web/ 未改动

Evidence / 证据

真实 Agent A/B 的发布门禁输出(节选):

- 结论:fail
- fail outcome_regressions — threshold violated (actual=1, threshold=0)
- pass infrastructure_errors — threshold satisfied (actual=0, threshold=0)
- pass token_regression_ratio — threshold satisfied (actual=0.006207, threshold=0.1)

json_object 输出模式只保证输出是合法 JSON,不约束结构;现在和 prompt_json 一样附上结构 Schema。
模型返回合法 JSON 但外壳不是 {result, state_updates} 时,按校验反馈纠正一次,不再直接让
CaseRun 以 provider_exhausted 失败;网络等请求错误仍然立即失败。
…agents

新增 python_agent Driver 与只依赖标准库的 agentrig.sdk harness:用被测项目自己的解释器启动
harness,Agno Agent/Team 在 tool_hooks 链最内层、LangGraph 在 ToolNode 的 wrap_tool_call
链最内层接管工具,普通函数用 @agentrig.sdk.tool 标记。被测环境无需安装 AgentRig,支持
Python 3.10+;被测进程只继承基础环境变量,AgentRig 自身的 Secret 不会进入被测代码。

同时:
- subprocess Driver 持续排空 stderr,单行上限 8 MiB,非 JSON 行返回错误事件,观察结果只留摘要;
- DriverPrepareContext 增加 tool_mode,执行器与「对话验证」都会传入;
- python_agent 支持 conversation_initial_state,对话验证可以向 Curator 描述业务世界;
- 新增 Python Agent 接入指南,同步架构、实现、部署文档与中英文 README;
- CI 增加 SDK 框架适配任务,在最新 Agno、LangGraph 与 Python 3.10 上验证 harness。
…6-63349

运行时依赖审计报告 anyio 4.14.1 存在三个已知漏洞,4.14.2 起修复;锁文件升级到 4.15.1,
其余依赖不变。
@ChenCJ-io
ChenCJ-io merged commit dbc3413 into main Sep 23, 2026
9 checks passed
@ChenCJ-io
ChenCJ-io deleted the feat/python-agent-driver branch September 23, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant