LangGraph + FastAPI service that generates Next.js code, supports human approval, and streams status updates.
- Accepts a generation request (
query,job_id,user_id, optionalmanifest). - Builds an implementation plan and pauses for approval.
- On approval, generates project files and sends them to your backend webhook.
- Publishes realtime events to Ably.
- Accepts build-error feedback and attempts automatic code fixes.
/Users/dulina/Documents/Research Project/Platform/Agent_v1_python
- Python
3.11+ pip- Network access to your model provider (Azure OpenAI or OpenAI)
cd "/Users/dulina/Documents/Research Project/Platform/Agent_v1_python"
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
cp .env.example .env
# Edit .env with your real valuesStart the API server (recommended):
uvicorn api.webhook:app --host 0.0.0.0 --port 8000 --reloadHealth check:
curl http://localhost:8000/healthExpected response:
{"status":"healthy","version":"0.5.0"}You can also run:
python app.pyNote: app.py is currently hardcoded to port 8001, while api/webhook.py defaults to API_PORT (default 8000).
Copy from .env.example and set these values.
AZURE_OPENAI_ENDPOINTAZURE_OPENAI_API_KEYAZURE_OPENAI_DEPLOYMENT_NAMEAZURE_OPENAI_API_VERSIONABLY_API_KEYNODE_BACKEND_URLNODE_BACKEND_WEBHOOK_SECRET
REDIS_URL(recommended, native Redis URL)
Example:
REDIS_URL=redis://default:password@your-redis-host:6379Without REDIS_URL, the agent falls back to in-memory checkpointing (state is lost on restart).
ABLY_CHANNEL_PREFIX(default:ai-backend-generation)API_HOST(default:0.0.0.0)API_PORT(default:8000)WEBHOOK_SECRET(validates legacy callback signatures)CONTAINER_BUILD_URLBACKEND_URLFASTAPI_WEBHOOK_SECRETPINECONE_API_KEY,PINECONE_INDEX_NAME(template RAG index)MCP_DOCS_SERVER_URLorMCP_DOCS_SERVER_COMMANDAZURE_STORAGE_CONNECTION_STRINGOPENAI_API_KEY(fallback if not using Azure OpenAI)
GET /healthPOST /api/v1/generateGET /api/v1/generate/{job_id}GET /api/v1/generate/{job_id}/filesPOST /api/v1/generate/{job_id}/approvePOST /api/v1/generate/{job_id}/rejectPOST /api/v1/generate/{job_id}/build-errorPOST /api/v1/chat/{job_id}POST /api/v1/chat/{job_id}/modify
Legacy endpoints:
POST /callbacks/build-status/{thread_id}POST /callbacks/human-response/{thread_id}
curl -X POST "http://localhost:8000/api/v1/generate" \
-H "Content-Type: application/json" \
-d '{
"query": "Create a modern dashboard with KPI cards and table",
"user_id": "user-001",
"job_id": "job-001",
"manifest": {
"name": "sample-backend",
"endpoints": [
{"path": "/api/users", "method": "GET"},
{"path": "/api/users", "method": "POST"}
]
},
"data_mode": "real_api",
"api_base_url": "http://localhost:8080"
}'curl "http://localhost:8000/api/v1/generate/job-001"curl -X POST "http://localhost:8000/api/v1/generate/job-001/approve" \
-H "Content-Type: application/json" \
-d '{
"user_id": "user-001"
}'curl -X POST "http://localhost:8000/api/v1/generate/job-001/reject" \
-H "Content-Type: application/json" \
-d '{
"user_id": "user-001",
"feedback": "Use tabs instead of side navigation"
}'curl -X POST "http://localhost:8000/api/v1/generate/job-001/build-error" \
-H "Content-Type: application/json" \
-d '{
"phase": "dev",
"errors": [
"Module not found: Cannot resolve ./components/Button"
],
"fullOutput": "full build log text here",
"retries_used": 0
}'Ably channel name format:
{ABLY_CHANNEL_PREFIX}:{job_id}
Default prefix:
ai-backend-generation
Common statuses you will receive include:
startedspecs_extractedapprovedrejectedcompletedfailedreflexion_progressreflexion_escalate
Run the setup test script:
python tests/test_setup.pyRun full tests:
pytest -quvicorn api.webhook:app ...default is8000(or.envAPI_PORT).python app.pyis currently hardcoded to8001.
- Confirm you are querying the same
job_idyou submitted. - Server restart clears in-memory
_active_jobs. - Use
REDIS_URLif you need durable checkpointing.
- Verify
ABLY_API_KEYis set and valid. - Confirm frontend subscribes to
ai-backend-generation:{job_id}or your custom prefix.
- Set a valid
REDIS_URL. - Upstash REST credentials alone may not provide full LangGraph checkpoint persistence.
DOCUMENTATION.md(full architecture and flow)USER_GUIDE.md(workflow guide)PINECONE_SETUP.md(RAG index setup)SSL_CERTIFICATE_FIX.md(SSL troubleshooting)