plan method

Future<ExecutionDAG> plan(
  1. AgentGoal goal,
  2. AgentContext context
)

Decomposes goal into an ExecutionDAG of concrete tasks.

If an LLMCore is available, it is used to generate the task list. Otherwise a simple rule-based decomposition is used as a fallback.

Implementation

Future<ExecutionDAG> plan(
  AgentGoal goal,
  AgentContext context,
) async {
  _logger.info('Planning for goal: "${_trunc(goal.description)}"');

  final dag = ExecutionDAG(goal.id);
  List<AgentTask> tasks;

  if (_llm != null) {
    tasks = await _planWithLLM(goal, context);
  } else {
    tasks = _planRuleBased(goal);
  }

  for (final t in tasks) {
    dag.add(t);
  }

  _logger.info('Plan generated: ${dag.size} task(s)');
  for (final t in dag.topologicalOrder) {
    _logger.debug(
        '  [${t.status.name}] ${t.description}'
        '${t.dependsOnIds.isNotEmpty ? " (deps: ${t.dependsOnIds.join(", ")})" : ""}');
  }

  return dag;
}