Skip to content

Commit 366327c

Browse files
committed
update activity proposal
1 parent 073d2df commit 366327c

File tree

1 file changed

+69
-38
lines changed

1 file changed

+69
-38
lines changed

docs/drafts/activity-events.mdx

Lines changed: 69 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,26 @@ this example UI:
6161

6262
### Overview
6363

64-
This proposal introduces two new concepts to the AG-UI protocol:
64+
This proposal introduces new concepts to the AG-UI protocol:
6565

66-
1. **ActivityEvent**: A new event type in the event stream
66+
1. **ActivitySnapshotEvent** and **ActivityDeltaEvent**: Two new event types following the established state management pattern
6767
2. **ActivityMessage**: A new message type alongside TextMessage, ToolMessage,
6868
etc.
6969

7070
Frameworks may emit ActivityEvents, and frontends can render them inline with
7171
chat.
7272

73-
### New Event: ActivityEvent
73+
### New Events: ActivitySnapshotEvent and ActivityDeltaEvent
74+
75+
Following the established pattern in AG-UI (similar to `StateSnapshotEvent` and `StateDeltaEvent`), activities are represented using two complementary events:
76+
77+
#### ActivitySnapshotEvent
78+
79+
Provides the complete activity state at a point in time.
7480

7581
```typescript
76-
type ActivityEvent = BaseEvent & {
77-
type: EventType.ACTIVITY
82+
type ActivitySnapshotEvent = BaseEvent & {
83+
type: EventType.ACTIVITY_SNAPSHOT
7884
/**
7985
* Unique identifier for the ActivityMessage this event belongs to.
8086
*/
@@ -84,14 +90,32 @@ type ActivityEvent = BaseEvent & {
8490
*/
8591
activityType: string
8692
/**
87-
* Snapshot of the full activity state (optional).
93+
* Complete activity state at this point in time.
94+
*/
95+
content: Record<string, any>
96+
}
97+
```
98+
99+
#### ActivityDeltaEvent
100+
101+
Provides incremental updates to the activity state.
102+
103+
```typescript
104+
type ActivityDeltaEvent = BaseEvent & {
105+
type: EventType.ACTIVITY_DELTA
106+
/**
107+
* Unique identifier for the ActivityMessage this event belongs to.
108+
*/
109+
messageId: string
110+
/**
111+
* Activity type, e.g. "PLAN", "SEARCH", "SCRAPE"
88112
*/
89-
snapshot?: Record<string, any>
113+
activityType: string
90114
/**
91-
* Patch to apply to the prior snapshot (optional).
92-
* Follows JSON Patch semantics.
115+
* JSON Patch operations to apply to the current activity state.
116+
* Follows RFC 6902 semantics.
93117
*/
94-
patch?: Record<string, any>
118+
patch: JSONPatchOperation[]
95119
}
96120
```
97121
@@ -103,10 +127,10 @@ Initial activity snapshot:
103127
{
104128
"id": "evt_001",
105129
"ts": 1714064100000,
106-
"type": "ACTIVITY",
130+
"type": "ACTIVITY_SNAPSHOT",
107131
"messageId": "msg_789",
108132
"activityType": "PLAN",
109-
"snapshot": {
133+
"content": {
110134
"tasks": ["check reddit", "search X.com"]
111135
}
112136
}
@@ -118,14 +142,16 @@ Incremental update via patch:
118142
{
119143
"id": "evt_002",
120144
"ts": 1714064120000,
121-
"type": "ACTIVITY",
145+
"type": "ACTIVITY_DELTA",
122146
"messageId": "msg_789",
123147
"activityType": "PLAN",
124-
"patch": {
125-
"op": "replace",
126-
"path": "/tasks/0",
127-
"value": "✓ check reddit"
128-
}
148+
"patch": [
149+
{
150+
"op": "replace",
151+
"path": "/tasks/0",
152+
"value": "✓ check reddit"
153+
}
154+
]
129155
}
130156
```
131157
@@ -157,35 +183,37 @@ type ActivityMessage = {
157183
158184
TypeScript SDK additions:
159185
160-
- New `ActivityEvent` type in `@ag-ui/core`
186+
- New `ActivitySnapshotEvent` and `ActivityDeltaEvent` types in `@ag-ui/core`
161187
- New `ActivityMessage` type in message unions
162188
- Activity renderer registry in `@ag-ui/client`
189+
- JSON Patch utilities for activity updates
163190
164191
Python SDK additions:
165192
166-
- New `ActivityEvent` class in `ag_ui.core.events`
193+
- New `ActivitySnapshotEvent` and `ActivityDeltaEvent` classes in `ag_ui.core.events`
167194
- New `ActivityMessage` class in message types
168195
- Activity serialization/deserialization support
196+
- JSON Patch utilities for activity updates
169197
170198
### Integration Impact
171199
172-
- **Planning Frameworks**: Can emit ActivityEvents during planning or tool
200+
- **Planning Frameworks**: Can emit ActivitySnapshotEvent/ActivityDeltaEvent during planning or tool
173201
execution phases
174202
- **Workflow Systems**: Can surface step-by-step workflow progress as
175-
ActivityEvents
176-
- **Other frameworks**: May emit ActivityEvents freely; AG-UI will serialize
203+
ActivitySnapshotEvent/ActivityDeltaEvent
204+
- **Other frameworks**: May emit ActivitySnapshotEvent/ActivityDeltaEvent freely; AG-UI will serialize
177205
them like other events
178206
179207
## Examples and Use Cases
180208
181209
### Example 1: Web Search Activity
182210
183211
```typescript
184-
// Agent emits search activity
185-
agent.emitActivity({
212+
// Agent emits initial search activity snapshot
213+
agent.emitActivitySnapshot({
186214
messageId: "msg_123",
187215
activityType: "SEARCH",
188-
snapshot: {
216+
content: {
189217
sources: [
190218
{ name: "Reddit", status: "pending" },
191219
{ name: "X.com", status: "pending" },
@@ -195,34 +223,37 @@ agent.emitActivity({
195223
})
196224

197225
// Update as search progresses
198-
agent.emitActivity({
226+
agent.emitActivityDelta({
199227
messageId: "msg_123",
200228
activityType: "SEARCH",
201-
patch: {
202-
op: "replace",
203-
path: "/sources/0/status",
204-
value: "complete",
205-
},
229+
patch: [
230+
{
231+
op: "replace",
232+
path: "/sources/0/status",
233+
value: "complete",
234+
}
235+
],
206236
})
207237
```
208238

209239
### Use Case: Multi-Step Workflow Visibility
210240

211241
A data analysis agent performing multiple steps:
212242

213-
1. Loading dataset → ActivityEvent shows progress bar
214-
2. Cleaning data → ActivityEvent shows rows processed
215-
3. Running analysis → ActivityEvent shows current computation
216-
4. Generating report → ActivityEvent shows sections completed
243+
1. Loading dataset → ActivitySnapshotEvent/ActivityDeltaEvent shows progress bar
244+
2. Cleaning data → ActivitySnapshotEvent/ActivityDeltaEvent shows rows processed
245+
3. Running analysis → ActivitySnapshotEvent/ActivityDeltaEvent shows current computation
246+
4. Generating report → ActivitySnapshotEvent/ActivityDeltaEvent shows sections completed
217247

218248
Each step appears inline with chat, giving users real-time feedback.
219249

220250
## Testing Strategy
221251

222-
- Unit tests for ActivityEvent serialization/deserialization
223-
- Integration tests with mock frameworks emitting ActivityEvents
252+
- Unit tests for ActivitySnapshotEvent/ActivityDeltaEvent serialization/deserialization
253+
- Integration tests with mock frameworks emitting ActivitySnapshotEvent/ActivityDeltaEvent
224254
- E2E tests in AG-UI Dojo demonstrating activity rendering
225255
- Performance benchmarks for high-frequency activity updates
256+
- JSON Patch application correctness tests
226257

227258
## References
228259

0 commit comments

Comments
 (0)