Agent node returns raw tool call tags instead of error/event when Max Iterations reached #21385

Closed
opened 2026-02-21 20:12:19 -05:00 by yindo · 1 comment
Owner

Originally created by @XiyanHou-SDNware on GitHub (Dec 31, 2025).

Originally assigned to: @fatelei on GitHub.

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.11.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. In the Agent node, set a small value for "Max Iterations" (e.g., 2).
  2. Trigger the Chatflow. Once the Agent node reaches the maximum number of iterations, it directly returns the raw tool call tags/markers in the output.
Image Image

✔️ Expected Behavior

  • The SSE response should include a specific event type or an error/exception prompt indicating that the iteration limit has been reached.

Actual Behavior

  • The node directly outputs the raw tool call tags (e.g., <tool_call>) in the final response text.
Image
Originally created by @XiyanHou-SDNware on GitHub (Dec 31, 2025). Originally assigned to: @fatelei on GitHub. ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.11.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 1. In the Agent node, set a small value for "Max Iterations" (e.g., 2). 2. Trigger the Chatflow. Once the Agent node reaches the maximum number of iterations, it directly returns the raw tool call tags/markers in the output. <img width="370" height="80" alt="Image" src="https://github.com/user-attachments/assets/924498cf-1f33-4bee-bdfc-f1f120f57249" /> <img width="1121" height="450" alt="Image" src="https://github.com/user-attachments/assets/c0e6441f-db7c-4c35-a1f6-b464d0801a15" /> ### ✔️ Expected Behavior - The SSE response should include a specific event type or an error/exception prompt indicating that the iteration limit has been reached. ### ❌ Actual Behavior - The node directly outputs the raw tool call tags (e.g., <tool_call>) in the final response text. <img width="1121" height="450" alt="Image" src="https://github.com/user-attachments/assets/3fffc0c9-6fb1-4f06-9b49-d01091f4d793" />
yindo added the 🤖 feat:agent label 2026-02-21 20:12:19 -05:00
yindo closed this issue 2026-02-21 20:12:19 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Dec 31, 2025):

Hi @XiyanHou-SDNware! I'm Dosu and I’m helping the dify team.

This is a confirmed bug: when the Agent node hits its Max Iterations limit, it outputs raw tool call tags instead of a proper error or event. The current implementation in Dify does not emit a specific error event when the iteration limit is reached—there’s no logic in the AgentNode or its message transformation pipeline to detect this condition and send a dedicated error message to the SSE stream. Instead, the raw tool call tags are passed through to the frontend, which is why you see them in the response text rather than a clear error or event indicator.

To fix this, the AgentNode (or the agent strategy) should detect when the iteration limit is reached and emit a NodeRunIterationFailedEvent (or similar error event) with a clear message, so the SSE response includes a structured error instead of leaking internal markup. The event class for this already exists and is designed to represent iteration limit failures, but it’s not currently triggered by the agent node logic. This would require a code change to hook the iteration limit enforcement and emit the appropriate event—see the relevant event definition here.

