LlmAgent

class LlmAgent(name: String, val model: Model, description: String = "", subAgents: List<BaseAgent> = emptyList(), beforeAgentCallbacks: List<BeforeAgentCallback> = emptyList(), afterAgentCallbacks: List<AfterAgentCallback> = emptyList(), disallowTransferToParent: Boolean = false, 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 outputSchema: Schema? = null, val outputKey: String? = null, val onModelErrorCallbacks: List<OnModelErrorCallback> = emptyList(), val onToolErrorCallbacks: List<OnToolErrorCallback> = emptyList(), val includeContents: LlmAgent.IncludeContents = IncludeContents.DEFAULT, val maxSteps: Int? = null) : 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, outputSchema: Schema? = null, outputKey: String? = null, onModelErrorCallbacks: List<OnModelErrorCallback> = emptyList(), onToolErrorCallbacks: List<OnToolErrorCallback> = emptyList(), includeContents: LlmAgent.IncludeContents = IncludeContents.DEFAULT, maxSteps: Int? = null)

Types

Link copied to clipboard
class Builder

Fluent builder for LlmAgent, provided primarily for Java callers. Any property left unset falls back to the same default as the constructor.

Link copied to clipboard
object Companion
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
open override val config: NodeConfig

The node's retry policy and execution timeout.

Link copied to clipboard
open override val description: String

What the node does, for humans and for a model that may call it.

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
open override val inputSchema: Schema?

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 maximum number of steps this agent runs within a single invocation, where a step is one model call plus any tool calls or transfers it triggers. Once the cap is reached the agent stops emitting further events, even if it has not yet produced a final response. Defaults to null, meaning no cap: the agent keeps stepping until it produces a final response or the invocation otherwise ends (which can run unbounded). Mirrors the Java ADK LlmAgent.maxSteps.

Link copied to clipboard

The model to use for the agent.

Link copied to clipboard
override val name: String

Identifies the node within its graph.

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

The key in session state to store the final text response of the agent. When set, the agent's concatenated text output (excluding parts marked as thoughts) is written to event.actions.stateDelta[outputKey] on each final-response event, which the session service then merges into the session state.

Link copied to clipboard
open override val outputSchema: Schema?

The schema the agent's final response must conform to. Only top-level object schemas are supported (matching the Java ADK; the Python ADK additionally supports list/primitive output schemas). When set, the agent asks the model to return JSON matching this schema and validates the final response against it before saving it to outputKey. If the agent also has tools (including the framework's transfer_to_agent tool when sub-agents/peers are reachable), the schema is applied directly on models that support a response schema together with tools; on models that do not (e.g. Gemini 2.x), the framework falls back to a set_model_response tool to collect the structured output.

Link copied to clipboard
open override val requiresAllPredecessors: Boolean

Whether the node runs only once every predecessor has completed, receiving all their outputs keyed by node name. A fan-in node overrides this to true.

Link copied to clipboard
open override val rerunOnResume: Boolean

On resume, whether to run the node again from scratch rather than completing it with the resuming answer as its output.

Link copied to clipboard
open override val stateSchema: Schema?

Declares the state keys the node uses. Child nodes inherit it unless they declare their own.

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.

Link copied to clipboard
open override val waitForOutput: Boolean

Whether the node stays re-triggerable until it produces an output or a route, instead of completing when runNode returns. A node that never produces either then waits forever, which is a graph-authoring error.

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 run(context: Context, nodeInput: Any?): Flow<Event>

Runs the node and emits its events. It drives runNode and normalizes each raw emission into an Event, so every node behaves the same way at its edges: null and Unit are skipped, an Event passes through with its output validated (a message-as-output event's content is not), and any other value becomes the output.

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

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

Link copied to clipboard
open override fun runNode(context: Context, nodeInput: Any?): Flow<Any?>

Runs this agent as a graph node by driving its runAsync lifecycle, so an agent placed in a workflow graph executes exactly as it would under a runner. Its events are forwarded as the node's output and its author is tracked; the node runner stamps each event's path.