Task 48 — Границы делегации
Phase: 4
Initiative: 23
Status: done
Owner: —
Slug: delegation-boundaries
Goal
Mesh ограничивает hop count, fan-out width, кумулятивные tool calls, общую стоимость и время на запрос. Агенты могут отклонить делегацию, чтобы не превышать свою policy или capacity.
Acceptance criteria
DelegationBoundaryConfiginMeshConfig(max hop count, fan-out width, cumulative tool calls, cost, time)IDelegationBoundaryServiceinterface +DelegationBoundaryServiceimplementationDelegationBoundaryContextmodel (hop count, tool calls, cost, wall-clock)- Outgoing delegation check: reject before fan-out if boundaries exceeded
- Incoming delegation check: decline or soft-warn on boundary violation
- FanOutOrchestrator integration (pre-check before routing)
- DI registration in
MeshServiceExtensions appsettings.jsonupdated withDelegationBoundariessection- Unit tests for all boundary checks (hop, width, tool calls, cost, time)
dotnet build+dotnet testpass
Sub-tasks
- Add
DelegationBoundaryConfigtoMeshConfiginAppConfig.cs - Create
DelegationBoundaryContextmodel - Create
IDelegationBoundaryServiceinterface - Implement
DelegationBoundaryService(hop, width, tool calls, cost, time checks) - Integrate boundary checks into
FanOutOrchestrator(pre-check before routing) - Integrate boundary checks into incoming delegation path (decline with reason)
- DI registration in
MeshServiceExtensions - Add
DelegationBoundariessection toappsettings.json - Write unit tests in
tests/.../Mesh/Budget/DelegationBoundaryTests.cs dotnet build+dotnet testpass
Validation
dotnet build src/agent/Hercules.csproj— succeeddotnet test --filter "FullyQualifiedName~DelegationBoundary"— pass
Implementation notes
Hop count enforcement uses existing AuthContext.DelegationDepth field. Fan-out width checked against DelegationBoundaryConfig.MaxFanOutWidth before FanOutOrchestrator.OrchestrateFanOutAsync. Cumulative tool calls and cost tracked per request chain via in-memory ConcurrentDictionary<string, DelegationBoundaryContext> keyed by root request ID.
Scope / Likely files
src/agent/Mesh/Budget/
Dependencies
- блокирует / опирается на: task_012 — budget-guardrails
- блокирует / опирается на: task_040 — trust-admission
Risks / Rollback
Слишком жёсткие границы блокируют легитимные задачи; явный reason code + метрики.
Links
- Backlog: ../backlog.md
- Roadmap (EN): ../../ROADMAP-EN.md
- Roadmap (RU): ../../ROADMAP-RU.md