You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(chat-agent): Introduce sub-agents for high-context tools #74
The current chat agent has 13 tools loaded directly, which causes two main issues:
Context pollution - Tools like web_read, document parsing (pdf, docx, pptx), and integration can generate large outputs (20K-50K tokens for web pages, large document content, database query results). These accumulate in the main agent's context window, leading to:
Increased token usage and cost
Potential context overflow
Degraded performance as context grows
Tool schema overhead - All 13 tool descriptions are included in every request, adding ~4,000-6,500 tokens to the system prompt even when most tools aren't needed.
Proposed Solution
Introduce 3 specialized sub-agents to handle high-context tools, following the existing workflow_assistant pattern:
Activity
larryro commentedon Jan 4, 2026
Implementation Plan
Overview
Refactor the chat agent to delegate high-context tools to specialized sub-agents, following the existing
workflow_assistant_tool.tspattern.Goals:
Current vs. Proposed Architecture
Before (13 tools in chat agent)
After (8 tools in chat agent)
Token Savings: ~40-50% reduction in tool schema tokens
New Sub-Agents (3 total)
OPENAI_MODELOPENAI_MODELOPENAI_MODELImplementation Steps
Phase 1: Create Sub-Agent Factory Functions
New files:
convex/lib/create_web_agent.tsweb_readOPENAI_MODELconvex/lib/create_document_agent.tspdf,image,docx,pptx,generate_excelOPENAI_MODELconvex/lib/create_integration_agent.tsintegration,integration_introspect,verify_approvalOPENAI_MODELPhase 2: Create Sub-Agent Delegation Tools
New files:
convex/agent_tools/sub_agents/web_assistant_tool.tsconvex/agent_tools/sub_agents/document_assistant_tool.tsconvex/agent_tools/sub_agents/integration_assistant_tool.tsparentThreadIdfor approval card linkingPhase 3: Create Sub-Agent Instructions
New files in
convex/agent_tools/sub_agents/instructions/:web_instructions.ts- URL fetching, search optimization, content summarizationdocument_instructions.ts- File format handling, template workflowsintegration_instructions.ts- Approval workflows, pre-validationPhase 4: Update Tool Registry
Modify:
convex/agent_tools/tool_registry.tsweb_assistant,document_assistant,integration_assistantPhase 5: Update Chat Agent (Replace Tools)
Modify:
convex/lib/create_chat_agent.tsBefore:
After:
Phase 6: Update Instructions & Test
Update chat agent system instructions:
Note: Keep original tools in the registry (sub-agents still use them). Only the chat agent's default tool selection changes.
Key Design Decisions
Files Summary
Files to Modify (2)
convex/agent_tools/tool_registry.tsconvex/lib/create_chat_agent.tsFiles to Create (9)
convex/lib/create_web_agent.tsconvex/lib/create_document_agent.tsconvex/lib/create_integration_agent.tsconvex/agent_tools/sub_agents/web_assistant_tool.tsconvex/agent_tools/sub_agents/document_assistant_tool.tsconvex/agent_tools/sub_agents/integration_assistant_tool.tsconvex/agent_tools/sub_agents/instructions/web_instructions.tsconvex/agent_tools/sub_agents/instructions/document_instructions.tsconvex/agent_tools/sub_agents/instructions/integration_instructions.tsReference Pattern
Follow the existing implementation in:
convex/agent_tools/sub_agents/workflow_assistant_tool.ts- Delegation tool patternconvex/lib/create_workflow_agent.ts- Agent factory patternTesting Checklist
web_assistantcorrectly delegates toweb_readdocument_assistanthandles all file operations (pdf, image, docx, pptx, generate_excel)integration_assistanthandles integrations with approval flowparentThreadIdis correctly passed for approval card linkingintegration_assistant(admin/developer only)customer_read,product_read,rag_search,context_search) still work fastworkflow_assistantfunctionality