Class PlannerAgent

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

public class PlannerAgent extends BaseAgent
An agent that delegates execution planning to a Planner strategy.

The PlannerAgent owns a set of sub-agents and a planner. At runtime, the planner inspects session state and decides which sub-agent(s) to run next. This enables dynamic, goal-oriented agent orchestration — the execution topology is determined at runtime rather than being fixed at build time.

The planning loop:

  1. Planner is initialized with context and available agents
  2. Planner returns what to do next via PlannerAction
  3. Selected sub-agent(s) execute, producing events
  4. Session state (world state) is updated from events
  5. Planner sees updated state and decides the next action
  6. Repeat until PlannerAction.Done or maxIterations

Example usage with a custom planner:

PlannerAgent agent = PlannerAgent.builder()
    .name("myAgent")
    .subAgents(agentA, agentB, agentC)
    .planner(new GoalOrientedPlanner("finalOutput", metadata))
    .maxIterations(20)
    .build();
  • Method Details

    • planner

      public Planner planner()
      Returns the planner strategy used by this agent.
    • maxIterations

      public int maxIterations()
      Returns the maximum number of planning iterations.
    • 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.
    • builder

      public static PlannerAgent.Builder builder()
      Returns a new PlannerAgent.Builder for creating PlannerAgent instances.