OpenAI Integration
Learn how to integrate OpenAI agents with the Scenario testing framework
OpenAI agents work seamlessly with Scenario through the AgentAdapter
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-mini",
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
- Explore Scenario Basics for advanced testing patterns
- Learn about Scripted Simulations for precise control
- Check out more Agent Integration patterns for other frameworks