agents.patterns.sequential_with_structured_outputΒΆ
Generic Sequential Agent Pattern with Structured Output Hooks.
This module provides a flexible pattern for creating sequential agent flows where the first agent performs some task and the second agent structures the output into a specific format.
Examples
Common sequential patterns:
ReactAgent β StructuredOutputAgent
ResearchAgent β SummaryAgent
AnalysisAgent β ReportAgent
ClassesΒΆ
Generic sequential agent pattern with structured output. |
|
Hooks for customizing sequential agent behavior. |
FunctionsΒΆ
|
Create an Analysis β Report pipeline. |
|
Create a ReactAgent β StructuredOutput pipeline. |
Module ContentsΒΆ
- class agents.patterns.sequential_with_structured_output.SequentialAgentWithStructuredOutput(first_agent, structured_output_model, structured_output_prompt=None, second_agent=None, hooks=None, name='sequential_structured', debug=False)ΒΆ
Bases:
Generic
[OutputT
]Generic sequential agent pattern with structured output.
This class orchestrates two agents in sequence: 1. First agent performs the main task (e.g., reasoning, research) 2. Second agent structures the output into a specific format
The pattern is flexible and works with any agent types.
Initialize sequential agent with structured output.
- Parameters:
first_agent (haive.agents.base.agent.Agent) β The agent that performs the main task
structured_output_model (type[OutputT]) β Pydantic model for structured output
structured_output_prompt (langchain_core.prompts.ChatPromptTemplate | None) β Optional custom prompt for structuring
second_agent (haive.agents.base.agent.Agent | None) β Optional custom second agent (otherwise creates SimpleAgent)
hooks (SequentialHooks | None) β Optional hooks for customizing behavior
name (str) β Name for this sequential pattern
debug (bool) β Enable debug mode
- async arun(input_data, context=None, **kwargs)ΒΆ
Run the sequential agent pipeline asynchronously.
- class agents.patterns.sequential_with_structured_output.SequentialHooks(/, **data)ΒΆ
Bases:
pydantic.BaseModel
Hooks for customizing sequential agent behavior.
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)
- agents.patterns.sequential_with_structured_output.create_analysis_to_report(analysis_prompt, report_model, name='analysis_report', analysis_config=None, report_prompt=None, hooks=None, debug=False)ΒΆ
Create an Analysis β Report pipeline.
- Parameters:
analysis_prompt (langchain_core.prompts.ChatPromptTemplate) β Prompt for analysis agent
report_model (type[OutputT]) β Model for structured report
name (str) β Name for the pipeline
analysis_config (dict[str, Any] | None) β Optional config for analysis agent
report_prompt (langchain_core.prompts.ChatPromptTemplate | None) β Optional custom report prompt
hooks (SequentialHooks | None) β Optional behavior hooks
debug (bool) β Enable debug mode
- Returns:
Configured sequential agent pipeline
- Return type:
SequentialAgentWithStructuredOutput[OutputT]
- agents.patterns.sequential_with_structured_output.create_react_to_structured(tools, structured_output_model, name='react_structured', react_config=None, structured_prompt=None, hooks=None, debug=False)ΒΆ
Create a ReactAgent β StructuredOutput pipeline.
- Parameters:
tools (list[Any]) β Tools for the ReactAgent
structured_output_model (type[OutputT]) β Output model for structuring
name (str) β Name for the pipeline
react_config (dict[str, Any] | None) β Optional config for ReactAgent
structured_prompt (langchain_core.prompts.ChatPromptTemplate | None) β Optional custom structuring prompt
hooks (SequentialHooks | None) β Optional behavior hooks
debug (bool) β Enable debug mode
- Returns:
Configured sequential agent pipeline
- Return type:
SequentialAgentWithStructuredOutput[OutputT]