[PR #28704] Add the return_direct capability to tools: supports skipping the LLM and directly returning the final answer #32143

Closed
opened 2026-02-21 20:50:50 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/28704

State: closed
Merged: No


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

After the tool is called, Dify's Agent will inject the tool response as an Observation into LLM, which will then output the final answer; When the tool returns excessively long text/JSON (such as ECharts configuration), it will significantly increase context load and latency, for example, my workflow may involve Echart charts for 2000 sets of data
Learn from Langchain to enable agents to skip LLM when calling certain tools.

-Add a return signal (strictly Boolean True) to pass from the tool message to the Agent Runner.
-FC Runner adopts the strategy of "short circuit only when all tools return directly": when all tools in the same round are return-direct=True, after executing all tools, aggregate the text as the final answer and return directly; Otherwise, continue back to LLM. Framework similar to Langgraph.

Provided some screenshots of the tests

Screenshots

1 3 4 5 6

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/28704 **State:** closed **Merged:** No --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary After the tool is called, Dify's Agent will inject the tool response as an Observation into LLM, which will then output the final answer; When the tool returns excessively long text/JSON (such as ECharts configuration), it will significantly increase context load and latency, for example, my workflow may involve Echart charts for 2000 sets of data Learn from Langchain to enable agents to skip LLM when calling certain tools. -Add a return signal (strictly Boolean True) to pass from the tool message to the Agent Runner. -FC Runner adopts the strategy of "short circuit only when all tools return directly": when all tools in the same round are return-direct=True, after executing all tools, aggregate the text as the final answer and return directly; Otherwise, continue back to LLM. Framework similar to Langgraph. Provided some screenshots of the tests ## Screenshots <img width="1875" height="627" alt="1" src="https://github.com/user-attachments/assets/c53f645c-d870-417e-af9b-ecb6c9d28f20" /> <img width="1404" height="801" alt="3" src="https://github.com/user-attachments/assets/91e079f0-139e-4adc-a9d9-d45c98bca9b2" /> <img width="897" height="536" alt="4" src="https://github.com/user-attachments/assets/8c534ce7-d579-4081-8485-9c16c8ecad7c" /> <img width="521" height="500" alt="5" src="https://github.com/user-attachments/assets/6b0354e9-1630-41ad-9f3a-899e2b002459" /> <img width="528" height="255" alt="6" src="https://github.com/user-attachments/assets/b2b2a8de-50ff-4d69-9e49-48312a157aec" /> ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:50:50 -05:00
yindo closed this issue 2026-02-21 20:50:50 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32143