Reasoning
AG-UI provides first-class support for LLM reasoning, enabling chain-of-thought visibility while maintaining privacy and state continuity across conversation turns.Overview
Modern LLMs increasingly use chain-of-thought reasoning to improve response quality. AG-UI’s reasoning support addresses three key challenges:- Reasoning visibility: Surface reasoning signals (e.g., summaries) to users without exposing raw chain-of-thought
- State continuity: Maintain reasoning context across turns using encrypted
reasoning items, even under
store:falseor zero data retention (ZDR) policies - Privacy compliance: Support enterprise privacy requirements while preserving reasoning capabilities
ReasoningMessage
TheReasoningMessage type represents reasoning content in the message history:
Key characteristics:
- Separate from assistant messages: Reasoning is kept distinct from final responses to avoid polluting conversation history
- Streamable: Content arrives via streaming events
- Optional encryption: When
encryptedValueis present, it represents encrypted chain-of-thought that the client stores and forwards opaquely
Reasoning Events
Reasoning events manage the lifecycle of reasoning messages. See Events for the complete event reference.Event Flow
A typical reasoning flow follows this pattern:Event Types
Privacy and Compliance
AG-UI reasoning is designed with privacy-first principles:Zero Data Retention (ZDR)
For deployments requiring zero data retention:- Encrypted reasoning values can carry state across turns without storing decryptable content on the client
- The client receives and forwards
encryptedValueblobs opaquely viaReasoningEncryptedValueevents - Only the agent (or authorized backend) can decrypt the reasoning content
Visibility Control
Agents control what reasoning is visible to users:- Full visibility: Stream the complete chain-of-thought via
ReasoningMessageContentevents - Summary only: Emit a condensed summary while attaching detailed reasoning as encrypted values
- Hidden: Use only
ReasoningEncryptedValueevents with no visible streaming
Compliance Considerations
Example Implementations
Basic Reasoning Flow
A simple implementation showing visible reasoning:Encrypted Content for State Continuity
When maintaining reasoning state across turns without exposing content, use theReasoningEncryptedValue event to attach encrypted chain-of-thought to messages
or tool calls:
Attaching Encrypted Reasoning to Tool Calls
You can also attach encrypted reasoning to tool calls to capture why the agent chose specific arguments or how it interpreted results:ZDR-Compliant Implementation
For zero data retention scenarios:Using the Convenience Chunk Event
TheReasoningMessageChunk event simplifies implementation by auto-managing
message lifecycle:
Client Integration
Handling Reasoning Events
Passing Encrypted Reasoning Back
When making subsequent requests, include stored encrypted values:Migration from Thinking Events
Deprecated Events
The following events are deprecated:Migration Steps
- Update event types: Replace all
THINKING_*event types with theirREASONING_*equivalents - Update message types: Use
ReasoningMessagewithrole: "reasoning"instead of any thinking-specific message types - Add encrypted value support: Consider using
ReasoningEncryptedValueevents for improved privacy compliance - Test thoroughly: Ensure existing functionality works with the new event types
Example Migration
Before (deprecated):Best Practices
- Always pair start/end events: Every
ReasoningStartshould have a correspondingReasoningEnd - Use encrypted values for sensitive reasoning: When chain-of-thought
contains sensitive information, use
ReasoningEncryptedValueto attach encrypted content to messages or tool calls - Provide user feedback: Even with encrypted reasoning, emit visible summaries so users know the agent is working
- Handle missing events gracefully: Clients should be resilient to incomplete event streams
- Consider bandwidth: For very long reasoning chains, consider emitting only summaries to reduce data transfer
Related Documentation
- Events - Complete event type reference
- Messages - Message type documentation
- Serialization - State continuity and lineage