Response Types
Response types define structured output formats for agents. They can be defined directly in YAML or imported from Python code.
Type Safety
While YAML configuration is convenient, defining response types as Pydantic models in Python code provides better type safety, IDE support, and reusability:
Response Configuration¶
Each response definition includes:
responses:
MyResponse:
response_schema: # Schema definition (required)
type: "inline" # or "import"
fields:
answer:
type: str
description: "Optional description of the response"
result_tool_name: "final_result" # Tool name for result creation
result_tool_description: "Create the final result" # Tool description
output_retries: 3 # Number of validation retries
Inline Responses¶
Define response structure directly in YAML:
# yaml-language-server: $schema=https://raw.githubusercontent.com/phil65/agentpool/refs/heads/main/schema/config-schema.json
responses:
WebResult:
response_schema:
type: inline
fields:
success:
type: bool
description: "Whether operation succeeded"
url:
type: str
description: "URL that was processed"
attempts:
type: int
description: "Number of attempts made"
constraints:
ge: 1
le: 5
CodeAnalysis:
response_schema:
type: "inline"
description: "Code analysis results with issues"
fields:
issues:
type: "list[str]"
description: "List of found issues"
severity:
type: "str"
description: "Overall severity level"
result_tool_name: "create_analysis"
result_tool_description: "Create code analysis result"
### Complex Response
DataProcessingResult:
response_schema:
type: "inline"
description: "Complex data processing result"
fields:
records_processed:
type: "int"
description: "Number of processed records"
errors:
type: "list[str]"
description: "List of errors if any"
metrics:
type: "dict[str, float]"
description: "Processing metrics"
Imported Responses¶
Import response types from Python code:
Python Type Import¶
responses:
AdvancedAnalysis:
response_schema:
type: "import"
import_path: "myapp.types:AnalysisResult"
MetricsResult:
response_schema:
type: "import"
import_path: "myapp.analysis:MetricsResponse"
Using Response Types¶
Assign to Agent¶
Inline Definition¶
An agent can also define its response inline, with the same fields as an entry of
responses (a response_schema without type is an inline schema):
agents:
classifier:
model: "openai:gpt-5-mini"
output_type:
response_schema:
fields:
label:
type: str
description: "Assigned category"
confidence:
type: float
result_tool_name: "submit_label"
Available Field Types¶
str: Text stringsint: Integer numbersfloat: Floating point numbersbool: Boolean valueslist[type]: Lists of values (e.g.,list[str],list[int])dict[key_type, value_type]: Dictionariesdatetime: Date and time values- Custom types through imports
Configuration Reference¶
StructuredResponseConfig¶
Base class for response definitions.
Docs: https://phil65.github.io/agentpool/configuration/responses/
InlineSchemaDef¶
Inline definition of schema.
Allows defining response types directly in the configuration using: - Field definitions with types and descriptions - Optional validation constraints - Custom field descriptions - Field dependencies and relationships
Example: type: inline fields: success: {type: bool, description: "Operation success"} message: {type: str, description: "Result details"} payment_method: {type: str, description: "Payment method used"} card_number: { type: str, description: "Credit card number", dependent_required: { "payment_method": ["card_expiry", "card_cvc"] } }
ImportedSchemaDef¶
Response definition that imports an existing Pydantic model.
Allows using externally defined Pydantic models as response types. Benefits: - Reuse existing model definitions - Full Python type support - Complex validation logic - IDE support for imported types
Example: responses: AnalysisResult: type: import import_path: myapp.models.AnalysisResult