Returns
It returns a result object from the Conversation Simulator containing the complete conversation history, status, and metadata. This is used to analyze how your agent performed in the test scenario.Agent Options
- Simple
- Chat History
- Structured
The quickest way to get started. Your function receives just the latest user message as a string.
All three signatures work with
evaluations.run(), traces.generate(), and simulator.simulate(). Both sync and async functions are supported. The SDK auto-detects which signature you’re using from the type hint on the first parameter.Only the Structured signature receives the files a test case attaches, as input_data.input_files. The other two receive the text alone and fail the trace for a file-only test case. See Reading attached files.Only the Structured signature can answer with files, through AgentResponse.output_file_paths. A response carrying files but no text is a real answer, not an empty one. simulator.simulate() is the exception: it raises a ValueError on a response carrying files, because a simulated conversation carries none yet. See Output Files.For the full list of fields available on AgentInput (including structured input access via message metadata), see the AgentInput reference.AgentInput Fields
With the Structured signature ((input_data: AgentInput) -> AgentResponse), your function receives an AgentInput. That page lists every field and helper method, including input_files for reading attached files.
Example
Parameters
str
required
The session identifier for this simulation.
AgentType
required
The agent function that generates responses. Supported signatures:
- Simple:
(user_message: str) -> str— receives last user message - Chat History:
(messages: list[dict]) -> str— receives full chat history (OpenAI format) - Structured:
(input_data: AgentInput) -> AgentResponse— structured input/output
usage_info, cost_info, or retrieval_context. Only the structured signature receives the files a test case attaches; the other two fail the trace for a file-only test case.int
Number of conversation turns this simulation may add. Defaults to the Test Case’s max turns if not provided. When the test case starts from a predefined conversation, the copied turns do not count against it: 4 predefined turns with
max_turns=1 call your agent once.bool
bool
Whether to call your agent one final time after the simulated user sends their last message. Default: True.
When enabled, your agent will have the opportunity to respond to the conversation’s final user message, ensuring complete dialogue coverage for evaluation purposes.
bool
Whether to include metadata in the simulation result. Default: False
bool
If True, the agent will generate the first message before any user messages are generated. Default: False
When
agent_goes_first is set to True:- Any
input(first user message) defined on the associatedTestCasewill be ignored. - The first call to your agent will have an empty
messageslist in theAgentInput. Ensure your agent function can handle cases whereinput_data.last_user_message_str()returnsNone(or the messages list is empty). - The opening turn is recorded as pending and only your agent’s reply completes it. If the run stops during that first call, the turn stays pending, and the session’s evaluations are skipped until something completes it.
- It cannot be combined with a test case that starts from a predefined conversation. The opening turn is recorded before the predefined conversation can be placed in front of it, so the simulation is refused.
bool
If True, the simulation will stop when the agent returns an empty (
"" / None) response. Default: TrueWhen
stop_when_agent_returns_empty_response is set to False:- The simulation will continue even if the agent returns a response that is empty (
"") orNone. - This allows for more flexible conversation flows where you want to capture all agent interactions regardless of content.
- Be careful when using this option, as it may lead to further credit consumption if the agent keeps returning empty responses. To mitigate this, you can also make use of the
max_turnsparameter to set an upper limit on the number of turns.