LlmCore.Agent.Context (llm_core v0.3.0)

Copy Markdown View Source

Carries data through the agentic iteration pipeline.

One Context is created per LLM response and flows through all stages of the LlmCore.Agent.Pipeline.Iteration pipeline. The outer loop (LlmCore.Agent.Loop) creates this from the LLM response, sends it through the pipeline, and reads the decision field to determine the next action.

Fields

Input — set by the outer loop before pipeline entry

  • messages — Current message list (grows each iteration)
  • tools — Available tool definitions ([LlmToolkit.Tool.t()])
  • response — The LLM response for this iteration
  • resolve_toolfn(%Call{}) -> {:ok, String.t()} | {:error, String.t()}

  • resolver_module — Optional module implementing ToolResolver behaviour. When set, DispatchTools checks for dispatch recipes via resolver_module.dispatch_recipe/1.
  • iteration — Current iteration count (0-based)
  • max_iterations — Hard iteration limit

Intermediate — populated by pipeline stages

  • tool_calls — Parsed tool call requests from the response
  • tool_results — Results after tool execution
  • result_messages — Formatted messages for the next LLM turn
  • validation_errors — Errors from call validation

Output — read by the outer loop after pipeline exit

  • decision{:continue, messages}, {:done, response}, or {:error, reason}
  • status:ok or :error (short-circuit flag for stages)
  • error — Error detail when status == :error
  • trace — Accumulated trace entries for observability

Summary

Types

decision()

@type decision() ::
  {:continue, [map()]}
  | {:done, LlmCore.LLM.Response.t()}
  | {:error, term()}
  | nil

t()

@type t() :: %LlmCore.Agent.Context{
  decision: decision(),
  error: term() | nil,
  iteration: non_neg_integer(),
  max_iterations: pos_integer(),
  messages: [map()],
  resolve_tool:
    (LlmToolkit.Tool.Call.t() -> {:ok, String.t()} | {:error, String.t()}) | nil,
  resolver_module: module() | nil,
  response: LlmCore.LLM.Response.t() | nil,
  result_messages: [map()],
  status: :ok | :error,
  tool_calls: [LlmToolkit.Tool.Call.t()],
  tool_results: [LlmToolkit.Tool.Result.t()],
  tools: [LlmToolkit.Tool.t()],
  trace: [term()],
  validation_errors: [term()]
}