Skip to content

Usage in context is not being updated with stream #638

@yusuf-eren

Description

@yusuf-eren

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions