agents.base.typed_agent¶
Typed agent base classes with clear separation of concerns.
This module provides a cleaner agent hierarchy that matches the state schema hierarchy, with better separation between different types of agents.
Classes¶
Agent that adapts its behavior based on performance. |
|
Base class for agents with primary decision-making engine. |
|
Base class for all executors (not necessarily agents). |
|
Executor for data processing workflows. |
|
Standard LLM-based agent. |
|
Agent that can spawn and manage other agents. |
|
Agent that reacts to specific patterns or triggers. |
|
Executor for tool-based workflows without LLM. |
|
Agent that can modify its own workflow graph. |
Functions¶
|
Factory to create appropriate agent. |
|
Factory to create appropriate executor. |
Module Contents¶
- class agents.base.typed_agent.AdaptiveAgent(name, performance_metrics, adaptation_threshold=0.7, **kwargs)¶
Bases:
WorkflowAgent
Agent that adapts its behavior based on performance.
Tracks its own performance and modifies strategy accordingly.
Init .
- Parameters:
- async adapt_strategy(state)¶
Adapt the agent’s strategy.
- Parameters:
state (haive.core.schema.base_state_schemas.WorkflowState)
- Return type:
None
- calculate_performance(state)¶
Calculate performance metrics.
- async execute(state)¶
Execute with performance tracking.
- Parameters:
state (haive.core.schema.base_state_schemas.WorkflowState)
- Return type:
haive.core.schema.base_state_schemas.WorkflowState
- class agents.base.typed_agent.BaseAgent(name, primary_engine=None, state_schema=AgentState, **kwargs)¶
Bases:
BaseExecutor
[haive.core.schema.base_state_schemas.AgentState
]Base class for agents with primary decision-making engine.
Agents are executors that have a primary engine (usually LLM) for making decisions.
Init .
- Parameters:
- async execute(state)¶
Execute agent logic.
- Parameters:
state (haive.core.schema.base_state_schemas.AgentState)
- Return type:
haive.core.schema.base_state_schemas.AgentState
- abstractmethod run_engine(engine, state)¶
- Async:
- Parameters:
engine (haive.core.engine.base.Engine)
state (haive.core.schema.base_state_schemas.AgentState)
- Return type:
Any
Run the primary engine with state.
- update_state_with_result(state, result)¶
Update state with engine result.
- Parameters:
state (haive.core.schema.base_state_schemas.AgentState)
result (Any)
- Return type:
haive.core.schema.base_state_schemas.AgentState
- class agents.base.typed_agent.BaseExecutor(name, state_schema, **kwargs)¶
Bases:
abc.ABC
,Generic
[TState
]Base class for all executors (not necessarily agents).
Executors are components that process state but don’t necessarily have LLM capabilities. This includes tool executors, data processors, routers, validators, etc.
Init .
- Parameters:
- abstractmethod execute(state)¶
- Async:
- Parameters:
state (TState)
- Return type:
TState
Execute the processing logic.
- class agents.base.typed_agent.DataProcessor(name, required_engines, **kwargs)¶
Bases:
BaseExecutor
[haive.core.schema.base_state_schemas.DataProcessingState
]Executor for data processing workflows.
Processes data through various transformation engines.
Init .
- Parameters:
- async execute(state)¶
Process data through stages.
- Parameters:
state (haive.core.schema.base_state_schemas.DataProcessingState)
- Return type:
haive.core.schema.base_state_schemas.DataProcessingState
- class agents.base.typed_agent.LLMAgent(name, primary_engine=None, state_schema=AgentState, **kwargs)¶
Bases:
BaseAgent
Standard LLM-based agent.
Uses an LLM engine for conversation and decision making.
Init .
- Parameters:
- async run_engine(engine, state)¶
Run LLM engine.
- Parameters:
engine (haive.core.engine.base.Engine)
state (haive.core.schema.base_state_schemas.AgentState)
- Return type:
Any
- update_state_with_result(state, result)¶
Update state with LLM result.
- Parameters:
state (haive.core.schema.base_state_schemas.AgentState)
result (Any)
- Return type:
haive.core.schema.base_state_schemas.AgentState
- class agents.base.typed_agent.MetaAgent(name, primary_engine=None, agent_factory=None, **kwargs)¶
Bases:
WorkflowAgent
Agent that can spawn and manage other agents.
This is for advanced scenarios where agents need to dynamically create and coordinate other agents.
Init .
- Parameters:
- aggregate_results(state)¶
Aggregate sub-agent results.
- Parameters:
state (haive.core.schema.base_state_schemas.MetaAgentState)
- Return type:
None
- async execute(state)¶
Execute meta-agent logic.
- Parameters:
state (haive.core.schema.base_state_schemas.MetaAgentState)
- Return type:
haive.core.schema.base_state_schemas.MetaAgentState
- async execute_sub_agents(state)¶
Execute active sub-agents.
- Parameters:
state (haive.core.schema.base_state_schemas.MetaAgentState)
- Return type:
None
- should_aggregate(state)¶
Determine if results should be aggregated.
- Parameters:
state (haive.core.schema.base_state_schemas.MetaAgentState)
- Return type:
- should_spawn_agents(state)¶
Determine if new agents should be spawned.
- Parameters:
state (haive.core.schema.base_state_schemas.MetaAgentState)
- Return type:
- async spawn_agents(state)¶
Spawn new sub-agents.
- Parameters:
state (haive.core.schema.base_state_schemas.MetaAgentState)
- Return type:
None
- class agents.base.typed_agent.ReactiveAgent(name, triggers, **kwargs)¶
Bases:
LLMAgent
Agent that reacts to specific patterns or triggers.
Useful for monitoring, alerting, or event-driven workflows.
Init .
- Parameters:
- check_triggers(state)¶
Check which triggers are activated.
- evaluate_trigger(trigger, state)¶
Evaluate a single trigger.
- async execute(state)¶
Check triggers before normal execution.
- Parameters:
state (haive.core.schema.base_state_schemas.AgentState)
- Return type:
haive.core.schema.base_state_schemas.AgentState
- class agents.base.typed_agent.ToolExecutor(name, execution_strategy='sequential', **kwargs)¶
Bases:
BaseExecutor
[haive.core.schema.base_state_schemas.ToolExecutorState
]Executor for tool-based workflows without LLM.
Executes tools based on predefined plans or rules.
Init .
- async execute(state)¶
Execute tools according to plan.
- Parameters:
state (haive.core.schema.base_state_schemas.ToolExecutorState)
- Return type:
haive.core.schema.base_state_schemas.ToolExecutorState
- class agents.base.typed_agent.WorkflowAgent(name, primary_engine=None, initial_graph=None, **kwargs)¶
Bases:
BaseAgent
Agent that can modify its own workflow graph.
This agent can inspect results and dynamically modify its execution graph.
Init .
- Parameters:
- async determine_graph_modifications(state)¶
Determine what graph modifications to make.
- async execute(state)¶
Execute with potential graph modification.
- Parameters:
state (haive.core.schema.base_state_schemas.WorkflowState)
- Return type:
haive.core.schema.base_state_schemas.WorkflowState
- agents.base.typed_agent.create_agent(agent_type, name, engine=None, **kwargs)¶
Factory to create appropriate agent.
- agents.base.typed_agent.create_executor(executor_type, name, **kwargs)¶
Factory to create appropriate executor.
- Parameters:
- Returns:
Executor instance
- Return type: