haive.core.engine.agent.config¶
Agent configuration for the Haive framework with protocol support.
This module provides the AgentConfig base class for configuring agent components with protocol-based validation and type checking to ensure that agent implementations conform to the expected interfaces.
TODO: Consisnteny in naming of persistence configs. TODO: Need to seperate and implement the registry system, similar to retrievers and add base. TODO: Need to clean up patterns and registry system.
Classes¶
Base configuration for an agent architecture. |
|
Configuration for a pattern to be applied to an agent. |
Module Contents¶
- class haive.core.engine.agent.config.AgentConfig[source]¶
Bases:
haive.core.engine.base.InvokableEngine
[TIn
,TOut
],Generic
[TIn
,TOut
,TState
]Base configuration for an agent architecture. Extends InvokableEngine to provide a consistent interface with the Engine framework.
This class is designed to NEVER include __runnable_config__ in any schemas. By default, it uses PostgreSQL for persistence if available.
This implementation supports protocol validation to ensure that agent implementations conform to the expected interfaces.
- add_node_config(name, engine, **kwargs)[source]¶
Add a node configuration to this agent with schema integration.
- Parameters:
name (str) – Name of the node
engine (Union[haive.core.engine.base.Engine, str, haive.core.graph.node.config.NodeConfig]) – Engine, engine name, or NodeConfig
**kwargs – Additional parameters for NodeConfig
- Returns:
Self for method chaining
- Return type:
- add_subagent(name, agent_config)[source]¶
Add a subagent for recursive composition with proper schema integration.
- Parameters:
name (str) – Name of the subagent
agent_config (AgentConfig) – Configuration for the subagent
- Returns:
Self for method chaining
- Return type:
- async ainvoke(input_data, runnable_config=None)[source]¶
Asynchronously invoke the agent with input data.
- Parameters:
input_data (TIn) – Input data for the agent
runnable_config (langchain_core.runnables.RunnableConfig | None) – Optional runtime configuration
- Returns:
Output from the agent
- Return type:
TOut
- apply_runnable_config(runnable_config=None)[source]¶
Extract parameters from runnable_config relevant to this agent.
- build_agent()[source]¶
Build an agent instance from this configuration with protocol validation.
- Return type:
- classmethod clear_schema_caches()[source]¶
Clear all schema caches completely for this class and its subclasses.
This ensures both class-level and instance-level caches are reset.
- Return type:
None
- create_runnable(runnable_config=None)[source]¶
Create a runnable instance from this agent config.
- Parameters:
runnable_config (langchain_core.runnables.RunnableConfig | None) – Optional runtime configuration
- Returns:
Built and compiled agent application
- Return type:
Any
- derive_input_schema()[source]¶
Derive input schema for this agent.
- Returns:
Input schema as BaseModel subclass
- Return type:
type[pydantic.BaseModel]
- derive_output_schema()[source]¶
Derive output schema for this agent.
- Returns:
Output schema as BaseModel subclass
- Return type:
type[pydantic.BaseModel]
- derive_schema()[source]¶
Derive state schema from components and engines using SchemaComposer.
- Returns:
A state schema class (with no __runnable_config__ field)
- Return type:
type[pydantic.BaseModel]
- disable_pattern(pattern_name)[source]¶
Disable a pattern.
- Parameters:
pattern_name (str) – Name of the pattern to disable
- Returns:
Self for method chaining
- Return type:
- enable_pattern(pattern_name)[source]¶
Enable a pattern.
- Parameters:
pattern_name (str) – Name of the pattern to enable
- Returns:
Self for method chaining
- Return type:
- classmethod from_dict(data)[source]¶
Create an agent config from a dictionary.
- classmethod from_json(json_str)[source]¶
Create an agent config from a JSON string.
- Parameters:
json_str (str) – JSON representation of the agent config
- Returns:
Agent config instance
- Return type:
- get_input_fields()[source]¶
Return input field definitions as field_name -> (type, default) pairs.
Implements the abstract method from Engine base class.
- get_output_fields()[source]¶
Return output field definitions as field_name -> (type, default) pairs.
Implements the abstract method from Engine base class.
- get_schema_manager(schema_instance=None)[source]¶
Get a StateSchemaManager for the agent’s schema.
- Parameters:
schema_instance – Optional specific schema to use (defaults to state_schema)
- Returns:
StateSchemaManager instance for schema manipulation
- Return type:
Any | None
- invoke(input_data, runnable_config=None)[source]¶
Invoke the agent with input data.
- Parameters:
input_data (TIn) – Input data for the agent
runnable_config (langchain_core.runnables.RunnableConfig | None) – Optional runtime configuration
- Returns:
Output from the agent
- Return type:
TOut
- mark_pattern_applied(pattern_name)[source]¶
Mark a pattern as applied.
- Parameters:
pattern_name (str) – Name of the pattern to mark
- Return type:
None
- classmethod register_agent_class(agent_class)[source]¶
Register an agent class for this configuration.
This method checks protocol compliance before registration.
- Parameters:
agent_class (type[haive.core.engine.agent.agent.Agent]) – Agent class to register
- Raises:
TypeError – If the agent class doesn’t implement required protocols
- Return type:
None
- resolve_engine(engine_ref=None)[source]¶
Resolve an engine reference to an actual engine.
- Parameters:
engine_ref (Any) – Engine reference (name or object) or None to use default engine
- Returns:
Resolved Engine object
- Return type:
haive.core.engine.base.Engine
- set_pattern_parameters(pattern_name, **parameters)[source]¶
Set global parameters for a pattern.
- Parameters:
pattern_name (str) – Name of the pattern
**parameters – Parameter values
- Returns:
Self for method chaining
- Return type:
- set_testing_mode(enabled=True)[source]¶
Enable or disable testing mode to bypass caching behavior.
- Parameters:
enabled (bool) – Whether testing mode should be enabled
- Returns:
Self for method chaining
- to_json()[source]¶
Convert agent config to JSON string.
- Returns:
JSON representation of the agent config
- Return type:
- use_pattern(pattern_name, parameters=None, order=None, condition=None, enabled=True)[source]¶
Add a pattern to be applied to this agent.
- Parameters:
pattern_name (str) – Name of the pattern in the registry
parameters (dict[str, Any] | None) – Parameters for pattern application
order (int | None) – Application order (lower numbers first)
condition (str | None) – Optional condition for pattern application
enabled (bool) – Whether this pattern is enabled
- Returns:
Self for method chaining
- Return type:
- class haive.core.engine.agent.config.PatternConfig(/, **data)[source]¶
Bases:
pydantic.BaseModel
Configuration for a pattern to be applied to an agent.
This allows detailed configuration of pattern application, including parameters, application order, and conditions.
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)
- merge_with(other)[source]¶
Merge this pattern configuration with another.
- Parameters:
other (PatternConfig) – The other pattern config to merge with
- Returns:
New merged pattern config
- Return type:
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].