diff options
| author | tanaka takashi <isazaka@gmail.com> | 2026-08-11 22:36:21 +0900 |
|---|---|---|
| committer | tanaka takashi <isazaka@gmail.com> | 2026-08-11 22:36:21 +0900 |
| commit | 8f8e82e00e5d0e9347feef10111faac788ad7d88 (patch) | |
| tree | 300934ab2cf1af03c0eeeb18e496608fe4d63e60 /src/Agent.Planner/TaskGraph.cs | |
| parent | c34a0df11ee4dd899781b44e7c4557e76b511fd5 (diff) | |
Require task-specific tool evidence
Diffstat (limited to 'src/Agent.Planner/TaskGraph.cs')
| -rw-r--r-- | src/Agent.Planner/TaskGraph.cs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/Agent.Planner/TaskGraph.cs b/src/Agent.Planner/TaskGraph.cs index 729f646..a4cdc5f 100644 --- a/src/Agent.Planner/TaskGraph.cs +++ b/src/Agent.Planner/TaskGraph.cs @@ -19,7 +19,7 @@ public sealed class TaskGraph(int maxTasks = 32) IEnumerable<Guid>? dependencies = null, bool requiresExternalEffect = false, Guid? id = null, - IEnumerable<string>? requiredEffectTools = null) + IEnumerable<string>? requiredTools = null) { if (string.IsNullOrWhiteSpace(description)) throw new PlannerValidationException("Task description is required."); if (_tasks.Count >= MaxTasks) throw new PlannerValidationException($"Task limit of {MaxTasks} exceeded."); @@ -27,13 +27,12 @@ public sealed class TaskGraph(int maxTasks = 32) Guid taskId = id ?? Guid.NewGuid(); if (_tasks.ContainsKey(taskId)) throw new PlannerValidationException($"Task '{taskId}' already exists."); HashSet<Guid> dependencySet = dependencies?.ToHashSet() ?? []; - HashSet<string> effectTools = requiredEffectTools?.ToHashSet(StringComparer.Ordinal) ?? []; - if (requiresExternalEffect && effectTools.Count == 0) throw new PlannerValidationException("An external-effect Task must name at least one required effect tool."); - if (!requiresExternalEffect && effectTools.Count != 0) throw new PlannerValidationException("A non-effect Task cannot require an effect tool."); + HashSet<string> tools = requiredTools?.ToHashSet(StringComparer.Ordinal) ?? []; + if (requiresExternalEffect && tools.Count == 0) throw new PlannerValidationException("An external-effect Task must name at least one required tool."); EnsureDependenciesExist(dependencySet); if (dependencySet.Contains(taskId)) throw new PlannerValidationException("A task cannot depend on itself."); - _tasks.Add(taskId, new MutableTask(taskId, description, dependencySet, budgetClass, estimate, requiresExternalEffect, effectTools)); + _tasks.Add(taskId, new MutableTask(taskId, description, dependencySet, budgetClass, estimate, requiresExternalEffect, tools)); _insertionOrder.Add(taskId); try { @@ -167,7 +166,7 @@ public sealed class TaskGraph(int maxTasks = 32) if (task.State == PlannerTaskState.Completed) throw new PlannerValidationException("Completed tasks are immutable."); } - private sealed class MutableTask(Guid id, string description, HashSet<Guid> dependencies, TokenBudgetClass budgetClass, TokenEstimate estimate, bool requiresExternalEffect, HashSet<string> requiredEffectTools) + private sealed class MutableTask(Guid id, string description, HashSet<Guid> dependencies, TokenBudgetClass budgetClass, TokenEstimate estimate, bool requiresExternalEffect, HashSet<string> requiredTools) { public Guid Id { get; } = id; public string Description { get; } = description; @@ -178,7 +177,7 @@ public sealed class TaskGraph(int maxTasks = 32) public long ActualInputTokens { get; set; } public long ActualOutputTokens { get; set; } public bool RequiresExternalEffect { get; } = requiresExternalEffect; - public HashSet<string> RequiredEffectTools { get; } = requiredEffectTools; - public PlannerTask Snapshot() => new(Id, Description, Dependencies.ToHashSet(), State, BudgetClass, Estimate, ActualInputTokens, ActualOutputTokens, RequiresExternalEffect, RequiredEffectTools.ToHashSet(StringComparer.Ordinal)); + public HashSet<string> RequiredTools { get; } = requiredTools; + public PlannerTask Snapshot() => new(Id, Description, Dependencies.ToHashSet(), State, BudgetClass, Estimate, ActualInputTokens, ActualOutputTokens, RequiresExternalEffect, RequiredTools.ToHashSet(StringComparer.Ordinal)); } } |
