Skip to content

支持 OpenAI Responses API 及 Agent Node HITL 交互#226

Closed
pcerypeng wants to merge 3 commits into
trpc-group:mainfrom
pcerypeng:main
Closed

支持 OpenAI Responses API 及 Agent Node HITL 交互#226
pcerypeng wants to merge 3 commits into
trpc-group:mainfrom
pcerypeng:main

Conversation

@pcerypeng

Copy link
Copy Markdown

OpenAIModel 支持 OpenAI Responses API(use_responses_api 可选参数)
Agent Node 支持 HITL 多轮人机交互(LongRunningEvent 中断传播 + 恢复)
新增 is_tool_execution_error() 工具执行错误检测能力

- 新增 use_responses_api 参数,使用 client.responses.create 替代 Chat Completions
- 支持 responses_api_params 透传 store、reasoning、truncation 等待有参数
- 新增 _convert_messages_to_responses_input 实现消息格式转换
- 新增 _create_responses_response 解析 Responses API 返回结果
- 支持流式 reasoning、文本和 tool call 增量
- 升级 openai 最低版本依赖至 1.66.0
- AgentNodeAction 支持 LongRunningEvent 中断并传播到父 Graph
- 支持多轮 HITL 交互及服务重启后正确恢复
- 新增 _trpc_agent_node_hitl 标记区分 HITL 中断与其他中断
- 更新 Graph 中英文文档
- 新增 is_tool_execution_error() 函数,区分 Provider 参数解析错误和 HITL 检查点
- LongRunningFunctionTool 集成错误检测,避免错误的工具响应被误判为 HITL 恢复
- is_tool_execution_error 添加到公开 API
@helloopenworld

Copy link
Copy Markdown
Contributor

AI Code Review

我已经掌握了足够的信息。现在我来整理审查报告。

发现的问题

🚨 Critical

(无)

⚠️ Warning

  • trpc_agent_sdk/models/_openai_model.py:1255-1256_convert_api_params_to_responsesparameter_map):Responses 模式下会把 top_logprobs 原样透传给 client.responses.create,但 Responses API 不支持顶层 top_logprobs(logprobs 需用 logprobs={"enabled":...} 结构)。当 use_responses_api=True 且请求配置开启 logprobs 时会触发上游 400 错误。建议在 Responses 路径中跳过 LOGPROBS/TOP_LOGPROBS 或映射为 Responses 的 logprobs 结构。

  • trpc_agent_sdk/tools/_long_running_tool.py:20-36is_tool_execution_error):判定启发式过于宽松——只要响应含 error/error_message 键或 result/message 文本中出现 "json parse error" 等子串即判为错误。合法的 LongRunning/HITL 工具若以 {"status":"error",...} 表达业务级拒绝、或正常返回文本恰好包含这些 marker,会被错误降级为普通工具响应、跳过 HITL 挂起并触发模型重试。建议仅对明确的参数解析失败信号判定,或要求 status 与 marker 同时命中。

💡 Suggestion

  • tests/trpc_agent_dsl/graph/test_agent_node_hitl.py:689:737received_call_ids: list[str] = [] 是类级可变属性,跨用例/重复执行会在同一进程内累积污染断言。建议在 fixture 或用例开头重置为实例属性,避免顺序依赖导致的脆弱测试。

总结

整体风险可控:HITL 多轮提升与 Responses API 适配的核心逻辑(interrupt 重放、子状态持久化、reasoning 往返)有测试覆盖且与 LangGraph 语义一致,未发现阻塞级问题。两处 Warning 分别是 Responses 路径下 logprobs 参数兼容性和工具错误判定启发式过宽,建议修复但非必须。

测试建议

  • 补充 Responses 模式开启 response_logprobs/logprobs 的用例,验证不会向 /v1/responses 透传不支持的 top_logprobs
  • 补充 LongRunning 工具返回 {"status":"error"} 业务级失败响应的用例,确认 HITL 提升行为符合预期(不被误判为参数解析错误而降级)。

@github-actions

Copy link
Copy Markdown

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


pcerypeng seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.07092% with 42 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@5ca3bf2). Learn more about missing BASE report.

Files with missing lines Patch % Lines
trpc_agent_sdk/models/_openai_model.py 88.40580% 32 Missing ⚠️
trpc_agent_sdk/agents/_llm_agent.py 79.16667% 5 Missing ⚠️
trpc_agent_sdk/dsl/graph/_node_action/_agent.py 96.20253% 3 Missing ⚠️
trpc_agent_sdk/tools/_long_running_tool.py 89.47368% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main        #226   +/-   ##
==========================================
  Coverage        ?   87.92616%           
==========================================
  Files           ?         479           
  Lines           ?       45230           
  Branches        ?           0           
==========================================
  Hits            ?       39769           
  Misses          ?        5461           
  Partials        ?           0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pcerypeng pcerypeng closed this Jul 23, 2026
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.

2 participants