@@ -26,7 +26,8 @@ object rather than a full result:
26
26
27
27
When streaming is enabled the returned ` stream ` implements the
28
28
` 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
30
31
text though, so the stream provides helpers.
31
32
32
33
### Get the text output
@@ -63,6 +64,76 @@ See [the streamed example](https://github.com/openai/openai-agents-js/tree/main/
63
64
for a fully worked script that prints both the plain text stream and the
64
65
raw event stream.
65
66
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
+
66
137
## Human in the loop while streaming
67
138
68
139
Streaming is compatible with handoffs that pause execution (for example
0 commit comments