Jido.Runner.Chain (Jido v1.1.0-rc.2)

View Source

A runner that executes instructions sequentially with support for result chaining.

Chain Execution

Instructions are executed in sequence with the output of each instruction becoming the input for the next instruction in the chain via the merge_results option.

Features

  • Sequential instruction execution
  • Result chaining between instructions
  • Directive accumulation
  • Comprehensive error handling

Summary

Functions

Executes a chain of instructions sequentially, with optional result merging.

Types

chain_opts()

@type chain_opts() :: [
  merge_results: boolean(),
  apply_directives?: boolean(),
  log_level: atom()
]

chain_result()

@type chain_result() ::
  {:ok, Jido.Agent.t(), [Jido.Agent.Directive.t()]} | {:error, Jido.Error.t()}

Functions

dbug(_, _ \\ [])

(macro)

error(_, _ \\ [])

(macro)

run(agent, opts \\ [])

@spec run(Jido.Agent.t(), chain_opts()) :: chain_result()

Executes a chain of instructions sequentially, with optional result merging.

Parameters

  • agent - The agent struct containing:
    • pending_instructions - Queue of pending instructions
    • state - Current agent state
    • id - Agent identifier
  • opts - Optional keyword list of execution options:
    • :merge_results - When true, merges each result into the next instruction's params (default: true)
    • :apply_directives? - When true (default), applies directives during execution

Returns

  • {:ok, updated_agent, directives} - Chain completed successfully with:
    • Final result stored in agent.result
    • List of accumulated directives
  • {:error, error} - Chain execution failed with error details

Examples

# Basic chain execution
{:ok, updated_agent, directives} = Chain.run(agent)

# Chain with result merging disabled
{:ok, updated_agent, directives} = Chain.run(agent, merge_results: false)

# Chain without applying directives
{:ok, updated_agent, directives} = Chain.run(agent, apply_directives?: false)