# LlmAgent

class LlmAgent(val name: String, val model: Model, val description: String = "", val subAgents: List<BaseAgent> = emptyList(), val beforeAgentCallbacks: List<BeforeAgentCallback> = emptyList(), val afterAgentCallbacks: List<AfterAgentCallback> = emptyList(), val disallowTransferToParent: Boolean = false, val disallowTransferToPeers: Boolean = false, val tools: List<BaseTool> = emptyList(), val toolsets: List<Toolset> = emptyList(), val generateContentConfig: GenerateContentConfig? = null, val instruction: Instruction? = null, val staticInstruction: Content? = null, val beforeModelCallbacks: List<BeforeModelCallback> = emptyList(), val afterModelCallbacks: List<AfterModelCallback> = emptyList(), val beforeToolCallbacks: List<BeforeToolCallback> = emptyList(), val afterToolCallbacks: List<AfterToolCallback> = emptyList(), val inputSchema: Schema? = null, val onModelErrorCallbacks: List<OnModelErrorCallback> = emptyList(), val onToolErrorCallbacks: List<OnToolErrorCallback> = emptyList(), val includeContents: LlmAgent.IncludeContents = IncludeContents.DEFAULT) : BaseAgent

LLM-based Agent.

When this agent is a sub-agent and the parent transfers control to it via `transfer_to_agent`, the runner decides who handles the next user turn based on the disallowTransferToParent / disallowTransferToPeers flags inherited from `BaseAgent` - see those flags for the full dispatch rules.

## Constructors

LlmAgent
Link copied to clipboard
constructor(name: String, model: Model, description: String = "", subAgents: List<BaseAgent> = emptyList(), beforeAgentCallbacks: List<BeforeAgentCallback> = emptyList(), afterAgentCallbacks: List<AfterAgentCallback> = emptyList(), disallowTransferToParent: Boolean = false, disallowTransferToPeers: Boolean = false, tools: List<BaseTool> = emptyList(), toolsets: List<Toolset> = emptyList(), generateContentConfig: GenerateContentConfig? = null, instruction: Instruction? = null, staticInstruction: Content? = null, beforeModelCallbacks: List<BeforeModelCallback> = emptyList(), afterModelCallbacks: List<AfterModelCallback> = emptyList(), beforeToolCallbacks: List<BeforeToolCallback> = emptyList(), afterToolCallbacks: List<AfterToolCallback> = emptyList(), inputSchema: Schema? = null, onModelErrorCallbacks: List<OnModelErrorCallback> = emptyList(), onToolErrorCallbacks: List<OnToolErrorCallback> = emptyList(), includeContents: LlmAgent.IncludeContents = IncludeContents.DEFAULT)

## Types

IncludeContents
Link copied to clipboard
enum IncludeContents : Enum<LlmAgent.IncludeContents>

Controls how prior conversation history is included in this agent's model request.

## Properties

afterAgentCallbacks
Link copied to clipboard
val afterAgentCallbacks: List<AfterAgentCallback>

List of callbacks to run after the agent executes.

afterModelCallbacks
Link copied to clipboard
val afterModelCallbacks: List<AfterModelCallback>

List of callbacks to run after each model call.

afterToolCallbacks
Link copied to clipboard
val afterToolCallbacks: List<AfterToolCallback>

List of callbacks to run after each tool call.

beforeAgentCallbacks
Link copied to clipboard
val beforeAgentCallbacks: List<BeforeAgentCallback>

List of callbacks to run before the agent executes.

beforeModelCallbacks
Link copied to clipboard
val beforeModelCallbacks: List<BeforeModelCallback>

List of callbacks to run before each model call.

beforeToolCallbacks
Link copied to clipboard
val beforeToolCallbacks: List<BeforeToolCallback>

List of callbacks to run before each tool call.

description
Link copied to clipboard
open val description: String

The description of the agent.

disallowTransferToParent
Link copied to clipboard
val disallowTransferToParent: Boolean = false

When `true`, the framework will not route the next user turn back to this agent after the parent transfers control to it; instead the next turn falls back to the root agent. Set this on utility sub-agents the parent calls and returns from (translators, summarizers, classifiers). Leave at the default `false` for sub-agents that should keep handling follow-up turns directly (e.g. billing, support).

disallowTransferToPeers
Link copied to clipboard
val disallowTransferToPeers: Boolean = false

When `true`, prevents this agent from transferring sideways to a peer agent under the same parent. Typically set together with disallowTransferToParent on one-shot utility agents. Violations are surfaced by the runner as `IllegalArgumentException`.

generateContentConfig
Link copied to clipboard
val generateContentConfig: GenerateContentConfig? = null

The additional content generation configurations.

includeContents
Link copied to clipboard
val includeContents: LlmAgent.IncludeContents

Controls how prior conversation history is included in the model request. Defaults to IncludeContents.DEFAULT, which includes the relevant conversation history. Set to IncludeContents.NONE to exclude prior history; the model then receives only the current turn (the most recent user input or other-agent reply, plus any tool calls/responses produced within that turn). The system instruction and tools are preserved in both modes.

inputSchema
Link copied to clipboard
val inputSchema: Schema? = null

The input schema of the agent.

instruction
Link copied to clipboard
val instruction: Instruction? = null

Instruction guiding the agent's behavior. Use one of: - `Instruction("text")` for a literal string (the most common case), - `Instruction(content)` for a pre-built, possibly multimodal Content, or - `Instruction { ctx -> ... }` for a Instruction.Provider resolved per turn.

model
Link copied to clipboard
val model: Model

The model to use for the agent.

name
Link copied to clipboard
val name: String

The name of the agent.

onModelErrorCallbacks
Link copied to clipboard
val onModelErrorCallbacks: List<OnModelErrorCallback>

List of callbacks to run when a model call fails.

onToolErrorCallbacks
Link copied to clipboard
val onToolErrorCallbacks: List<OnToolErrorCallback>

List of callbacks to run when a tool call fails.

staticInstruction
Link copied to clipboard
val staticInstruction: Content? = null

Static instruction content sent literally as system instruction at the beginning. This field is for content that never changes. It's sent directly to the model without any processing or variable substitution.

subAgents
Link copied to clipboard
val subAgents: List<BaseAgent>

List of sub-agents.

tools
Link copied to clipboard
val tools: List<BaseTool>

Tools available to this agent.

toolsets
Link copied to clipboard
val toolsets: List<Toolset>

Toolsets available to this agent.

## Functions

findAgent
Link copied to clipboard
fun BaseAgent.findAgent(targetName: String): BaseAgent?

Finds an agent with the given name in this agent's subtree (including itself).

runAsync
Link copied to clipboard
fun runAsync(parentContext: InvocationContext): Flow<Event>

Public entry point for executing the agent asynchronously (text-based).