feat(adk): add support for early stop instructions#755
feat(adk): add support for early stop instructions#755crossProblems wants to merge 2 commits intocloudwego:mainfrom
Conversation
|
This PR adds LangChain-compatible early stopping behavior to the ADK ReAct agent when MotivationToday, when the ReAct agent reaches
This PR brings the same option to Eino’s API changesAdded to
Internally, Behavior
This ensures a “final answer” attempt instead of looping into tools once the iteration budget is exhausted. Implementation highlights
Tests
中文补充这个 PR 为 ADK 的 ReAct agent 增加了类似 LangChain 的
|
|
这种处理流程:抛出ErrExceedMaxIterations -> 应用层捕获这个 error -> 以预设的 query 再次发起 agent 调用。感觉跟你这里的配置是等价的。 |
我理解您说的“应用层捕获ErrExceedMaxIterations后用预设query再次调用agent”的方案,在直接调用单个agent的场景确实可以达到类似效果;但我这次主要想覆盖的是agent被adk.NewAgentTool包装成“子Agent工具”之后的链路:当子Agent触发ErrExceedMaxIterations时,这个error往往会作为tool调用失败向上冒泡,最终导致最外层Agent也直接失败。此时应用层通常只能重新对最外层Agent发起一次完整query,而无法在同一次执行里对作为工具的子Agent做“追加总结指令/再生成一次最终输出”的收敛处理,所以我希望在框架侧提供generate这种可配置的early stopping,让子Agent在触顶时仍能返回一个best-effort的final answer(且不再进入工具调用),从而避免错误扩散把整条链路打断。 |
|
AgentTool 的话,可以写一个 middleware 配置给外层的 ChatModelAgent,捕获这个特定 error,转换成 tool result 给模型。 |
明白您的意思。不过这种做法下,外层通常只能拿到子Agent触顶的提示信息,而拿不到子Agent基于自身完整上下文生成的best-effort最终答案,我也注意到有OutputKey这个参数,但一旦报错它往往会为空,或者最多只能拿到最后一次的输出,同时还需要在每个使用AgentTool的场景里单独配置拦截与转换逻辑。相比之下,将force/generate作为子Agent自身(也适用于普通Agent)的可选行为更内聚,集成成本更低,对使用eino开发Agent的开发者来说更加便捷,您觉得呢。 |
What type of PR is this?
Check the PR title.
(Optional) Translate the PR title into Chinese.
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en:
zh(optional):
(Optional) Which issue(s) this PR fixes:
(optional) The PR that updates user documentation: