# Class LlmAgent

java.lang.Object
com.google.adk.agents.BaseAgent
com.google.adk.agents.LlmAgent

public class LlmAgent extends BaseAgent
The LLM-based agent.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `LlmAgent.Builder`
  Builder for `LlmAgent`.
  `static enum`
  `LlmAgent.IncludeContents`
  Enum to define if contents of previous events should be included in requests to the underlying LLM.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `LlmAgent(LlmAgent.Builder builder)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `List<? extends Callbacks.AfterModelCallback>`
  `afterModelCallback()`
  `List<? extends Callbacks.AfterToolCallback>`
  `afterToolCallback()`
  `List<? extends Callbacks.BeforeModelCallback>`
  `beforeModelCallback()`
  `List<? extends Callbacks.BeforeToolCallback>`
  `beforeToolCallback()`
  `static LlmAgent.Builder`
  `builder()`
  Returns a `LlmAgent.Builder` for `LlmAgent`.
  `List<? extends Callbacks.AfterModelCallback>`
  `canonicalAfterModelCallbacks()`
  The resolved afterModelCallback field as a list.
  `List<? extends Callbacks.AfterToolCallback>`
  `canonicalAfterToolCallbacks()`
  The resolved afterToolCallback field as a list.
  `List<? extends Callbacks.BeforeModelCallback>`
  `canonicalBeforeModelCallbacks()`
  The resolved beforeModelCallback field as a list.
  `List<? extends Callbacks.BeforeToolCallback>`
  `canonicalBeforeToolCallbacks()`
  The resolved beforeToolCallback field as a list.
  `io.reactivex.rxjava3.core.Single<Map.Entry<String,Boolean>>`
  `canonicalGlobalInstruction(ReadonlyContext context)`
  Constructs the text global instruction for this agent based on the `globalInstruction` field.
  `io.reactivex.rxjava3.core.Single<Map.Entry<String,Boolean>>`
  `canonicalInstruction(ReadonlyContext context)`
  Constructs the text instruction for this agent based on the `instruction` field.
  `List<? extends Callbacks.OnModelErrorCallback>`
  `canonicalOnModelErrorCallbacks()`
  The resolved onModelErrorCallback field as a list.
  `List<? extends Callbacks.OnToolErrorCallback>`
  `canonicalOnToolErrorCallbacks()`
  The resolved onToolErrorCallback field as a list.
  `io.reactivex.rxjava3.core.Flowable<BaseTool>`
  `canonicalTools()`
  Constructs the list of tools for this agent based on the `tools()` field.
  `io.reactivex.rxjava3.core.Flowable<BaseTool>`
  `canonicalTools(@Nullable ReadonlyContext context)`
  Constructs the list of tools for this agent based on the `tools()` field.
  `io.reactivex.rxjava3.core.Completable`
  `close()`
  Closes all sub-agents.
  `Optional<BaseCodeExecutor>`
  `codeExecutor()`
  `protected BaseLlmFlow`
  `determineLlmFlow()`
  `boolean`
  `disallowTransferToParent()`
  `boolean`
  `disallowTransferToPeers()`
  `Optional<Executor>`
  `executor()`
  `static LlmAgent`
  `fromConfig(LlmAgentConfig config, String configAbsPath)`
  Creates an LlmAgent from configuration with full subagent support.
  `Optional<com.google.genai.types.GenerateContentConfig>`
  `generateContentConfig()`
  `Instruction`
  `globalInstruction()`
  `LlmAgent.IncludeContents`
  `includeContents()`
  `Optional<com.google.genai.types.Schema>`
  `inputSchema()`
  `Instruction`
  `instruction()`
  `Optional<Integer>`
  `maxSteps()`
  `Optional<Model>`
  `model()`
  `List<? extends Callbacks.OnModelErrorCallback>`
  `onModelErrorCallback()`
  `List<? extends Callbacks.OnToolErrorCallback>`
  `onToolErrorCallback()`
  `Optional<String>`
  `outputKey()`
  `Optional<com.google.genai.types.Schema>`
  `outputSchema()`
  `boolean`
  `planning()`
  `Model`
  `resolvedModel()`
  `protected io.reactivex.rxjava3.core.Flowable<Event>`
  `runAsyncImpl(InvocationContext invocationContext)`
  Agent-specific asynchronous logic.
  `protected io.reactivex.rxjava3.core.Flowable<Event>`
  `runLiveImpl(InvocationContext invocationContext)`
  Agent-specific synchronous logic.
  `io.reactivex.rxjava3.core.Single<List<BaseTool>>`
  `tools()`
  `List<BaseToolset>`
  `toolsets()`
  `List<Object>`
  `toolsUnion()`

  ### Methods inherited from class BaseAgent

  `afterAgentCallback, beforeAgentCallback, canonicalAfterAgentCallbacks, canonicalBeforeAgentCallbacks, description, findAgent, findSubAgent, fromConfig, name, parentAgent, parentAgent, rootAgent, runAsync, runLive, subAgents, toolOrigin`
  Modifier and Type
  Method
  Description
  `com.google.common.collect.ImmutableList<? extends Callbacks.AfterAgentCallback>`
  `afterAgentCallback()`
  `com.google.common.collect.ImmutableList<? extends Callbacks.BeforeAgentCallback>`
  `beforeAgentCallback()`
  `com.google.common.collect.ImmutableList<? extends Callbacks.AfterAgentCallback>`
  `canonicalAfterAgentCallbacks()`
  The resolved afterAgentCallback field as a list.
  `com.google.common.collect.ImmutableList<? extends Callbacks.BeforeAgentCallback>`
  `canonicalBeforeAgentCallbacks()`
  The resolved beforeAgentCallback field as a list.
  `final String`
  `description()`
  Gets the one-line description of the agent's capability.
  `Optional<BaseAgent>`
  `findAgent(String name)`
  Finds an agent (this or descendant) by name.
  `Optional<BaseAgent>`
  `findSubAgent(String name)`
  Recursively search sub agent by name.
  `static BaseAgent`
  `fromConfig(BaseAgentConfig config, String configAbsPath)`
  Creates a new agent instance from a configuration object.
  `final String`
  `name()`
  Gets the agent's unique name.
  `BaseAgent`
  `parentAgent()`
  Retrieves the parent agent in the agent tree.
  `protected void`
  `parentAgent(BaseAgent parentAgent)`
  Sets the parent agent.
  `BaseAgent`
  `rootAgent()`
  Returns the root agent for this agent by traversing up the parent chain.
  `io.reactivex.rxjava3.core.Flowable<Event>`
  `runAsync(InvocationContext parentContext)`
  Runs the agent asynchronously.
  `io.reactivex.rxjava3.core.Flowable<Event>`
  `runLive(InvocationContext parentContext)`
  Runs the agent synchronously.
  `List<? extends BaseAgent>`
  `subAgents()`
  `AgentEnums.AgentOrigin`
  `toolOrigin()`
  Returns the origin of the tool when this agent is used as a tool.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### LlmAgent

    protected LlmAgent(LlmAgent.Builder builder)

- ## Method Details

  - ### builder

    public static LlmAgent.Builder builder()
    Returns a `LlmAgent.Builder` for `LlmAgent`.

  - ### determineLlmFlow

    protected BaseLlmFlow determineLlmFlow()

  - ### runAsyncImpl

    protected io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(InvocationContext invocationContext)
    Description copied from class: `BaseAgent`
    Agent-specific asynchronous logic.
    Specified by:
      `runAsyncImpl` in class `BaseAgent`
    Parameters:
      `invocationContext` - Current invocation context.
    Returns:
      stream of agent-generated events.

  - ### runLiveImpl

    protected io.reactivex.rxjava3.core.Flowable<Event> runLiveImpl(InvocationContext invocationContext)
    Description copied from class: `BaseAgent`
    Agent-specific synchronous logic.
    Specified by:
      `runLiveImpl` in class `BaseAgent`
    Parameters:
      `invocationContext` - Current invocation context.
    Returns:
      stream of agent-generated events.

  - ### canonicalInstruction

    public io.reactivex.rxjava3.core.Single<Map.Entry<String,Boolean>> canonicalInstruction(ReadonlyContext context)
    Constructs the text instruction for this agent based on the `instruction` field. Also returns a boolean indicating that state injection should be bypassed when the instruction is constructed with an `Instruction.Provider`.

    This method is only for use by Agent Development Kit.

    Parameters:
      `context` - The context to retrieve the session state.
    Returns:
      The resolved instruction as a `Single` wrapped Map.Entry. The key is the instruction string and the value is a boolean indicating if state injection should be bypassed.

  - ### canonicalGlobalInstruction

    public io.reactivex.rxjava3.core.Single<Map.Entry<String,Boolean>> canonicalGlobalInstruction(ReadonlyContext context)
    Constructs the text global instruction for this agent based on the `globalInstruction` field. Also returns a boolean indicating that state injection should be bypassed when the instruction is constructed with an `Instruction.Provider`.

    This method is only for use by Agent Development Kit.

    Parameters:
      `context` - The context to retrieve the session state.
    Returns:
      The resolved global instruction as a `Single` wrapped Map.Entry. The key is the instruction string and the value is a boolean indicating if state injection should be bypassed.

  - ### canonicalTools

    public io.reactivex.rxjava3.core.Flowable<BaseTool> canonicalTools()
    Constructs the list of tools for this agent based on the `tools()` field.
    Returns:
      The resolved list of tools as a `Single` wrapped list of `BaseTool`.

  - ### canonicalTools

    public io.reactivex.rxjava3.core.Flowable<BaseTool> canonicalTools(@Nullable ReadonlyContext context)
    Constructs the list of tools for this agent based on the `tools()` field.
    Parameters:
      `context` - The context to retrieve the session state.
    Returns:
      The resolved list of tools as a `Single` wrapped list of `BaseTool`.

  - ### instruction

    public Instruction instruction()

  - ### globalInstruction

    public Instruction globalInstruction()

  - ### model

    public Optional<Model> model()

  - ### planning

    public boolean planning()

  - ### maxSteps

    public Optional<Integer> maxSteps()

  - ### generateContentConfig

    public Optional<com.google.genai.types.GenerateContentConfig> generateContentConfig()

  - ### includeContents

    public LlmAgent.IncludeContents includeContents()

  - ### tools

    public io.reactivex.rxjava3.core.Single<List<BaseTool>> tools()

  - ### toolsUnion

    public List<Object> toolsUnion()

  - ### toolsets

    public List<BaseToolset> toolsets()

  - ### disallowTransferToParent

    public boolean disallowTransferToParent()

  - ### disallowTransferToPeers

    public boolean disallowTransferToPeers()

  - ### beforeModelCallback

    public List<? extends Callbacks.BeforeModelCallback> beforeModelCallback()

  - ### afterModelCallback

    public List<? extends Callbacks.AfterModelCallback> afterModelCallback()

  - ### beforeToolCallback

    public List<? extends Callbacks.BeforeToolCallback> beforeToolCallback()

  - ### afterToolCallback

    public List<? extends Callbacks.AfterToolCallback> afterToolCallback()

  - ### onModelErrorCallback

    public List<? extends Callbacks.OnModelErrorCallback> onModelErrorCallback()

  - ### onToolErrorCallback

    public List<? extends Callbacks.OnToolErrorCallback> onToolErrorCallback()

  - ### canonicalBeforeModelCallbacks

    public List<? extends Callbacks.BeforeModelCallback> canonicalBeforeModelCallbacks()
    The resolved beforeModelCallback field as a list.

    This method is only for use by Agent Development Kit.

  - ### canonicalAfterModelCallbacks

    public List<? extends Callbacks.AfterModelCallback> canonicalAfterModelCallbacks()
    The resolved afterModelCallback field as a list.

    This method is only for use by Agent Development Kit.

  - ### canonicalOnModelErrorCallbacks

    public List<? extends Callbacks.OnModelErrorCallback> canonicalOnModelErrorCallbacks()
    The resolved onModelErrorCallback field as a list.

    This method is only for use by Agent Development Kit.

  - ### canonicalBeforeToolCallbacks

    public List<? extends Callbacks.BeforeToolCallback> canonicalBeforeToolCallbacks()
    The resolved beforeToolCallback field as a list.

    This method is only for use by Agent Development Kit.

  - ### canonicalAfterToolCallbacks

    public List<? extends Callbacks.AfterToolCallback> canonicalAfterToolCallbacks()
    The resolved afterToolCallback field as a list.

    This method is only for use by Agent Development Kit.

  - ### canonicalOnToolErrorCallbacks

    public List<? extends Callbacks.OnToolErrorCallback> canonicalOnToolErrorCallbacks()
    The resolved onToolErrorCallback field as a list.

    This method is only for use by Agent Development Kit.

  - ### inputSchema

    public Optional<com.google.genai.types.Schema> inputSchema()

  - ### outputSchema

    public Optional<com.google.genai.types.Schema> outputSchema()

  - ### executor

    public Optional<Executor> executor()

  - ### outputKey

    public Optional<String> outputKey()

  - ### codeExecutor

    public Optional<BaseCodeExecutor> codeExecutor()

  - ### resolvedModel

    public Model resolvedModel()

  - ### fromConfig

    public static LlmAgent fromConfig(LlmAgentConfig config, String configAbsPath) throws ConfigAgentUtils.ConfigurationException
    Creates an LlmAgent from configuration with full subagent support.
    Parameters:
      `config` - the agent configuration
      `configAbsPath` - The absolute path to the agent config file. This is needed for resolving relative paths for e.g. tools and subagents.
    Returns:
      the configured LlmAgent
    Throws:
      `ConfigAgentUtils.ConfigurationException` - if the configuration is invalid

  - ### close

    public io.reactivex.rxjava3.core.Completable close()
    Description copied from class: `BaseAgent`
    Closes all sub-agents.
    Overrides:
      `close` in class `BaseAgent`
    Returns:
      a `Completable` that completes when all sub-agents are closed.