A powerful multi-agent coding system built with deepagents, LangGraph, and the bmodel LLM wrapper. This agent can write, review, and refactor complex Python code autonomously while maintaining strict correctness and optimal time/space complexity.
Instead of manually wiring up subprocess and filesystem tools, the implementation uses deepagents.backends.FilesystemBackend.
root_dir="sandbox": All file operations (reads, writes, lists) are automatically jailed to this directory.virtual_mode=True: Ensures the backend operates securely within the confines of the sandbox, providing standard tools to the agent out-of-the-box.
The AsyncSqliteSaver from LangGraph is used to persist the agent's state.
- By connecting to
checkpoints.db, the agent can remember past interactions within a specificthread_id. - This is crucial for long-running tasks or multi-turn conversations where context needs to be preserved across sessions.
To prevent the main agent from being overwhelmed by complex tasks, work is delegated to specialized subagents. deepagents automatically exposes these subagents as tools to the main agent.
- The Coding Agent (
coding_agent): A dedicated worker for writing and modifying complex code. Offloads the heavy lifting of writing out files, allowing the main agent to focus on orchestration. - The Validator Agent (
validator_agent): An elite code reviewer tasked with ensuring optimal time and space complexity. LLMs often take shortcuts (e.g., usingO(n log n).sort()for a Priority Queue insert instead ofO(log n)heap operations). The validator acts as a strict gatekeeper to catch and reject sub-optimal code.
The true power of this setup comes from the strict, state-machine-like prompting used to orchestrate the subagents:
- The validator is strictly mandated to output
"STATUS: REJECTED"or"STATUS: APPROVED"and provide fixes for sub-optimal code. - The main orchestrator is instructed to run a rigid feedback loop: passing tasks to the coder, submitting the result to the validator, and returning feedback to the coder until it receives an
APPROVEDstatus. It is FORBIDDEN from finishing early.
- Python 3.13+
- uv (for fast dependency management)
- Clone the repository and navigate to the project root:
cd coding-agent - Install dependencies using
uv:(This will installuv sync
langgraph,deepagents,aiosqlite, and my localbmodelpackage)
Run the main agent script:
uv run main.pyThe script will automatically create the sandbox directory and begin generating and validating code (e.g., creating the optimal data structures). You can watch the files appear in real-time in the sandbox/ folder and inspect the SQLite database checkpoints.db for thread state.