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

View Source

Summary

Types

t()

Common state for AI agents that work with code. Includes an internal map that can be used to store additional state that is specific to the implementation.

Functions

Returns a string that describes the values and principles that guide the code agent's design and implementation decisions. This is used to inform the AI agent's behavior and responses, ensuring that it adheres to a consistent set of coding standards and practices.

Executes a completion request using the AI model specified in the state. The prompt is appended to the existing messages in the state as a system message. Unless keep_prompt? is true, the system prompt will be removed from the messages after the completion is received to keep the cascade of instructions clean.

Retrieves a value from the internal state of the AI agent. key may be either a single atom or a list of atoms representing a path to a value in the internal map (per get_in/2 semantics).

Creates a new state for an AI agent that works with code. The initial message list includes the system prompt and the user prompt, as provided.

Sets the internal, implementation-specific state for the AI agent. key may be either a single atom or a list of atoms representing a path to a value in the internal map (per put_in/3 semantics).

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()
}

Common state for AI agents that work with code. Includes an internal map that can be used to store additional state that is specific to the implementation.

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()

Returns a string that describes the values and principles that guide the code agent's design and implementation decisions. This is used to inform the AI agent's behavior and responses, ensuring that it adheres to a consistent set of coding standards and practices.

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(
  state :: t(),
  prompt :: binary(),
  response_format :: map() | nil,
  keep_prompt? :: boolean()
) :: t()

Executes a completion request using the AI model specified in the state. The prompt is appended to the existing messages in the state as a system message. Unless keep_prompt? is true, the system prompt will be removed from the messages after the completion is received to keep the cascade of instructions clean.

get_state(state, key)

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

Retrieves a value from the internal state of the AI agent. key may be either a single atom or a list of atoms representing a path to a value in the internal map (per get_in/2 semantics).

When passing a list of keys, all keys must exist within the nested structure. {:error, :not_found} will be returned if any key is missing.

Examples:

# Get a single value
{:ok, value} = AI.Agent.Code.Common.get_state(state, :blarg)

# Get a nested value
{:ok, value} = AI.Agent.Code.Common.get_state(state, [:blarg, :foo])

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

@spec new(
  agent :: AI.Agent.t(),
  model :: AI.Model.t(),
  toolbox :: AI.Tools.toolbox(),
  system_prompt :: binary(),
  user_prompt :: binary()
) :: t()

Creates a new state for an AI agent that works with code. The initial message list includes the system prompt and the user prompt, as provided.

put_state(state, key, value)

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

Sets the internal, implementation-specific state for the AI agent. key may be either a single atom or a list of atoms representing a path to a value in the internal map (per put_in/3 semantics).

When passing a list of keys, all keys must exist within the nested structure. An exception will be thrown (by put_in/3) if any key is missing.

Examples:

# Set a single value
state = AI.Agent.Code.Common.put_state(state, :blarg, "how now brown beaurocrat")

# Set a nested value
state = AI.Agent.Code.Common.put_state(state, [:blarg, :foo], "bar")

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

@spec report_task_outcome(
  state :: t(),
  task :: task(),
  error :: binary(),
  outcome :: binary(),
  follow_up_tasks :: [new_task()]
) :: :ok

report_task_stack(state)

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