There are no existing workarounds or patches for this issue in the repo or community threads. For now, you can try to adjust your agent prompt to encourage a final answer before the iteration limit is reached, but a proper fix will require backend changes to emit the correct error event when the limit is hit.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Dec 31, 2025): <!-- Greeting --> Hi @XiyanHou-SDNware! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify team. <!-- Answer --> This is a confirmed bug: when the Agent node hits its Max Iterations limit, it outputs raw tool call tags instead of a proper error or event. The current implementation in Dify does not emit a specific error event when the iteration limit is reached—there’s no logic in the AgentNode or its message transformation pipeline to detect this condition and send a dedicated error message to the SSE stream. Instead, the raw tool call tags are passed through to the frontend, which is why you see them in the response text rather than a clear error or event indicator. To fix this, the AgentNode (or the agent strategy) should detect when the iteration limit is reached and emit a NodeRunIterationFailedEvent (or similar error event) with a clear message, so the SSE response includes a structured error instead of leaking internal markup. The event class for this already exists and is designed to represent iteration limit failures, but it’s not currently triggered by the agent node logic. This would require a code change to hook the iteration limit enforcement and emit the appropriate event—see the relevant event definition [here](https://github.com/langgenius/dify/blob/f28a08a69642e43dc556d3c33b3ba75dc9eb528a/api/core/workflow/graph_events/iteration.py#L10-L41). There are no existing workarounds or patches for this issue in the repo or community threads. For now, you can try to adjust your agent prompt to encourage a final answer before the iteration limit is reached, but a proper fix will require backend changes to emit the correct error event when the limit is hit. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/5c198e17-b4d6-4229-8b3d-ea7be4492d26?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/5c198e17-b4d6-4229-8b3d-ea7be4492d26?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/5c198e17-b4d6-4229-8b3d-ea7be4492d26?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/5c198e17-b4d6-4229-8b3d-ea7be4492d26?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/5c198e17-b4d6-4229-8b3d-ea7be4492d26?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/5c198e17-b4d6-4229-8b3d-ea7be4492d26?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/5c198e17-b4d6-4229-8b3d-ea7be4492d26?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20confirmed%20bug%3A%20when%20the%20Agent%20node%20hits%20its%20Max%20Iterations%20limit%2C%20it%20outputs%20raw%20tool%20call%20tags%20instead%20of%20a%20proper%20error%20or%20event.%20The%20current%20implementation%20in%20Dify%20does%20not%20emit%20a%20specific%20error%20event%20when%20the%20iteration%20limit%20is%20reached%E2%80%94there%E2%80%99s%20no%20logic%20in%20the%20AgentNode%20or%20its%20message%20transformation%20pipeline%20to%20detect%20this%20condition%20and%20send%20a%20dedicated%20error%20message%20to%20the%20SSE%20stream.%20Instead%2C%20the%20raw%20tool%20call%20tags%20are%20passed%20through%20to%20the%20frontend%2C%20which%20is%20why%20you%20see%20them%20in%20the%20response%20text%20rather%20than%20a%20clear%20error%20or%20event%20indicator.%0A%0ATo%20fix%20this%2C%20the%20AgentNode%20%28or%20the%20agent%20strategy%29%20should%20detect%20when%20the%20iteration%20limit%20is%20reached%20and%20emit%20a%20NodeRunIterationFailedEvent%20%28or%20similar%20error%20event%29%20with%20a%20clear%20message%2C%20so%20the%20SSE%20response%20includes%20a%20structured%20error%20instead%20of%20leaking%20internal%20markup.%20The%20event%20class%20for%20this%20already%20exists%20and%20is%20designed%20to%20represent%20iteration%20limit%20failures%2C%20but%20it%E2%80%99s%20not%20currently%20triggered%20by%20the%20agent%20node%20logic.%20This%20would%20require%20a%20code%20change%20to%20hook%20the%20iteration%20limit%20enforcement%20and%20emit%20the%20appropriate%20event%E2%80%94see%20the%20relevant%20event%20definition%20%5Bhere%5D%28https%3A//github.com/langgenius/dify/blob/f28a08a69642e43dc556d3c33b3ba75dc9eb528a/api/core/workflow/graph_events/iteration.py%23L10-L41%29.%0A%0AThere%20are%20no%20existing%20workarounds%20or%20patches%20for%20this%20issue%20in%20the%20repo%20or%20community%20threads.%20For%20now%2C%20you%20can%20try%20to%20adjust%20your%20agent%20prompt%20to%20encourage%20a%20final%20answer%20before%20the%20iteration%20limit%20is%20reached%2C%20but%20a%20proper%20fix%20will%20require%20backend%20changes%20to%20emit%20the%20correct%20error%20event%20when%20the%20limit%20is%20hit.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/30419)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#21385