AI.Agent.Code.Common (fnord v0.9.17)

View Source

State management for code-oriented agents (planner, implementor, validator). Provides multi-turn conversation primitives and task management helpers.

This module manages its own struct and completion loop independently of AI.Agent.Composite. The code agents use this directly rather than implementing the Composite behaviour.

Summary

Functions

Executes a completion request. The prompt is appended as a system message, then removed after the completion (unless keep_prompt? is true). The assistant's response is always appended to the message history.

Creates a new state for a code agent. The initial message list contains the system prompt and the user prompt.

Types

new_task()

@type new_task() :: %{label: binary(), detail: binary()}

t()

@type t() :: %AI.Agent.Code.Common{
  agent: AI.Agent.t(),
  error: any(),
  internal: map(),
  messages: AI.Util.msg_list(),
  model: AI.Model.t(),
  request: binary(),
  response: binary() | nil,
  toolbox: AI.Tools.toolbox()
}

task()

@type task() :: Services.Task.task()

Functions

add_task(list_id, map)

@spec add_task(Services.Task.list_id(), new_task()) :: any()

add_tasks(list_id, new_tasks)

@spec add_tasks(Services.Task.list_id(), [new_task()]) :: :ok

coder_values_prompt()

@spec coder_values_prompt() :: binary()

format_new_tasks(new_tasks)

@spec format_new_tasks([new_task()]) :: binary()

get_completion(state, prompt, response_format \\ nil, keep_prompt? \\ false)

@spec get_completion(t(), binary(), map() | nil, boolean()) :: t()

Executes a completion request. The prompt is appended as a system message, then removed after the completion (unless keep_prompt? is true). The assistant's response is always appended to the message history.

get_state(state, key)

@spec get_state(t(), atom() | list()) :: {:ok, any()} | {:error, :not_found}

new(agent, model, toolbox, system_prompt, user_prompt)

@spec new(AI.Agent.t(), AI.Model.t(), AI.Tools.toolbox(), binary(), binary()) :: t()

Creates a new state for a code agent. The initial message list contains the system prompt and the user prompt.

put_state(state, key, value)

@spec put_state(t(), atom() | list(), any()) :: t()

report_task_outcome(state, task, error, outcome, follow_up_tasks)

@spec report_task_outcome(t(), task(), binary(), binary(), [new_task()]) :: :ok

report_task_stack(state)

@spec report_task_stack(state :: t()) :: any()