# `ADK.Agent.LlmAgent`
[🔗](https://github.com/zeroasterisk/adk-elixir/blob/main/lib/adk/agent/llm_agent.ex#L1)

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

# `t`

```elixir
@type t() :: %ADK.Agent.LlmAgent{
  _peer_agents: term(),
  after_tool_callback: (map(), map(), map(), any() -&gt; any()) | nil,
  before_tool_callback:
    (map(), map(), map() -&gt; {: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() -&gt; 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() -&gt;
       {: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()]
}
```

# `build_request`

```elixir
@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`

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

Clone an agent with optional overrides.

# `compile_instruction`

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

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

# `effective_tools`

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

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

# `get_agent_to_run`

```elixir
@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`

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

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

# `new`

```elixir
@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`

```elixir
@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).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
