AI-driven DeFi research system with multi-agent orchestration, streaming responses, and report generation.
- Overview
- Core Capabilities
- Agent Architecture
- Data Flow
- Project Structure
- Quick Start
- API Reference
- Configuration
- Engineering Notes
- Roadmap
- License
DeFi Research Agent is an end-to-end MVP for DeFi analysis workflows. It combines:
- a FastAPI backend,
- a multi-agent pipeline (Data, Research, Report),
- tool-calling style responses,
- SSE streaming for chat,
- and a Next.js frontend for interactive analysis.
The project is designed for rapid iteration: real data first, mock fallback always available, and clear API contracts for integration.
- Multi-agent orchestration for routing between data query, analysis, and report generation.
- Live DeFi data integration with automatic fallback:
- token prices via CoinGecko,
- protocol TVL via DefiLlama,
- fallback to deterministic mock values on upstream failure.
- RAG backend switch (
simple/chroma) with graceful fallback tosimplewhenchromadbis unavailable. - Function-calling style tool trace in
/chatresponses. - Streaming output via
/chat/stream(SSE). - Frontend pages:
- streaming chat console,
- report generation dashboard.
User Query
|
v
AgentOrchestrator (routing)
|-------------------------------|
| |
v v
DataAgent ResearchAgent
| |
v v
DeFiTools (price/TVL/risk) RAG (simple/chroma)
| |
|----------- merge -------------|
|
v
ReportAgent
|
v
API Response / SSE Stream
AgentOrchestrator: task routing and execution path selection (data,research,report).DataAgent: structured metric retrieval (symbol extraction, protocol extraction, price/TVL calls).ResearchAgent: context retrieval + risk analysis + structured insights.ReportAgent: consolidates data/research outputs into report schema.ToolCallingEngine: function-calling style tool trace and deterministic summary composition.
- Added backend CORS policy for local frontend origins.
- Added frontend request error boundaries to prevent unhandled runtime crashes.
- Fixed SSE chunk duplication caused by mutable state update path.
- Improved data-route answer formatting to prevent field binding ambiguity.
Frontend (Next.js)
|
| POST /chat or /chat/stream
v
FastAPI Route Layer
|
v
AgentOrchestrator
|
+--> DataAgent --> DeFiTools --> tool_calling summary
|
+--> ResearchAgent --> RAG + risk
|
+--> ReportAgent (when report path)
|
v
JSON response or SSE chunks
defi-research-agent/
config/
default.yaml
frontend/
app/
page.tsx
report/page.tsx
src/
main.py
agents/
data_agent.py
research_agent.py
report_agent.py
orchestrator.py
core/
settings.py
rag.py
tool_calling.py
tools/
defi_tools.py
web/
app.py
middleware.py
schemas.py
routes/
health.py
chat.py
analyze.py
report.py
tests/
test_api_smoke.py
test_defi_tools.py
test_rag_backends.py
conda env create -f environment.yml
conda activate defi-research-agentcopy .env.example .envuvicorn src.main:app --reload --host 0.0.0.0 --port 8000Backend docs:
- Swagger: http://localhost:8000/docs
pytest -qcd frontend
npm install
npm run devFrontend:
If backend endpoint differs, set:
set NEXT_PUBLIC_API_BASE=http://localhost:8000GET /health
POST /chat- request:
{ "query": "ETH price and Uniswap TVL" } - response includes:
routeresult- optional
tool_calling answer
- request:
POST /chat/stream- request:
{ "query": "summarize ETH DeFi trends" } - stream events:
{"type":"chunk","content":"..."}{"type":"done"}
- request:
POST /analyze- request:
{ "query": "30d snapshot", "protocol": "Aave" }
- request:
POST /report- request:
{ "query": "generate investment brief", "protocol": "Aave" }
- request:
APP_VERSIONLOG_LEVELRATE_LIMIT_PER_MINUTE
NEXT_PUBLIC_API_BASE
config/default.yaml->rag.backendsimple(default)chroma
Install chroma backend dependency when needed:
pip install chromadbtools.use_mock_data: true: force mock mode.tools.use_mock_data: false: use live APIs first; fallback to mock on failure.
- Request observability headers:
X-Request-IdX-Process-Time-Ms
- Unified error format:
VALIDATION_ERRORINTERNAL_ERROR
- Basic in-memory rate limiting per client IP.
- CORS enabled for local frontend development origins.
- Redis caching layer and deployment baseline.
- CI gate hardening for backend tests + frontend build + stream smoke checks.
- SSE/output regression tests for duplication and field binding correctness.
This project is licensed under the MIT License. See LICENSE for details.