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

AgentConfig

Base configuration for an agent architecture.

PatternConfig

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:
Returns:

Self for method chaining

Return type:

AgentConfig

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:

AgentConfig

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.

Parameters:

runnable_config (langchain_core.runnables.RunnableConfig | None) – Runtime configuration to extract from

Returns:

Dictionary of relevant parameters

Return type:

dict[str, Any]

build_agent()[source]

Build an agent instance from this configuration with protocol validation.

Return type:

haive.core.engine.agent.agent.Agent

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:

AgentConfig

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:

AgentConfig

ensure_engine()[source]

Ensure at least one engine is available.

Return type:

Self

ensure_state_schema()[source]

Ensure state schema is derived if not provided.

Return type:

Self

extract_params()[source]

Extract parameters from this engine for serialization.

Returns:

Dictionary of engine parameters

Return type:

dict[str, Any]

classmethod from_dict(data)[source]

Create an agent config from a dictionary.

Parameters:

data (dict[str, Any]) – Dictionary representation of the agent config

Returns:

Agent config instance

Return type:

AgentConfig

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:

AgentConfig

get_input_fields()[source]

Return input field definitions as field_name -> (type, default) pairs.

Implements the abstract method from Engine base class.

Returns:

Dictionary mapping field names to (type, default) tuples

Return type:

dict[str, tuple[type, Any]]

get_output_fields()[source]

Return output field definitions as field_name -> (type, default) pairs.

Implements the abstract method from Engine base class.

Returns:

Dictionary mapping field names to (type, default) tuples

Return type:

dict[str, tuple[type, Any]]

get_pattern_order()[source]

Get ordered list of patterns to apply.

Returns:

List of pattern names in application order

Return type:

list[str]

get_pattern_parameters(pattern_name)[source]

Get combined parameters for a pattern.

Parameters:

pattern_name (str) – Name of the pattern

Returns:

Combined parameters from pattern config and global parameters

Return type:

dict[str, Any]

get_schema_fields()[source]

Get schema fields for this agent.

Returns:

Dictionary mapping field names to (type, default) tuples Never includes __runnable_config__

Return type:

dict[str, tuple[type, Any]]

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

is_pattern_applied(pattern_name)[source]

Check if a pattern has been applied.

Parameters:

pattern_name (str) – Name of the pattern to check

Returns:

True if the pattern has been applied

Return type:

bool

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:

AgentConfig

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_dict()[source]

Convert agent config to a dictionary.

Returns:

Dictionary representation of the agent config

Return type:

dict[str, Any]

to_json()[source]

Convert agent config to JSON string.

Returns:

JSON representation of the agent config

Return type:

str

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:

AgentConfig

with_config_overrides(overrides)[source]

Create a new agent config with configuration overrides.

Parameters:

overrides (dict[str, Any]) – Configuration overrides to apply

Returns:

New agent config instance with overrides applied

Return type:

AgentConfig

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:

PatternConfig

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].