Agent Node in Chat Flow Shows 0 Token Usage in Tracing View
Self Checks
- [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
- [x] I have searched for existing issues search for existing issues, including closed ones.
- [x] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
- [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
- [x] Please do not modify this template :) and fill in all the required fields.
Dify version
1.3.1
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
In the Chatflow/Workflow editor, add an Agent Node and set the Agentic Strategy to Function Calling. Add a tool and provide the necessary instructions to the node. Then initiate a conversation that triggers this agent. After the conversation is processed, go to Conversation Log > Tracing, and inspect the agent node's details. You will notice that the token usage fields — such as total_tokens, answer_tokens, and message_tokens — are all zero, even though a valid response is generated.
agent node
llm node
I have another question: How do you handle memory messages in the agent node? I could see them in Conversation Log > Tracing > Process Data for the LLM node, but in the agent node, these parameters are empty, too.
✔️ Expected Behavior
The Agent Node should report accurate token usage statistics: total_tokens, answer_tokens, and message_tokens, similar to the LLM Node.
❌ Actual Behavior
The agent node shows zero values for all token metrics in the tracing view, despite generating a response. Additionally, memory messages are not visible in the agent node’s process data.
Your observation is correct: in Dify 1.3.1, the Agent Node in Chat Flow may show zero values for token usage metrics (total_tokens, answer_tokens, message_tokens) in the tracing view, even when a valid response is generated. This is due to how token usage is calculated and reported for agent nodes, especially when using the Function Calling strategy.
Why Token Usage Shows as Zero
Token usage metrics are tracked using the LLMUsage object, which is updated during each agent iteration and saved via the save_agent_thought method. However, for the Agent Node, the reporting of these metrics in the tracing view depends on the correct propagation of usage data through the workflow's metadata and event system. If the agent runner (such as FunctionCallAgentRunner) or the plugin strategy does not properly attach the usage data to the node's execution metadata, the tracing UI will display zeros—even though the underlying LLM calls are consuming tokens and the data is being tracked internally. This is a known architectural pattern in Dify, where the reporting is standardized but relies on correct downstream propagation of execution metadata fields, including token counts. If any step in this chain is missing or misconfigured, the UI will show zero usage [source].
Memory Messages in Agent Node
Memory messages in Dify are managed using the TokenBufferMemory class, which extracts and prunes conversation history to fit token constraints. For the Agent Node, memory is injected into prompt construction via the AgentChatAppRunner and transformed by classes like AgentHistoryPromptTransform. If the memory configuration is missing, disabled, or not properly passed through the agent's configuration or plugin YAML, the process data for the Agent Node will not show memory messages—even though the LLM node may display them correctly [source].
To ensure memory is available in the Agent Node, check that:
- The memory feature is enabled in your agent plugin's YAML configuration (add the
history-messagesfeature). - The memory toggle is enabled in the UI for the Agent Node.
- The window size is set appropriately to retain enough conversation history [source].
Troubleshooting & Recommendations
- If you are using a custom or third-party agent strategy, ensure it correctly propagates token usage and memory data in its outputs.
- Review your plugin's YAML configuration to confirm that memory features are enabled.
- If you are on 1.3.1, consider checking for updates or reviewing recent pull requests, as some memory and tracing improvements have been made in later versions.
References:
- FunctionCallAgentRunner and token usage handling
- Agent Node memory integration
- Enabling memory in Agent Node (GitHub Issue)
If you need more specific guidance on configuration or want to verify if your setup is affected by a known bug, please share your agent plugin YAML or relevant configuration details.
To reply, just mention my name @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other