Skip to content

Commit 2911733

Browse files
authored
docs: inline streaming event types in guide (follows #205) (#229)
1 parent bd463ef commit 2911733

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

docs/src/content/docs/guides/streaming.mdx

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ object rather than a full result:
2626

2727
When streaming is enabled the returned `stream` implements the
2828
`AsyncIterable` interface. Each yielded event is an object describing
29-
what happened within the run. Most applications only want the model's
29+
what happened within the run. The stream yields one of three event types, each describing a different part of the agent's execution.
30+
Most applications only want the model's
3031
text though, so the stream provides helpers.
3132

3233
### Get the text output
@@ -63,6 +64,76 @@ See [the streamed example](https://github.com/openai/openai-agents-js/tree/main/
6364
for a fully worked script that prints both the plain text stream and the
6465
raw event stream.
6566

67+
## Event types
68+
69+
The stream yields three different event types:
70+
71+
### raw_model_stream_event
72+
73+
```ts
74+
type RunRawModelStreamEvent = {
75+
type: 'raw_model_stream_event';
76+
data: ResponseStreamEvent;
77+
};
78+
```
79+
80+
Example:
81+
82+
```json
83+
{
84+
"type": "raw_model_stream_event",
85+
"data": {
86+
"type": "output_text_delta",
87+
"delta": "Hello"
88+
}
89+
}
90+
```
91+
92+
### run_item_stream_event
93+
94+
```ts
95+
type RunItemStreamEvent = {
96+
type: 'run_item_stream_event';
97+
name: RunItemStreamEventName;
98+
item: RunItem;
99+
};
100+
```
101+
102+
Example handoff payload:
103+
104+
```json
105+
{
106+
"type": "run_item_stream_event",
107+
"name": "handoff_occurred",
108+
"item": {
109+
"type": "handoff_call",
110+
"id": "h1",
111+
"status": "completed",
112+
"name": "transfer_to_refund_agent"
113+
}
114+
}
115+
```
116+
117+
### agent_updated_stream_event
118+
119+
```ts
120+
type RunAgentUpdatedStreamEvent = {
121+
type: 'agent_updated_stream_event';
122+
agent: Agent<any, any>;
123+
};
124+
```
125+
126+
Example:
127+
128+
```json
129+
{
130+
"type": "agent_updated_stream_event",
131+
"agent": {
132+
"name": "Refund Agent"
133+
}
134+
}
135+
```
136+
66137
## Human in the loop while streaming
67138

68139
Streaming is compatible with handoffs that pause execution (for example

0 commit comments

Comments
 (0)