Skip to content

OpenAI Integration

Learn how to integrate OpenAI agents with the Scenario testing framework

OpenAI agents work seamlessly with Scenario through the AgentAdapter[py] interface. Since OpenAI uses the standard message format, integration is straightforward.

Basic Integration Pattern

You can integrate OpenAI directly, as its messages are already in the standard format:

import scenario
import openai
 
class OpenAIAgentAdapter(scenario.AgentAdapter):
    async def call(self, input: scenario.AgentInput) -> scenario.AgentReturnTypes:
        response = openai.chat.completions.create(
            model="gpt-4.1",
            messages=[
                {
                    "role": "system",
                    "content": """
                        You are a helpful AI assistant.
                        Provide clear, concise, and accurate responses to user queries.
                    """,
                },
                *input.messages,
            ],
        )
 
        return response.choices[0].message  # type: ignore

Next Steps