summaryrefslogtreecommitdiff
path: root/src/Agent.Core/Runtime/PlannerService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Agent.Core/Runtime/PlannerService.cs')
-rw-r--r--src/Agent.Core/Runtime/PlannerService.cs25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/Agent.Core/Runtime/PlannerService.cs b/src/Agent.Core/Runtime/PlannerService.cs
index 7a450d0..110e476 100644
--- a/src/Agent.Core/Runtime/PlannerService.cs
+++ b/src/Agent.Core/Runtime/PlannerService.cs
@@ -55,7 +55,15 @@ public sealed class PlannerService(IOllamaClient ollama, AgentRuntimeSettings se
if (plan is null || plan.Tasks.Count == 0)
return CreateFallbackGraph(request);
- TaskGraph graph = BuildTaskGraph(plan, request);
+ TaskGraph graph;
+ try
+ {
+ graph = BuildTaskGraph(plan, request);
+ }
+ catch
+ {
+ return CreateFallbackGraph(request);
+ }
session.TaskGraphs[taskId] = graph;
return graph;
}
@@ -116,10 +124,21 @@ public sealed class PlannerService(IOllamaClient ollama, AgentRuntimeSettings se
}
string description = string.IsNullOrWhiteSpace(pt.Description) ? originalRequest : pt.Description;
- PlannerTask task = graph.AddTask(description, budgetClass, estimate, dependencies, pt.RequiresExternalEffect);
- idMap.Add(task.Id);
+ try
+ {
+ PlannerTask task = graph.AddTask(description, budgetClass, estimate, dependencies, pt.RequiresExternalEffect);
+ idMap.Add(task.Id);
+ }
+ catch (PlannerValidationException)
+ {
+ // If a task fails validation (e.g., bad estimate, cycle), fall back to single-task graph.
+ return CreateFallbackGraph(originalRequest);
+ }
}
+ // If all tasks were filtered out, fall back.
+ if (graph.Count == 0) return CreateFallbackGraph(originalRequest);
+
return graph;
}