# 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();

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `PlannerAgent.Builder`
  Builder for `PlannerAgent`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static PlannerAgent.Builder`
  `builder()`
  Returns a new `PlannerAgent.Builder` for creating `PlannerAgent` instances.
  `int`
  `maxIterations()`
  Returns the maximum number of planning iterations.
  `Planner`
  `planner()`
  Returns the planner strategy used by this agent.
  `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.

  ### Methods inherited from class BaseAgent

  `afterAgentCallback, beforeAgentCallback, canonicalAfterAgentCallbacks, canonicalBeforeAgentCallbacks, close, 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.
  `io.reactivex.rxjava3.core.Completable`
  `close()`
  Closes all sub-agents.
  `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`

- ## 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.