Overview
AgentInput is the input object your agent receives when using the Structured signature ((input_data: AgentInput) -> AgentResponse). It provides the conversation history, session context, and helper methods for accessing user messages.
When a test case has structured JSON input (e.g. {"user_message": "hello", "chat_type": "support"}), the SDK splits it: user_message becomes the message content, and the remaining fields (like chat_type) are placed in the first user message’s metadata.
Fields
list[ConversationMessage]
required
The full conversation history up to this turn. Each
ConversationMessage has:role(str):"user"or"assistant"content(str): The message textretrieval_context(Optional[str]): Retrieved context (for RAG agents)metadata(Optional[dict[str, Any]]): Additional fields. When the test case uses structured JSON input, non-message fields (e.g.chat_type,priority) appear here on the first user message.
str
required
The current session identifier. Use this to maintain state in stateful agents.
Optional[dict[str, Any]]
Structured context data from the test case. This comes from the test case’s
context / context_data field, not from the input. Use it to pass supplemental information like customer tier, environment, or domain context.Optional[dict[str, Any]]
Additional metadata for the current execution.
Optional[str]
The inference result ID for this execution. Forward this to remote agents so they can attach traces to the correct session via
set_context(inference_result_id=...). See Remote Agent Tracing.Helper Methods
Optional[str]
Returns the
content of the last user message, or None if no user message exists. This is the simplest way to get the user’s message text.Optional[ConversationMessage]
Returns the full
ConversationMessage object for the last user message (with role, content, retrieval_context, and metadata), or None if not found. Use this when you need access to the message’s metadata.Basic Usage
Accessing Structured Input Fields
When your test case input is a JSON object (e.g. uploaded via CSV with{"user_message": "hello", "chat_type": "support"} in the input column), the SDK places user_message as the message content and remaining fields in messages[0].metadata:
Accessing Context Data
context_data is separate from the input. It comes from the test case’s context field and is useful for passing supplemental information that is not part of the user message:
Structured Input on TestCase and InferenceResult
Outside ofAgentInput, the TestCase and InferenceResult models provide two fields for accessing input:
.input(str): Theuser_messagevalue as a plain string.input_data(dict): The full structured input object with all fields
InferenceResult also provides a symmetric pair for the agent output:
.actual_output(str | None): The scored output as a plain string. For voice turns this is theassistant_messagetranscript unwrapped from the content-parts envelope..actual_output_data(dict | None): The full output envelope when present (e.g.{"assistant_message": "...", "content": [{"type": "audio", "uri": "...", "transcript": "..."}]}), otherwiseNonefor plain-text output.
When submitting an
actualOutput content-parts envelope, each audio part must include either a non-empty transcript or a non-empty uri. If you provide only a uri, the API transcribes the stored audio automatically and fills in the transcript. A client-supplied transcript or assistant_message always takes precedence over the API’s speech-to-text result. The strict transcript requirement applies only to the user turn (input) — the agent output side accepts audio-only parts.How Structured Input Flows Through the System
- Test case CSV: You provide JSON in the
inputcolumn:{"user_message": "hello", "chat_type": "support"} - TestCase model:
.input="hello",.input_data={"user_message": "hello", "chat_type": "support"} - Endpoint templates: Use
{{ input.user_message }}or{{ input.chat_type }}to access individual fields, or{{ input }}for the full message - AgentInput (SDK):
messages[0].content="hello",messages[0].metadata={"chat_type": "support"} - InferenceResult:
.input="hello",.input_data={"user_message": "hello", "chat_type": "support"}
Related
Simulating Conversations
Multi-turn conversation simulation tutorial.
Generate Inference Result
Single-turn agent execution with automatic trace collection.
Templates & Mapping
Endpoint template syntax including
{{ input.field_name }}.Tracing Agent Operations
Capture internal operations and forward inference_result_id to remote agents.