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

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

Link copied to clipboard

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

Properties

Link copied to clipboard

List of callbacks to run after the agent executes.

Link copied to clipboard

List of callbacks to run after each model call.

Link copied to clipboard

List of callbacks to run after each tool call.

Link copied to clipboard

List of callbacks to run before the agent executes.

Link copied to clipboard

List of callbacks to run before each model call.

Link copied to clipboard

List of callbacks to run before each tool call.

Link copied to clipboard

The description of the agent.

Link copied to clipboard

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

Link copied to clipboard

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.

Link copied to clipboard

The additional content generation configurations.

Link copied to clipboard

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.

Link copied to clipboard
val inputSchema: Schema? = null

The input schema of the agent.

Link copied to clipboard

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.

Link copied to clipboard

The model to use for the agent.

Link copied to clipboard

The name of the agent.

Link copied to clipboard

List of callbacks to run when a model call fails.

Link copied to clipboard

List of callbacks to run when a tool call fails.

Link copied to clipboard

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.

Link copied to clipboard

List of sub-agents.

Link copied to clipboard

Tools available to this agent.

Link copied to clipboard

Toolsets available to this agent.

Functions

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

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

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

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