Full-stack AI agent combining Ollama (local LLM), Tavily web search, and x402-style payment simulation — built with Python + Streamlit
trustflow-ai is an early-stage Python project in the AI payments / x402 ecosystem. It currently has 0 GitHub stars and 0 forks.
A full-stack AI agent system combining a local LLM (via Ollama), real-time web search (Tavily), an x402-style payment simulation layer, and ERC-8004 blockchain decision logging — all wrapped in a Streamlit chat interface.
Project Structure:
trustflow-ai/
├── backend/
│ ├── __init__.py # Package marker
│ ├── config.py # Centralised env-var configuration
│ ├── logger.py # Structured JSON logger
│ ├── llm.py # Ollama REST client (local LLM)
│ ├── search.py # Tavily web-search client
│ ├── payment.py # x402-style payment simulation layer
│ ├── agent.py # ReAct orchestrator (LLM + search + payment + blockchain)
│ └── services/
│ └── blockchain.py # ERC-8004 decision logging & on-chain verification
├── frontend/
│ └── app.py # Streamlit UI (Chat + Trust Ledger tabs)
├── contracts/
│ ├── TrustLedger.sol # Smart contract for on-chain decision storage
│ └── deploy.js # Hardhat deployment script
├── logs/ # JSON log output (git-ignored)
├── .env.example # Environment variable template
├── .gitignore
├── requirements.txt
└── README.md
System Flow:
┌─────────────┐ ┌──────────────┐ ┌─────────────────┐
│ Frontend │────▶│ Agent │────▶│ Ollama (LLM) │
│ (Streamlit) │ │ Orchestrator │ └─────────────────┘
└─────────────┘ └──────┬───────┘
│
┌──────▼───────┐ ┌─────────────────┐
│ Decision │────▶│ Tavily Search │
│ Logger │ └─────────────────┘
└──────┬───────┘
│
┌──────▼───────┐ ┌─────────────────┐
│ Blockchain │────▶│ ERC-8004 │
│ Service │ │ TrustLedger │
└──────────────┘ └─────────────────┘
backend/llm.py — Ollama IntegrationWraps Ollama's /api/chat endpoint for local LLM inference.
ConnectionError with a clear message if Ollama is not runningbackend/search.py — Tavily SearchCalls the Tavily Search API for real-time web results.
format_for_context() serialises results into LLM-ready textbackend/payment.py — x402 Payment LayerSimulates the HTTP 402 Payment Required micropayment pattern.
Wallet has a credit balance and an immutable transaction ledgerwallet.authorize(cost) — deducts credits or raises PaymentRequiredErrorwallet.top_up() — adds credits (simulates settlement).envbackend/agent.py — ReAct OrchestratorImplements a Reason → Act loop with blockchain decision logging:
{"action": "search", "query": "…"} or {"action": "answer", "content": "…"}search: Tavily is called, results injected into context, loop continuesanswer: final response returned with full thought tracebackend/services/blockchain.py — ERC-8004 Identity & Decision LoggingLogs every AI decision on Ethereum with verifiable identity.
frontend/app.py — Streamlit UI| Requirement | Version | Notes |
|---|---|---|
| Python | 3.10+ | |
| Ollama | latest | Must be running locally |
| Ollama model | any | e.g. ollama pull llama3 |
| Tavily API key | — | Optional — free tier available |
| Ethereum RPC | — | Optional — for on-chain logging |
git clone https://github.com/joshuapremkumar/trustflow-ai.git
cd trustflow-ai
cp .env.example .env
# Edit .env — add your TAVILY_API_KEY and ETHEREUM_RPC_URL (optional)
ollama serve # start the Ollama daemon
ollama pull llama3 # pull your chosen model
Windows:
streamlit run frontend/app.py
macOS / Linux:
streamlit run frontend/app.py
Open http://localhost:8501 in your browser.
| Variable | Default | Description |
|---|---|---|
OLLAMA_BASE_URL |
http://localhost:11434 |
Ollama server URL |
OLLAMA_DEFAULT_MODEL |
llama3 |
Local model name |
TAVILY_API_KEY |
(empty) | Tavily API key (optional) |
TAVILY_MAX_RESULTS |
5 |
Max search results per query |
PAYMENT_INITIAL_CREDITS |
10.0 |
Starting wallet balance |
PAYMENT_LLM_COST |
0.05 |
Credits per LLM call |
PAYMENT_SEARCH_COST |
0.10 |
Credits per search call |
PAYMENT_TOPUP_AMOUNT |
5.0 |
Credits added per top-up |
ETHEREUM_RPC_URL |
(empty) | Ethereum RPC URL (optional) |
ETHEREUM_PRIVATE_KEY |
(empty) | Wallet private key (optional) |
ETHEREUM_CONTRACT_ADDRESS |
(empty) | Deployed contract (optional) |
AGENT_ID |
trustflow-erc8004-001 |
ERC-8004 agent identity |
LOG_LEVEL |
INFO |
Logging verbosity |
User sends message
│
▼
wallet.authorize(LLM_COST) ──── insufficient? ──► HTTP 402 analogue
│
▼
Ollama LLM call
│
├─ action: "search"
│ │
│ ▼
│ wallet.authorize(SEARCH_COST) ──── insufficient? ──► 402
│ │
│ ▼
│ Tavily search → inject results → loop back to LLM
│
└─ action: "answer"
│
▼
wallet.authorize(BLOCKCHAIN_LOG_COST)
│
▼
Log decision with SHA-256 hash (ERC-8004 identity)
│
▼
Return AgentResponse (answer + trace + blockchain record)
Every AI decision generates a verifiable hash containing:
trustflow-erc8004-001)The hash is:
Mock Mode (Default): Decisions logged locally with hash verification
ETHEREUM_RPC_URL=
On-Chain Mode: Real blockchain storage
ETHEREUM_RPC_URL=https://sepolia.infura.io/v3/YOUR_PROJECT_ID
ETHEREUM_PRIVATE_KEY=your_private_key
ETHEREUM_CONTRACT_ADDRESS=deployed_contract_address
cd contracts
npm install
npx hardhat compile
npx hardhat run scripts/deploy.js --network sepolia
The Trust Ledger tab shows:
All modules write structured JSON logs to logs/<module>.log:
{"timestamp": "2026-03-22T10:00:00Z", "level": "INFO", "module": "blockchain", "message": "Decision logged: abc123 (on_chain=False)"}
To add new tools:
backend/tools/<tool>.py with a run(input) -> str interfaceagent.pyTrustFlowAgent.run() looppayment.pyMIT
Built with 🔐 TrustFlow AI · Powered by Ollama + Tavily + Streamlit + Ethereum
The living ecosystem where AI agents complete tasks through workflow loops, improve through iterative execution, are evaluated by mentor agents or humans in the loop, and turn completed work into reusable work experience and data to improve future agents.
The living ecosystem where AI agents complete tasks through workflow loops, improve through iterative execution, are evaluated by mentor agents or humans in the loop, and turn completed work into reusable work experience and data to improve future agents.
Self-healing infrastructure for AI agent payments. 90.3% auto-recovery.
The first agentic payment network: policy-controlled, gasless, and real money-ready. OmniClaw CLI + Financial Policy Engine let autonomous agents pay and earn safely at machine speed.
The A2A x402 Extension brings cryptocurrency payments to the Agent-to-Agent (A2A) protocol, enabling agents to monetize their services through on-chain payments. This extension revives the spirit of HTTP 402 "Payment Required" for the decentralized agent ecosystem.
DePIN for Vintage Hardware — Proof-of-Antiquity blockchain where old machines outmine new ones. AI-powered hardware fingerprinting, 15+ CPU architectures, Solana bridge (wRTC). $0 VC.