Skip to content

Enhance agent orchestrator with real tool execution and persistence#3

Merged
seanebones-lang merged 1 commit into
mainfrom
claude/enhance-system-agents-lk66U
Mar 17, 2026
Merged

Enhance agent orchestrator with real tool execution and persistence#3
seanebones-lang merged 1 commit into
mainfrom
claude/enhance-system-agents-lk66U

Conversation

@seanebones-lang
Copy link
Copy Markdown
Owner

Summary

This PR significantly enhances the agent orchestration system by implementing real tool execution for specialized agents, adding a persistence layer for learning systems, and introducing new specialized agents for refactoring, architecture, and debugging tasks.

Key Changes

Agent Orchestrator Enhancements

  • Real Tool Execution: Agents now execute actual tools (search_code, run_command) instead of returning placeholders
  • Parallel Execution: Implemented executeAgent() function that runs agents with configurable iterations and tool call limits
  • Context Passing: Added priorContext support to pass results between agent phases
  • Progress Callbacks: Added onProgress and onToolCall callbacks for monitoring agent execution
  • Improved Plan Creation: Enhanced createOrchestrationPlan() with relevance scoring for better agent matching

Persistence Layer (New)

  • PersistenceManager: New file-based persistence system in src/lib/persistence.ts
    • Stores RAG documents, knowledge graph entities, ML patterns, precision metrics, and agent memory
    • Supports auto-save with configurable intervals
    • Includes in-memory caching with TTL for performance
    • Automatic pruning of collections exceeding size limits

Learning Systems Integration

  • RAG System: Now loads/persists documents from disk on initialization
  • Knowledge Graph: Loads persisted entities and relationships on startup
  • ML Learning System: Persists interactions, patterns, and performance metrics
  • Agent Memory: Works both client-side (localStorage) and server-side (file persistence)
  • Precision System: Persists agent metrics and enhancements across sessions

New Specialized Agents

  • Refactoring Agent (🔧): Code smell detection, DRY violations, complexity reduction, dead code elimination
  • Architecture Agent (🏗️): Dependency analysis, module boundaries, design pattern enforcement, scalability assessment
  • Debugging Agent (🔍): Systematic error tracing, stack trace analysis, root cause identification
  • Database Agent (🗄️): Schema design, query optimization, migration management, N+1 detection

Tool Executor Improvements

  • patch_file: New surgical edit tool for find/replace operations without full file rewrites
  • Retry Logic: Added exponential backoff for transient failures (network timeouts, rate limits)
  • File Caching: In-memory cache with 30-second TTL to reduce redundant reads
  • Enhanced search_code: Expanded file types, context lines, and exclusion patterns
  • Enhanced run_command: Support for pipes, redirects, configurable timeout (max 5 minutes)

MCP Bridge Enhancements

  • Multiple Transport Modes: HTTP, stdio, and fallback to local execution
  • Proper JSON-RPC: Implements JSON-RPC 2.0 protocol for MCP communication
  • Process Management: Spawns and manages MCP server processes with proper cleanup

Agent Loop Updates

  • Added patch_file, web_search, and web_browse to available tools
  • Updated tool documentation with new parameters and capabilities
  • Expanded allowed commands (vitest, make, docker, curl)

Code Organization

  • Consolidated agent definitions: security.ts, testing.ts, documentation.ts, performance.ts now re-export from canonical specialized-agents.ts source
  • Reduced duplication and maintenance burden

Implementation Details

  • Workspace Safety: All file operations respect AGENT_WORKSPACE boundaries
  • Error Handling: Comprehensive error handling with proper fallbacks
  • Performance: Caching and retry logic minimize redundant operations
  • Scalability: Persistence system handles up to 10,000 items per collection with automatic pruning
  • Backward Compatibility: Existing agent APIs remain unchanged; new features are additive

Testing Recommendations

  • Verify agent execution with various task types
  • Test persistence across server restarts
  • Validate tool execution with edge cases (large files, timeouts, network failures)
  • Confirm learning systems properly load and save state

https://claude.ai/code/session_01EgmjHaEN3MdD47o3BgynKV

Major enhancements across the entire agent system:

**Agent Loop & Tools:**
- Fix tool numbering collision (duplicate ###6 entries)
- Add parallel tool call support (JSON array format)
- Add patch_file tool for surgical find/replace edits
- Enhance search_code with 25+ file extensions, context lines, exclusions
- Enable shell mode for run_command (pipes, redirects, && chains)
- Add configurable timeout for run_command (up to 5 minutes)
- Add in-memory file cache with 30s TTL
- Add automatic retry with exponential backoff for transient failures

**Agent Orchestrator:**
- Replace stub/placeholder swarm execution with real agent execution
- Agents now actually run tool calls (search_code, run_command, etc.)
- Add inter-phase context passing between sequential phases
- Add relevance-scored agent matching for task routing
- Track toolsUsed and filesChanged per agent result

**MCP Bridge:**
- Implement real HTTP transport (MCP_SERVER_URL env)
- Implement real stdio transport (MCP_SERVER_CMD env)
- Add MCP_ENABLED env toggle
- Add graceful shutdown for stdio processes

**Persistence Layer (NEW):**
- Add file-based JSON persistence in .grok-data/ directory
- Wire into RAG system, Knowledge Graph, ML Learning, Precision System
- All learning data survives server restarts
- Auto-save with configurable interval, flush on process exit

**Agent Memory:**
- Fix server-side support (was localStorage-only, silent no-op on server)
- Server-side now uses file persistence layer
- Client-side still uses localStorage as before

**New Specialized Agents:**
- Refactoring Agent: code smells, DRY violations, complexity reduction
- Architecture Agent: dependency graphs, module boundaries, design patterns
- Debugging Agent: systematic error tracing, root cause analysis
- Database Agent: schema design, query optimization, N+1 detection

**Cleanup:**
- Consolidate duplicate agent definitions (agents/*.ts re-export from canonical source)
- Fix hardcoded date in BASE_2026_PROMPT (now dynamic via getBase2026Prompt())
- Add web_search and web_browse to ToolName type union

https://claude.ai/code/session_01EgmjHaEN3MdD47o3BgynKV
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
grokcode Error Error Mar 17, 2026 5:16pm

Request Review

@seanebones-lang seanebones-lang merged commit 1cff4fd into main Mar 17, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants