Skip to content

feat: refactor to Deep Agents architecture#503

Open
avoidwork wants to merge 28 commits into
mainfrom
feat/refactor-langgraph-to-deep-agents
Open

feat: refactor to Deep Agents architecture#503
avoidwork wants to merge 28 commits into
mainfrom
feat/refactor-langgraph-to-deep-agents

Conversation

@avoidwork

@avoidwork avoidwork commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Description

Refactored the LangGraph-based ReAct agent to use LangChain's Deep Agents architecture. Replaced the process-spawning subAgent tool family with a native orchestrator that manages specialized agents (coding agent, utility agent) for task delegation.

Changes

  • Deleted src/agent/react.js — replaced by clean deepAgents.js using createDeepAgent
  • Deleted src/tools/subAgent.js, subAgentLog.js, subAgentMessage.js — process spawning removed
  • Deleted src/tools/skills.js, src/tools/filesystem.js, src/tools/memory.js — replaced by deepagents middleware
  • Deleted src/tools/compact_context.js, src/tools/compaction.js — replaced by compaction tool
  • Removed SUB_AGENT_TEMPERATURE env var handling from src/provider/openai.js
  • Removed src/cache/llm_cache.js and tiny-lru dependency
  • Updated SYSTEM_PROMPT.md: replaced "sub-agent" terminology with "deep agent"
  • Removed old react_agent, skills, filesystem, memory, compaction tests
  • Updated index.js to use invokeAgent with Deep Agents streaming API
  • Added coding-agent and utility-agent subagents with CODE_AGENT.md prompts
  • Fixed process tool name from processTool to process
  • Removed middleware duplication that was causing test failures
  • Added OpenSpec artifacts for the change (design, proposal, specs, tasks)

Architecture

Main Agent (orchestrator) with coding-agent and utility-agent subagents.
Uses createDeepAgent with streamMode updates and subgraphs true for native streaming.

Testing

  • All tests passing, zero failures
  • Clean diff: +1274 / -7331 lines

Related Issues

Closes #502

@avoidwork avoidwork self-assigned this Jul 1, 2026
- Replace react.js with clean deepAgents.js using createDeepAgent
- Delete subAgent tool family (subAgent.js, subAgentLog.js, subAgentMessage.js)
- Remove SUB_AGENT_TEMPERATURE env var handling
- Remove old react_agent tests
- Update index.js to use invokeAgent with Deep Agents streaming
- Add coding-agent and utility-agent subagents with SUB_AGENT.md prompts
- Fix process tool name from processTool to process
- All 1128 tests passing
@avoidwork avoidwork changed the title feat: refactor-langgraph-to-deep-agents — OpenSpec proposal, design, specs, and tasks feat: refactor to Deep Agents architecture Jul 1, 2026
@avoidwork

Copy link
Copy Markdown
Owner Author

Audit Results

Status: Complete
Summary: Deep Agents refactoring implemented and tested.

Verification:

  • All 1128 tests passing, zero failures
  • react.js deleted, replaced by clean deepAgents.js using createDeepAgent
  • subAgent tool family deleted (subAgent.js, subAgentLog.js, subAgentMessage.js)
  • SUB_AGENT_TEMPERATURE env var handling removed
  • Process tool name fixed from processTool to process
  • Coding-agent and utility-agent subagents configured with SUB_AGENT.md prompts
  • Streaming uses createDeepAgent with streamMode updates and subgraphs true

Diff: +624 / -2943 lines across 23 files

Specs vs Implementation:

  • All behavioral requirements from specs implemented
  • Tasks.md all 58 tasks marked complete
  • No gaps between proposal/design/specs and implementation

Ready for review and merge.

avoidwork added 6 commits July 1, 2026 15:07
- Remove unused variables from invokeAgent (signal, maxContextLength, maxTokens)
- Remove unused namespace variable from stream loop
- Auto-format index.js and prompts.test.js
The checkpointer requires thread_id in the configurable property to
persist conversation state. Added configurable to streamOptions.
Pass systemPrompt to createDeepAgentsOrchestrator factory.
Remove manual SystemMessage prepending from invokeAgent.
- streamMode: ['updates', 'messages'] to get text chunks and tool events
- Handle mode === 'messages' for text/reasoning output
- Handle mode === 'updates' for tool_start/tool_end/tool_error events
- Fix letconst syntax error from corrupted patch
- Add missing variable initializations (currentMessages, compactionActive, etc.)
- Restore proper while loop and try/catch structure
- System prompt prepending restored in invokeAgent for new threads
@avoidwork

Copy link
Copy Markdown
Owner Author

Deep Agents Overlap Analysis

