agents.structured_output.agentΒΆ
Generalized Structured Output Agent for enhancing any agent with structured output parsing.
ClassesΒΆ
Agent that adds structured output parsing to any other agent. |
Module ContentsΒΆ
- class agents.structured_output.agent.StructuredOutputAgent(/, **data)ΒΆ
Bases:
haive.agents.simple.agent.SimpleAgent
Agent that adds structured output parsing to any other agent.
This agent acts as a post-processor that takes the output from any agent and ensures it conforms to a structured format. It can work standalone or as part of a sequential multi-agent chain.
Key features: - Works with any agent type (SimpleAgent, ReactAgent, etc.) - Preserves original context and input - Uses PydanticToolsParser for robust parsing - Can be chained sequentially with any agent - Supports multiple output models
Example
# Enhance any agent with structured output enhanced_agent = StructuredOutputAgent.enhance_agent( base_agent=my_agent, output_models=[SearchResult, AnalysisResult] ) # Or use as standalone post-processor processor = StructuredOutputAgent.create_processor( output_models=[ResultModel], include_original_input=True )
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- classmethod create_processor(output_models, name='structured_output_processor', include_original_input=True, system_message=None, **kwargs)ΒΆ
Create a standalone structured output processor.
- Parameters:
output_models (list[type[pydantic.BaseModel]]) β List of Pydantic models for output formats
name (str) β Name for the processor
include_original_input (bool) β Include original input for context
system_message (str | None) β Custom system message (auto-generated if not provided)
**kwargs β Additional configuration
- Returns:
Configured StructuredOutputAgent instance
- Return type:
- classmethod create_reflection_processor(reflection_models, name='reflection_processor', **kwargs)ΒΆ
Create a processor specifically for reflection patterns.
This is optimized for reflection/reflexion agents that need to analyze their own outputs and provide structured feedback.
- Parameters:
- Returns:
StructuredOutputAgent configured for reflection
- Return type:
- classmethod create_validation_processor(validation_models, name='validation_processor', **kwargs)ΒΆ
Create a processor for validation patterns.
- Parameters:
- Returns:
StructuredOutputAgent configured for validation
- Return type:
- classmethod enhance_agent(base_agent, output_models, name=None, include_original_input=True, **kwargs)ΒΆ
Enhance any agent with structured output capabilities.
Creates a sequential multi-agent that runs: 1. Base agent (processes input normally) 2. StructuredOutputAgent (ensures output is structured)
- Parameters:
base_agent (haive.agents.base.agent.Agent) β The agent to enhance
output_models (list[type[pydantic.BaseModel]]) β List of Pydantic models for output formats
name (str | None) β Name for the enhanced agent
include_original_input (bool) β Include original input for context
**kwargs β Additional arguments for the structured output agent
- Returns:
ProperMultiAgent configured for sequential execution
- Return type:
haive.agents.multi.experiments.implementations.proper_base.ProperMultiAgent
- process_with_context(content, original_input=None)ΒΆ
Process content with optional original context.
- setup_agent()ΒΆ
Setup hook to configure structured output state.
- Return type:
None