[Bug] Agent V2 node in Chatflow/Workflow: SSE stream only emits node_started/message/node_finished, missing intermediate execution events (tool calls, reasoning steps)
- Dominant language
- TypeScript
- Stars
- 156k
- Forks
- 24.6k
- Avg merge
- 22h 9m
- Merged PRs (30d)
- 610
Description
## Self Checks
- [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 (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)).
- [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
- [x] Please do not modify this template :) and fill in all the required fields.
## Dify version
1.17.1
## Cloud or Self Hosted
Self Hosted (Docker)
## Steps to reproduce
1. Create a **Chatflow** (or Workflow) application.
2. Add an **Agent V2** node to the flow and configure it with a model that supports function calling and at least one tool.
3. Trigger the application via the REST API with streaming enabled:
```
POST /v1/chat-messages
{
"query": "What's the weather in Beijing?",
"response_mode": "streaming",
"conversation_id": "",
"user": "test-user"
}
```
4. Observe the SSE event stream returned by the API.
5. Inspect the events emitted for the Agent V2 node. You will only see:
- `node_started` — the agent node begins execution
- `message` — the final text response from the agent node
- `node_finished` — the agent node completes
**No intermediate events are emitted.** There are no events for:
- Which tool(s) the agent decided to call
- Tool call parameters / arguments
- Tool response / observation data
- Intermediate reasoning steps (agent thoughts between tool calls)
- Per-iteration token usage or latency
By contrast, the legacy Agent node in Chatflow/Workflow emits `agent_thought` events (via `AgentLogEvent`) that include `tool`, `tool_input`, `observation`, and `thought` fields, allowing API consumers to trace the full agent execution process.
The standalone Agent V2 app (non-chatflow) also surfaces agent trace data in its log UI (though with its own gaps, see #40761 and #42265), but when Agent V2 is used as a **node inside a Chatflow/Workflow**, the SSE stream provides zero visibility into the intermediate execution.
## ✔️ Expected Behavior
When an Agent V2 node is used in a Chatflow/Workflow and the application is called via `POST /v1/chat-messages` with `response_mode: "streaming"`, the SSE stream should include intermediate execution events for the agent node, such as:
- `agent_thought` events (or equivalent) showing:
- Tool name being invoked
- Tool input parameters
- Tool output / observation
- The agent's reasoning text between tool calls
- Per-iteration metadata (token usage, latency, timestamps)
This is critical for API consumers who need to:
- Display real-time agent progress to end users (e.g., "Calling tool: weather_api...", "Tool returned: 25°C")
- Debug unexpected agent behavior (which tool was called, what it returned, where reasoning went wrong)
- Monitor and log agent execution traces for production observability
The legacy Agent node in Chatflow/Workflow already provides this via `agent_thought` events. Agent V2 should achieve feature parity.
## ❌ Actual Behavior
The SSE stream for the Agent V2 node only contains three event types:
1. `node_started` — contains basic node metadata (node ID, title, type)
2. `message` — contains only the final text output
3. `node_finished` — contains node-level metadata (elapsed time, total tokens, execution state)
**No intermediate execution events are emitted.** The entire agent execution process — tool selection, tool calls, tool responses, reasoning steps — is invisible in the SSE stream. API consumers receive a "black box" where the input goes in and the final answer comes out, with no visibility into what happened in between.
## Additional context
- **Related issues:**
- #41269 — Restore Agent V2 support in Chatflow (Agent V2 was hidden from Chatflow in 1.16.1 via PR #39439; this suggests Agent V2 in Chatflow is still a work in progress)
- #42265 — Feature request: Agent V2 execution log viewing (covers the standalone Agent V2 app; this issue is specifically about the SSE event stream when Agent V2 is used as a node in Chatflow/Workflow)
- #40761 — Broken log icon in Agent V2 log UI
- #39546 — Ordering issue between node-start persistence and Agent V2 node execution (may be related to why intermediate events are not emitted)
- #20952 — Legacy issue about agent streaming in workflow (closed; was about final response streaming, not intermediate events)
- #20485 — Agent node in Chatflow shows 0 token usage and empty process data in tracing view
- **Backend data exists:** PR #38592 added per-call tool thought recording on the backend. The data is recorded but not emitted as SSE events for Agent V2 nodes in Chatflow/Workflow.
- **Legacy Agent parity:** The legacy Agent node in Chatflow/Workflow emits `AgentLogEvent` with `agent_thought` data (tool, tool_input, observation, thought). Agent V2 should provide equivalent intermediate events in the SSE stream.
Contributor guide
Research direction
Start at the POST /v1/chat-messages streaming entry point and trace how an Agent V2 node emits events in Chatflow/Workflow. Compare that path with the legacy AgentLogEvent behavior and the backend recording described in PR #38592; done means the SSE stream exposes tool calls, inputs, observations, reasoning, and per-iteration metadata for Agent V2 nodes.
Written by the indexing model from the issue text.
Assessment
- Domain
- ai, api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100