Skip to content

[Feature] Advanced planning and task decomposition for CugaSupervisorGraph #103

@sami-marreed

Description

@sami-marreed

What you want and why

Inspired by #57, the CugaSupervisorGraph should gain a proper planning and task decomposition layer analogous to what TaskDecompositionNode + PlanControllerNode provide for the main AgentState graph.

Today the supervisor uses create_update_todos as its only lightweight planning primitive (see create_prepare_agents_and_prompt_node in cuga_supervisor_graph.py). This is enough for simple linear tasks but falls short when:

  • The user's request spans multiple agents and requires sequential or parallel sub-task execution with dependencies.
  • Operators want the supervisor to produce a visible, structured plan before execution starts (currently plan_approval only interrupts for a yes/no approval of the agent list, not a structured plan).
  • There is no mechanism to surface intermediate progress as chat messages — sub-agent results are opaque until the supervisor emits its final_answer.
  • Complex multi-agent tasks have no complexity-based trigger to decide when structured decomposition is warranted versus simple create_update_todos.

How it could work

1. Supervisor-aware PlanningMode

Introduce a PlanningMode enum (mirroring #57's proposal) with a AGENTS variant consumed by the supervisor:

class PlanningMode(str, Enum):
    TOOLS = "tools"    # CugaLite (existing)
    AGENTS = "agents"  # CugaSupervisor (new)
    DEFAULT = "default"

2. SupervisorTaskDecompositionNode

A new node (or a parameterised variant of TaskDecompositionNode) that:

  • Receives the user intent and the set of available agents (from CugaSupervisorState.available_agents).
  • Produces a structured SupervisorTaskPlan: an ordered list of sub-tasks, each scoped to a named agent, with dependency links.
  • Respects the existing policy layer — routing, sequencing, and approval policies already resolved in prepare_agents_and_prompt must be reflected in the plan.

3. SupervisorPlanControllerNode

A new controller node (parallel to PlanControllerNode) wired into the supervisor graph that:

  • Drives execution through the structured plan rather than leaving the LLM free to generate arbitrary delegation code.
  • Tracks each sub-task's status (pendingin_progresscompleted / failed) in CugaSupervisorState.
  • Decides whether to delegate to the next agent, retry a failed sub-task, or conclude the plan.
  • Falls back to the current conversational loop for single-agent or conversational tasks.

4. Planning trigger logic

Add a heuristic (configurable via settings) to decide when structured planning is needed:

Condition Mode chosen
>1 agent and task has explicit sequencing cues Structured decomposition
Single agent, single step create_update_todos
settings.supervisor.force_planning = true Always structured

5. Chat message synchronisation

When structured planning is active, inject tagged AIMessage entries into supervisor_chat_messages at key moments:

  • After decomposition: formatted plan with all sub-task statuses.
  • Sub-task start: update or append a status message naming the active agent.
  • Sub-task completion: brief result summary before moving to the next sub-task.
  • Plan complete: final summary before final_answer is emitted.

6. YAML / SDK surface

Expose a planning_mode field in the supervisor: stanza and a matching parameter on create_cuga_supervisor_graph():

supervisor:
  planning_mode: agents   # "agents" | "default"
create_cuga_supervisor_graph(
    supervisor_model=...,
    agents=...,
    planning_mode=PlanningMode.AGENTS,
)

Links or extra context

  • Parent inspiration: [Feature]: Generic Task Decomposition & Planning Component with Chat Synchronization #57 (Generic Task Decomposition & Planning Component)
  • Relevant files:
    • src/cuga/backend/cuga_graph/nodes/cuga_supervisor/cuga_supervisor_graph.pycreate_cuga_supervisor_graph, prepare_agents_and_prompt, call_model
    • src/cuga/backend/cuga_graph/nodes/cuga_supervisor/cuga_supervisor_state.py — state fields to extend
    • src/cuga/backend/cuga_graph/nodes/task_decomposition_planning/plan_controller.py — reference implementation of PlanControllerNode
    • src/cuga/backend/cuga_graph/nodes/task_decomposition_planning/task_decomposition.py — reference TaskDecompositionNode
    • src/cuga/supervisor_utils/supervisor_config.py — YAML config loading (needs planning_mode field)
  • The existing create_update_todos tool should remain as the default / low-complexity path; structured planning is an opt-in enhancement.
  • CugaSupervisorState already has available_agents, supervisor_allowed_agents, supervisor_sequence_order, and supervisor_dispatched_agents — these can seed the plan without re-running policy checks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions