Assistant Planner and Adaptive Planning
The planning engine is the cognitive heart of the assistant module, responsible for breaking down complex requests into actionable steps and executing them via the ReAct (Reasoning and Acting) loop.
The ReAct Loop
The core Planner (in assistant/planner.go) implements a standard ReAct loop:
- Thought: The LLM reasons about the user's request and its current context.
- Action: The LLM selects a tool to execute and provides arguments.
- Observation: The system executes the tool and captures the result.
- Repeat: The loop continues until the LLM provides a final answer.
Adaptive Planning
The AdaptivePlanner (in assistant/adaptive_planner.go) is a meta-layer on top of the standard planner designed for higher resiliency and complexity.
Key Capabilities
- Dynamic Replanning: If a tool fails or an unexpected result is observed, the adaptive planner can adjust the overall plan rather than just retrying the same step.
- Error Categorization: It categorizes failures (e.g., timeouts, rate limits, syntax errors) and applies specific recovery strategies.
- Alternative Tool Discovery: If a primary tool is unavailable or failing, it can search for alternative tools with similar capabilities.
- Hierarchical Decomposition: For very large tasks, it can decompose the problem into sub-plans that are managed independently.
Data Structures
- Plan: A list of
Taskobjects representing the steps to be taken. - Task: A specific unit of work with a description, status (Pending, InProgress, Completed, Failed), and result.
- AdaptivePlannerSession: Maintains the state of an active adaptive planning workflow.
Flow Diagram: Adaptive Planning Recovery
flowchart TD
Task[Execute Task] --> Result{Check Result}
Result -- Success --> Next[Next Task]
Result -- Failure --> Categorize[Categorize Error]
Categorize -- Retryable --> Retry[Retry Task]
Categorize -- Fatal --> Replan[Invoke Replanning]
Replan --> NewPlan[Generate Modified Plan]
NewPlan --> Task
Retry --> Task
Key Functions
NewPlannerSession(): Creates a standard ReAct session.ExecutePlan(): Orchestrates the execution of a pre-defined plan.NewAdaptivePlannerSession(): Wraps a standard session with adaptive capabilities.registerAdaptivePlannerSession(): Adds the session to the global registry for tracking.
Guidance for AI Agents
- Be Explicit in Thoughts: Clear reasoning helps the adaptive planner (and human auditors) understand why a certain path was taken.
- Handle Partial Success: If a multi-step tool partially succeeds, record the progress so the planner doesn't start from scratch.
- Use the Plan Tool: In complex sessions, use the
plantool to explicitly lay out your strategy before acting.