Refactor: Should SubAgentService.executeTask() keep its own while loop...
Documentation for Sessions
♻️ Refactor: Should SubAgentService.executeTask() keep its own while loop...
Date: 2026-03-18
Time: 16:41:57 UTC
Session: gspace1-234.4
Agent: angular
Confidence: 95%
Status: ✅ Documented
📋 Decision Context
Question:
Should SubAgentService.executeTask() keep its own while loop or delegate to AgentLoopService.run()?
Task: S234.2: Sub-Vitto Engine - SubAgentService refactoring
🎯 Decision Made
Chosen:
Replaced the manual while loop (lines 550-614) with AgentLoopService.run() call, keeping all post-loop logic (validation, outcome recording, learning logging) intact. Added SUB_AGENT_TOOL_NAMES static array for toolFilter. Marked executeSubAgentTool() as @deprecated.
Options Considered:
- Keep the manual while loop and add stuck detection/SSE separately
- Create a shared base class for both loops
- Use AgentLoopService.run() with toolFilter (chosen)
💭 Reasoning
The while loop duplicated ~160 lines of logic already in AgentLoopService: cost guards, tool call processing, message management, iteration tracking. By delegating to run(), sub-agents inherit stuck detection (loop + stall), checkpoint/crash recovery, parallel tool calls, SSE streaming, and SmartRouter model selection — all for free. The refactoring eliminates the divergence risk where bug fixes to AgentLoopService wouldn't apply to sub-agents. The SUB_AGENT_TOOL_NAMES array (4 tools: recall_memory, search_decisions, query_docs, task_complete) maps cleanly to AgentLoopOptions.toolFilter, so no custom tool execution is needed. http_request was intentionally excluded — it was already returning an error in the old executeSubAgentTool() method.
📁 Files Involved
APIs/backend-vitto-api/src/app/engine/sub-agent.service.tsAPIs/backend-vitto-api/src/app/engine/agent-loop.service.ts
🔗 Related
- Decision ID:
dev_1773852117486_gsqs3g6 - Session: 234
- Workspace: gspace1
Auto-generated by MCP Smart Consolidation