@langwatch/scenario
    Preparing search index...

    Class RealtimeAgentAdapter

    Adapter that connects Scenario testing framework to OpenAI Realtime API

    This adapter wraps a RealtimeSession to provide the Scenario framework interface. The session is created by your own session creator, so the same creation pattern runs in both browser and tests. connect() mints the session credential at OPENAI_BASE_URL, which is how a run through a LangWatch AI Gateway gets metered.

    // In beforeAll
    const session = createVegetarianRecipeSession();
    const adapter = new RealtimeAgentAdapter({
    session,
    role: AgentRole.AGENT
    });
    await adapter.connect();

    // In test
    await scenario.run({
    agents: [adapter, scenario.userSimulatorAgent()],
    script: [scenario.user("quick recipe"), scenario.agent()]
    });

    // In afterAll
    session.close();

    Hierarchy (View Summary)

    Index
    name: string

    The name that LangWatch shows as the target of the run. When you do not set it, the framework uses the class name of the adapter.

    role: AgentRole
    • Open the session, minting its credential the way every other realtime adapter does.

      The media websocket runs to OpenAI either way. What changes is the bearer it opens with: POST ${OPENAI_BASE_URL}/realtime/client_secrets is OpenAI's own mint path and a LangWatch AI Gateway mirrors it, so pointing OPENAI_BASE_URL at a gateway makes the same request check the virtual key's budget and session cap and open one spend record. The socket then carries the ephemeral secret the mint returned, which the @openai/agents websocket transport was built to take.

      An explicit params.apiKey skips the mint: the caller has already said which credential to dial with.

      Parameters

      • Optionalparams: RealtimeSessionConnectOptions

      Returns Promise<void>