Class LlmAgent

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

public class LlmAgent extends BaseAgent
The LLM-based agent.
  • Constructor Details

  • 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

      @Deprecated public io.reactivex.rxjava3.core.Flowable<BaseTool> canonicalTools(Optional<ReadonlyContext> context)
      Deprecated.
    • 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()
    • exampleProvider

      public Optional<BaseExampleProvider> exampleProvider()
    • includeContents

      public LlmAgent.IncludeContents includeContents()
    • tools

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

      public List<Object> toolsUnion()
    • toolsets

      public com.google.common.collect.ImmutableList<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.