Skip to content

Commit 3c37c5c

Browse files
committed
feat: add thinking message events and types to enhance agent reasoning visibility
1 parent 1fa099d commit 3c37c5c

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

docs/introduction.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ AG-UI provides:
2323
communication
2424
- **Best practices** for chat, streaming state updates, human-in-the-loop and
2525
shared state
26+
- **Thinking transparency** with dedicated thinking message events that expose
27+
agent reasoning processes to users
2628

2729
## Existing Integrations
2830

docs/quickstart/introduction.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Think of it like adding a universal translator to your agent. Instead of buildin
1919

2020
Agents integrating with AG-UI can:
2121
- **Stream responses** - Real-time text that appears as it's generated
22+
- **Show thinking** - Expose internal reasoning through thinking message events
2223
- **Call client-side tools** - Your agent can use functions and services defined by clients
2324
- **Share state** - Your agent's state is bidirectional shared state
2425
- **Execute universally** - Integrate with any AG-UI compatible client application

docs/sdk/python/core/events.mdx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class EventType(str, Enum):
2222
TEXT_MESSAGE_START = "TEXT_MESSAGE_START"
2323
TEXT_MESSAGE_CONTENT = "TEXT_MESSAGE_CONTENT"
2424
TEXT_MESSAGE_END = "TEXT_MESSAGE_END"
25+
THINKING_TEXT_MESSAGE_START = "THINKING_TEXT_MESSAGE_START"
26+
THINKING_TEXT_MESSAGE_CONTENT = "THINKING_TEXT_MESSAGE_CONTENT"
27+
THINKING_TEXT_MESSAGE_END = "THINKING_TEXT_MESSAGE_END"
2528
TOOL_CALL_START = "TOOL_CALL_START"
2629
TOOL_CALL_ARGS = "TOOL_CALL_ARGS"
2730
TOOL_CALL_END = "TOOL_CALL_END"
@@ -210,6 +213,64 @@ class TextMessageEndEvent(BaseEvent):
210213
| ------------ | ----- | ----------------------------------------- |
211214
| `message_id` | `str` | Matches the ID from TextMessageStartEvent |
212215

216+
## Thinking Message Events
217+
218+
These events represent the lifecycle of thinking messages that show an agent's internal reasoning process.
219+
220+
### ThinkingTextMessageStartEvent
221+
222+
`from ag_ui.core import ThinkingTextMessageStartEvent`
223+
224+
Signals the start of a thinking message.
225+
226+
```python
227+
class ThinkingTextMessageStartEvent(BaseEvent):
228+
type: Literal[EventType.THINKING_TEXT_MESSAGE_START]
229+
thinking_id: str
230+
```
231+
232+
| Property | Type | Description |
233+
| ------------- | ----- | ------------------------------------- |
234+
| `thinking_id` | `str` | Unique identifier for the thinking sequence |
235+
236+
### ThinkingTextMessageContentEvent
237+
238+
`from ag_ui.core import ThinkingTextMessageContentEvent`
239+
240+
Represents a chunk of content in a streaming thinking message.
241+
242+
```python
243+
class ThinkingTextMessageContentEvent(BaseEvent):
244+
type: Literal[EventType.THINKING_TEXT_MESSAGE_CONTENT]
245+
thinking_id: str
246+
delta: str # Non-empty string
247+
248+
def model_post_init(self, __context):
249+
if len(self.delta) == 0:
250+
raise ValueError("Delta must not be an empty string")
251+
```
252+
253+
| Property | Type | Description |
254+
| ------------- | ----- | -------------------------------------------------- |
255+
| `thinking_id` | `str` | Matches the ID from ThinkingTextMessageStartEvent |
256+
| `delta` | `str` | Thinking content chunk (non-empty) |
257+
258+
### ThinkingTextMessageEndEvent
259+
260+
`from ag_ui.core import ThinkingTextMessageEndEvent`
261+
262+
Signals the end of a thinking message.
263+
264+
```python
265+
class ThinkingTextMessageEndEvent(BaseEvent):
266+
type: Literal[EventType.THINKING_TEXT_MESSAGE_END]
267+
thinking_id: str
268+
```
269+
270+
| Property | Type | Description |
271+
| ------------- | ----- | -------------------------------------------------- |
272+
| `thinking_id` | `str` | Matches the ID from ThinkingTextMessageStartEvent |
273+
213274
## Tool Call Events
214275

215276
These events represent the lifecycle of tool calls made by agents.
@@ -392,6 +453,9 @@ Event = Annotated[
392453
TextMessageStartEvent,
393454
TextMessageContentEvent,
394455
TextMessageEndEvent,
456+
ThinkingTextMessageStartEvent,
457+
ThinkingTextMessageContentEvent,
458+
ThinkingTextMessageEndEvent,
395459
ToolCallStartEvent,
396460
ToolCallArgsEvent,
397461
ToolCallEndEvent,

docs/sdk/python/core/types.mdx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ messages in the system.
5151
Represents the possible roles a message sender can have.
5252

5353
```python
54-
Role = Literal["developer", "system", "assistant", "user", "tool"]
54+
Role = Literal["developer", "system", "assistant", "user", "tool", "thinking"]
5555
```
5656

5757
### DeveloperMessage
@@ -155,6 +155,26 @@ class ToolMessage(ConfiguredBaseModel):
155155
| `tool_call_id` | `str` | ID of the tool call this message responds to |
156156
| `error` | `Optional[str]` | Error message if the tool call failed |
157157

158+
### ThinkingMessage
159+
160+
`from ag_ui.core import ThinkingMessage`
161+
162+
Represents a thinking message that shows an agent's internal reasoning process.
163+
164+
```python
165+
class ThinkingMessage(BaseMessage):
166+
role: Literal["thinking"]
167+
content: str
168+
```
169+
170+
| Property | Type | Description |
171+
| ----------- | --------------------- | ----------------------------------------------- |
172+
| `id` | `str` | Unique identifier for the message |
173+
| `role` | `Literal["thinking"]` | Role of the message sender, fixed as "thinking" |
174+
| `content` | `str` | Text content of the thinking (required) |
175+
| `name` | `Optional[str]` | Optional name of the sender |
176+
| `timestamp` | `Optional[int]` | Optional timestamp for temporal tracking |
177+
158178
### Message
159179

160180
`from ag_ui.core import Message`
@@ -163,7 +183,7 @@ A union type representing any type of message in the system.
163183

164184
```python
165185
Message = Annotated[
166-
Union[DeveloperMessage, SystemMessage, AssistantMessage, UserMessage, ToolMessage],
186+
Union[DeveloperMessage, SystemMessage, AssistantMessage, UserMessage, ToolMessage, ThinkingMessage],
167187
Field(discriminator="role")
168188
]
169189
```

0 commit comments

Comments
 (0)