Skip to content

fix(agent): honor returnDirect routing#4786

Open
6mmLIU wants to merge 1 commit into
alibaba:mainfrom
6mmLIU:agent/fix-react-agent-return-direct-routing
Open

fix(agent): honor returnDirect routing#4786
6mmLIU wants to merge 1 commit into
alibaba:mainfrom
6mmLIU:agent/fix-react-agent-return-direct-routing

Conversation

@6mmLIU

@6mmLIU 6mmLIU commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the ReactAgent returnDirect routing behavior reported in #4427.

jump_to is a transient hook routing command, but it was stored in graph state. After a returnDirect tool set jump_to=end, the checkpoint for that turn could carry the stale command into a later invocation on the same thread and short-circuit before the model ran. ReactAgent also did not install the existing return-direct model hook by default, so @Tool(returnDirect = true) was not honored unless users wired the hook manually.

This change:

  • registers ReturnDirectModelHook automatically for tool-enabled ReactAgent instances unless an equivalent hook is already present
  • consumes and removes jump_to when routing so one-shot hook decisions do not leak through checkpoints or later turns
  • routes tool-node output back through the before-model hook chain, letting ReturnDirectModelHook end direct tool responses while normal tools still return to the model
  • adds a mock ChatModel regression test covering direct tools, same-thread follow-up turns, and normal tool routing

Fixes #4427

Tests

  • ./mvnw -pl :spring-ai-alibaba-agent-framework -am -Dtest=ReactAgentReturnDirectRoutingTest test

@6mmLIU 6mmLIU marked this pull request as ready for review July 7, 2026 06:42

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 25af7143e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

[BUG] ReactAgent returnDirect错误

1 participant