Production-ready FastAPI service for blockchain intent orchestration with auditable run steps, tool-call logging, and policy gating.
- Deterministic graph execution with step-level audit trail
- Conversational router for QUERY/ACTION/CLARIFY intents
- Tool-call instrumentation for all external calls
- Policy engine for risk checks and approval gating
- Persisted artifacts for resumable runs
- Run outcomes include
final_statusandcurrent_stepfor UI state
Client -> FastAPI -> LangGraph -> Policy Engine -> Web3 RPC
| |
| +-> run_steps (audit)
+-> tool_calls (observability)
+-> runs (FSM + artifacts)
Client -> /v1/chat/route -> tools (query) or runs (action)
- Python 3.12
- PostgreSQL 14+
uv venv
uv pip install -r requirements.txt
uv run uvicorn app.main:app --reloadIf you prefer plain venv:
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\Activate.ps1
pip install -r requirements.txt
uvicorn app.main:app --reloaddocker compose up --builddocker-compose.override.yml bind-mounts the repo and enables --reload.
Create a .env (see .env.example):
Required:
DATABASE_URLRPC_URLSALLOWLIST_TO(JSON list of allowlisted target addresses)
Optional:
ALLOWLIST_TO_ALL(true/false, bypass target allowlist checks for local dev)ALLOWLISTED_TOKENS,ALLOWLISTED_ROUTERSLLM_MODELLOG_LEVEL,LOG_JSONLANGSMITH_*
alembic upgrade headBase: http://localhost:8000
Endpoints:
POST /v1/chat/routeroute a chat message (QUERY/ACTION/CLARIFY)POST /v1/runscreate a runPOST /v1/runs/{id}/startexecute the graphPOST /v1/runs/{id}/approveapprovePOST /v1/runs/{id}/rejectrejectGET /v1/runs/{id}fetch run detailsGET /v1/runs/{id}?includeArtifacts=truefetch run + artifactsGET /v1/runs/{id}/tool-callstool-call timeline
Run responses include current_step and final_status to support UI progress
and gating (approval/execute only proceed when final_status == READY).
- Native transfers:
send 0.0001 eth to 0x...transfer 0.1 matic to 0x...
- DeFi swaps (approve + swap) on allowlisted tokens/routers:
swap 1 usdc to weth
If the intent does not match supported formats, the planner returns a noop plan.
- GENERAL handles greetings/help without triggering clarifications
- At any time, exactly one ACTION intent may be active per conversation.
- QUERY intents are non-blocking and can be answered while an ACTION is pending.
uv run pytestuv run streamlit run streamlit_app.pySet Backend URL to your API (default: http://localhost:8000).
api/ FastAPI routes and schemas
app/ app config and middleware
app/chat/ chat routing, tools, and conversation state
chain/ web3 client and RPC helpers
db/ models, repos, migrations
graph/ LangGraph nodes and state
policy/ policy rules and engine
tools/ tool-call instrumentation
- Create a feature branch
- Add tests for behavior changes
- Ensure migrations are included for schema changes