agents.chain.chain_agent_simple

ChainAgent - The simplest way to build agent chains.

Just list your nodes and define the flow. That’s it.

Classes

ChainAgent

The simplest way to build chains - just list nodes and edges.

FlowBuilder

Builder for method chaining.

Functions

flow(*nodes, **kwargs)

Create a flow chain - the simplest way.

flow_with_edges(nodes, *edges)

Create a flow with custom edges.

Module Contents

class agents.chain.chain_agent_simple.ChainAgent(*nodes, **kwargs)

Bases: haive.agents.base.agent.Agent

The simplest way to build chains - just list nodes and edges.

Initialize with nodes directly.

Examples

ChainAgent(node1, node2, node3) # Auto-sequential ChainAgent(node1, node2, edges=[“0->1”])

Parameters:

nodes (NodeLike)

add(node)

Add a node and auto-link from previous.

Parameters:

node (NodeLike)

Return type:

ChainAgent

branch(condition, **branches)

Add conditional branching.

Parameters:
Return type:

ChainAgent

build_graph()

Build the graph from nodes and edges.

Return type:

haive.core.graph.state_graph.base_graph2.BaseGraph

merge_to(target_idx)

Merge the last node to a target node.

Parameters:

target_idx (int)

Return type:

ChainAgent

class agents.chain.chain_agent_simple.FlowBuilder(initial=None)

Builder for method chaining.

Init .

Parameters:

initial (NodeLike | None) – [TODO: Add description]

add(node)

Add a node.

Parameters:

node (NodeLike)

Return type:

FlowBuilder

branch(condition, **branches)

Add branching.

Parameters:
Return type:

FlowBuilder

build()

Get the chain.

Return type:

ChainAgent

merge_to(target_idx)

Merge to a previous node.

Parameters:

target_idx (int)

Return type:

FlowBuilder

agents.chain.chain_agent_simple.flow(*nodes, **kwargs)

Create a flow chain - the simplest way.

Examples

# Sequential chain = flow(node1, node2, node3)

# With edges chain = flow(node1, node2, node3, edges=[“0->2”]) # Skip node2

# With name chain = flow(node1, node2, name=”My Flow”)

Parameters:

nodes (NodeLike)

Return type:

ChainAgent

agents.chain.chain_agent_simple.flow_with_edges(nodes, *edges)

Create a flow with custom edges.

Examples

chain = flow_with_edges(

[classifier, simple, complex, output], (0, {“simple”: 1, “complex”: 2}, lambda s: s.type), “1->3”, “2->3”

)

Parameters:
  • nodes (list[NodeLike])

  • edges (EdgeLike)

Return type:

ChainAgent