ADK.Agent.LlmAgent (ADK v0.0.1)

Copy Markdown View Source

An LLM-powered agent that calls a language model to generate responses, handles tool calls, and loops until a final text response is produced.

This is the primary agent type in ADK Elixir.

Options

  • :max_history_turns - Maximum number of conversation turns (user + model pairs) to keep from session history. When set to a positive integer, only the most recent N turns are included in the prompt. Defaults to nil (unlimited).

Summary

Functions

Build the LLM request map from the current context and agent configuration.

Clone an agent with optional overrides.

Compile the instruction string, merging global + agent instruction and substituting {key} state variables.

Compute the full tool list including auto-generated transfer tools.

Find an agent by name in the tree, or raise with a helpful error.

Get all agent names in the agent tree for error reporting.

Create a new LLM agent.

Compute the list of agents this agent can transfer to.

Types

t()

@type t() :: %ADK.Agent.LlmAgent{
  _peer_agents: term(),
  after_tool_callback: (map(), map(), map(), any() -> any()) | nil,
  before_tool_callback:
    (map(), map(), map() -> {:cont, map()} | {:halt, any()}) | nil,
  context_compressor: keyword() | nil,
  description: String.t(),
  disallow_transfer_to_parent: boolean(),
  disallow_transfer_to_peers: boolean(),
  generate_config: map(),
  global_instruction: String.t() | nil,
  instruction: String.t() | (map() -> String.t()),
  iteration_delay_ms: non_neg_integer(),
  max_history_turns: pos_integer() | nil,
  max_iterations: pos_integer(),
  model: String.t(),
  name: String.t(),
  on_tool_error_callback:
    (map(), map(), map(), term() ->
       {:retry, any()} | {:fallback, any()} | {:error, any()})
    | nil,
  output_key: atom() | String.t() | nil,
  output_schema: map() | nil,
  parent_agent: t() | nil,
  planner: struct() | nil,
  sub_agents: [map()],
  tool_config: map() | nil,
  tools: [map()]
}

Functions

build_request(ctx, agent)

@spec build_request(ADK.Context.t(), t()) :: map()

Build the LLM request map from the current context and agent configuration.

Assembles everything the LLM provider needs for a generation call:

  • :model — the model identifier from the agent config
  • :instruction — compiled system instruction (may include dynamic parts)
  • :messages — conversation history from the context
  • :tools — tool declarations for all effective tools
  • :agent_name — the agent's name (used for multi-agent routing)
  • :generate_config — generation parameters (temperature, etc.) when set
  • :tool_config — tool-calling mode/constraints when set
  • :live_connect_config — real-time/streaming options from RunConfig (audio transcription, affective dialog, proactivity, session resumption, realtime input config, context window compression)

Planner configuration (e.g. ADK.Planner.BuiltIn) is applied last, which may add thinking/reasoning parameters to the request.

The returned map is passed directly to the LLM provider module (e.g. ADK.LLM.Gemini, ADK.LLM.OpenAI, ADK.LLM.Anthropic).

clone(agent, overrides \\ %{})

@spec clone(t(), map()) :: t()

Clone an agent with optional overrides.

compile_instruction(ctx, agent)

@spec compile_instruction(ADK.Context.t(), t()) :: String.t()

Compile the instruction string, merging global + agent instruction and substituting {key} state variables.

effective_tools(agent)

@spec effective_tools(t()) :: [map()]

Compute the full tool list including auto-generated transfer tools.

get_agent_to_run(root_agent, agent_name)

@spec get_agent_to_run(t(), String.t()) :: {:ok, t()}

Find an agent by name in the tree, or raise with a helpful error.

get_available_agent_names(root_agent)

@spec get_available_agent_names(t()) :: [String.t()]

Get all agent names in the agent tree for error reporting.

new(opts)

@spec new(keyword()) :: t()

Create a new LLM agent.

Applies any skills from the :skills option, builds the struct, and wires parent/peer references for sub-agent transfer.

transfer_targets(agent)

@spec transfer_targets(t()) :: [t()]

Compute the list of agents this agent can transfer to.

Includes sub-agents, parent (if not disallowed), and peer siblings (if not disallowed).