-
Notifications
You must be signed in to change notification settings - Fork 469
Open
Labels
Milestone
Description
Example code:
import 'dotenv/config';
import { Agent, run } from '@openai/agents';
import fs from 'fs';
async function main() {
const agent = new Agent({
name: 'greeting-agent',
instructions: 'You are a helpful assistant that can greet the user.',
tools: [],
});
const response = await run(
agent,
[
{
role: 'user',
content: 'Hello, how are you?',
},
],
{ stream: true }
);
await response.completed;
fs.writeFileSync(
'response-with-stream.json',
JSON.stringify(response, null, 2)
);
}
main();output:
{
"state": {
"context": {
"usage": {
"requests": 0,
"inputTokens": 0,
"outputTokens": 0,
"totalTokens": 0
},
"approvals": {},
"context": {}
}
},
}If stream option is disabled its ok. but if stream is enabled, it doesnt update the context.