DSA Solver Agent
A constraint-aware, adversarial multi-agent loop that turns a problem statement into a
reviewed, submission-ready solution. Every node has a distinct responsibility and the final
answer must pass a verifier.
problem + constraints
|--------------------|
semantic analyzer
|
|-----------------------|
N code generators M edge-case generators
|-----------------------|
|
parallel candidate validators
| fail
pass --------> repair + revalidation
|
final solution
The edge-case node targets boundary values, duplicates, degenerate structures, overflow,
counterexamples to tempting greedy logic, and worst-case performance. Strategy agents receive
these cases before writing code.
Run
Requires Python 3.11+ and an OpenAI API key. Copy the example file and edit .env:
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -e .
Copy-Item .env.example .env
# Replace the placeholder in .env with: OPENAI_API_KEY=sk-...
# This project defaults to the US regional endpoint. To override it, add:
# OPENAI_BASE_URL=https://api.openai.com/v1
dsa-solve problem.txt --constraints constraints.txt --language cpp --output solution.json
.env is excluded from Git. Use --env-file path\to\another.env for another file.
Render the execution trace from the generated JSON as a PNG:
dsa-graph solution.json --output agent-graph.png
Tune fan-out with --agents 6 --edge-agents 4 --validators 2 --repairs 2. The normal successful
path uses only three serial API waves; generators and validators run concurrently. The JSON contains the
interpretation, generated edge cases, approach, proof, complexity, code, confidence, review,
and execution trace.
The LLM interface is provider-independent and fakeable in tests. The system fails closed if
no candidate passes verification: no LLM can guarantee correctness for literally every DSA
problem, so confidence is checked instead of assumed.
For --language cpp, the final verifier enforces #include <bits/stdc++.h> as the only include
and rejects Boost or other external libraries.
Run offline tests with python -m pytest after installing pytest.
dsa-solve problem.txt --constraints constraints.txt --language cpp --agents 6 --edge-agents 4 --validators 2 --repairs 2
--output solution.json
(Get-Content solution.json -Raw | ConvertFrom-Json).code |
Set-Content solution.cpp