deepagents provides built-in middleware that includes these tool categories:

  • createFilesystemMiddleware — read_file, write_file, patch, search_files
  • createMemoryMiddleware — memory management
  • createSkillsMiddleware — skill discovery and management
  • createSummarizationMiddleware — context summarization/compaction

Overlapping Tools (can be removed from madz)

Madz Tool Permission Deep Agents Equivalent
readFile filesystem:read createFilesystemMiddleware
writeFile filesystem:write createFilesystemMiddleware
patch filesystem:write createFilesystemMiddleware
searchFiles filesystem:read createFilesystemMiddleware
memory filesystem:read, filesystem:write createMemoryMiddleware
skillView filesystem:read createSkillsMiddleware
createSkill filesystem:write createSkillsMiddleware
compactContext none createSummarizationMiddleware
compaction none createSummarizationMiddleware

Non-Overlapping Tools (unique to madz — keep)

Madz Tool Permission Notes
terminal filesystem:exec, process:spawn Shell execution
process process:spawn Background process management
todo filesystem:read, filesystem:write Task queue
sessionSearch filesystem:read Session history search
clarify none User clarification prompts
webSearch network:outbound Web search
webExtract network:outbound Web page extraction
visionAnalyze none Image analysis
imageGenerate network:outbound Image generation
executeCode none Code execution sandbox
cronJob network:outbound Cron scheduling
textToSpeech none TTS
mixtureOfAgents none MoA routing
sampling none Ephemeral memory sampling
date none Date/time
scanAgents none AGENTS.md scanning

Summary: 9 of 25 tools overlap with deepagents middleware. The remaining 16 are unique to madz and should stay.

Want me to remove the overlapping tools and wire up the deepagents middleware instead?

avoidwork added 18 commits July 1, 2026 16:02
…apping tools

- Create FileBackend implementing BackendProtocolV2 for file storage
- Wire up createFilesystemMiddleware, createMemoryMiddleware, createSkillsMiddleware, createSummarizationMiddleware
- Remove 9 overlapping tools from madz (readFile, writeFile, patch, searchFiles, memory, skillView, createSkill, compactContext, compaction)
- Remove LRU caching from deepAgents.js
- Remove unused compaction logic, constants, and imports
- Remaining 16 tools are madz-specific and stay
- Delete obsolete tests for removed compactContext and compaction tools
- Update tool_index.test.js to reflect current tool registry (16 tools)
- Update tool_registration.test.js assertions for removed tools
The TUI's handleChat callback expects events with { type, text } shape,
but callProvider was passing raw strings. This caused assistant response
text to never render in the conversation panel.
- Pass middleware array to createDeepAgent (was built but never wired in)
- Fix streaming callback to pass structured {type, text} events instead of raw strings
- Remove unused RECURSION_LIMIT_MESSAGE constant
- Remove unnecessary try/catch re-throw wrapper in callProvider
- Prefix unused namespace variable with _ to satisfy linter
- README.md: Agent section, tools table, env vars, directory structure
- docs/OVERVIEW.md: Replace Sub-Agent section with Deep Agents, remove Sub-Agent Log/Message sections
- docs/FLOWS.md: Replace Sub-Agent flows with Deep Agents orchestration flow
- docs/TUTORIAL.md: Update built-in tools section
- README.md: remove subAgent config entries, change 'specialized sub-agents' to 'specialized agents'
- docs/OVERVIEW.md: remove sub-agent references, rephrase code identifiers
- docs/FLOWS.md: change section titles and references
- README.md: remove subAgent, subAgentLog, subAgentMessage from tools table
- docs/FLOWS.md: remove subAgentLog from file dependencies
- docs/TUTORIAL.md: remove subAgent tool mention
- Split tools into Deep Agents middleware (filesystem, memory, skills, summarization)
- and built-in LangChain tools gated by sandbox permissions
- Omitted compactContext as requested
Removed filesystem.js, memory.js, skills.js, compact_context.js,
compaction.js and their tests — these are now handled by deepagents
middleware.
- Delete prompts/COMPACTION.md
- Rename SUB_AGENT.md → CODE_AGENT.md
- Update deepAgents.js to load CODE_AGENT.md
- Rewrite CODE_AGENT.md as a tight, deliverables-focused coding agent prompt
avoidwork added 2 commits July 1, 2026 21:04
…dule and tiny-lru

- Replace 'sub-agent' with 'deep agent' in system prompt (3 occurrences)
- Delete src/cache/llm_cache.js and remove tiny-lru dependency
…from deepagents

- Remove utility-agent subagent from src/agent/deepAgents.js
- Remove utilityAgent config from config.yaml
- Update README.md, docs/OVERVIEW.md, docs/FLOWS.md, docs/TUTORIAL.md
- Update JSDoc comment in deepAgents.js
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.

feat: refactor LangGraph to use Deep Agents

1 participant