Skip to main content

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:false or zero data retention (ZDR) policies
  • Privacy compliance: Support enterprise privacy requirements while preserving reasoning capabilities
Unlike Activity messages, Reasoning messages are intended to represent the agent’s internal thought process and may be encrypted for privacy and are meant to be sent back to the agent for further processing on subsequent turns.

ReasoningMessage

The ReasoningMessage 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 encryptedValue is 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:
  1. Encrypted reasoning values can carry state across turns without storing decryptable content on the client
  2. The client receives and forwards encryptedValue blobs opaquely via ReasoningEncryptedValue events
  3. 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 ReasoningMessageContent events
  • Summary only: Emit a condensed summary while attaching detailed reasoning as encrypted values
  • Hidden: Use only ReasoningEncryptedValue events 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 the ReasoningEncryptedValue 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

The ReasoningMessageChunk 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

The THINKING_* events are deprecated and will be removed in version 1.0.0. New implementations should use REASONING_* events.

Deprecated Events

The following events are deprecated:

Migration Steps

  1. Update event types: Replace all THINKING_* event types with their REASONING_* equivalents
  2. Update message types: Use ReasoningMessage with role: "reasoning" instead of any thinking-specific message types
  3. Add encrypted value support: Consider using ReasoningEncryptedValue events for improved privacy compliance
  4. Test thoroughly: Ensure existing functionality works with the new event types

Example Migration

Before (deprecated):
After (current):

Best Practices

  1. Always pair start/end events: Every ReasoningStart should have a corresponding ReasoningEnd
  2. Use encrypted values for sensitive reasoning: When chain-of-thought contains sensitive information, use ReasoningEncryptedValue to attach encrypted content to messages or tool calls
  3. Provide user feedback: Even with encrypted reasoning, emit visible summaries so users know the agent is working
  4. Handle missing events gracefully: Clients should be resilient to incomplete event streams
  5. Consider bandwidth: For very long reasoning chains, consider emitting only summaries to reduce data transfer