Class BaseAgent

java.lang.Object
com.google.adk.agents.BaseAgent
Direct Known Subclasses:
LlmAgent, LoopAgent, ParallelAgent, SequentialAgent

public abstract class BaseAgent extends Object
Base class for all agents.
  • Constructor Details

    • BaseAgent

      public BaseAgent(String name, String description, List<? extends BaseAgent> subAgents, List<Callbacks.BeforeAgentCallback> beforeAgentCallback, List<Callbacks.AfterAgentCallback> afterAgentCallback)
      Creates a new BaseAgent.
      Parameters:
      name - Unique agent name. Cannot be "user" (reserved).
      description - Agent purpose.
      subAgents - Agents managed by this agent.
      beforeAgentCallback - Callbacks before agent execution. Invoked in order until one doesn't return null.
      afterAgentCallback - Callbacks after agent execution. Invoked in order until one doesn't return null.
  • Method Details

    • name

      public final String name()
      Gets the agent's unique name.
      Returns:
      the unique name of the agent.
    • description

      public final String description()
      Gets the one-line description of the agent's capability.
      Returns:
      the description of the agent.
    • parentAgent

      public BaseAgent parentAgent()
      Retrieves the parent agent in the agent tree.
      Returns:
      the parent agent, or null if this agent does not have a parent.
    • parentAgent

      protected void parentAgent(BaseAgent parentAgent)
      Sets the parent agent.
      Parameters:
      parentAgent - The parent agent to set.
    • rootAgent

      public BaseAgent rootAgent()
      Returns the root agent for this agent by traversing up the parent chain.
      Returns:
      the root agent.
    • findAgent

      public BaseAgent findAgent(String name)
      Finds an agent (this or descendant) by name.
      Returns:
      the agent or descendant with the given name, or null if not found.
    • findSubAgent

      public @Nullable BaseAgent findSubAgent(String name)
      Recursively search sub agent by name.
    • subAgents

      public List<? extends BaseAgent> subAgents()
    • beforeAgentCallback

      public Optional<List<Callbacks.BeforeAgentCallback>> beforeAgentCallback()
    • afterAgentCallback

      public Optional<List<Callbacks.AfterAgentCallback>> afterAgentCallback()
    • runAsync

      public io.reactivex.rxjava3.core.Flowable<Event> runAsync(InvocationContext parentContext)
      Runs the agent asynchronously.
      Parameters:
      parentContext - Parent context to inherit.
      Returns:
      stream of agent-generated events.
    • runLive

      public io.reactivex.rxjava3.core.Flowable<Event> runLive(InvocationContext parentContext)
      Runs the agent synchronously.
      Parameters:
      parentContext - Parent context to inherit.
      Returns:
      stream of agent-generated events.
    • runAsyncImpl

      protected abstract io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(InvocationContext invocationContext)
      Agent-specific asynchronous logic.
      Parameters:
      invocationContext - Current invocation context.
      Returns:
      stream of agent-generated events.
    • runLiveImpl

      protected abstract io.reactivex.rxjava3.core.Flowable<Event> runLiveImpl(InvocationContext invocationContext)
      Agent-specific synchronous logic.
      Parameters:
      invocationContext - Current invocation context.
      Returns:
      stream of agent-generated events.