Build trustless AI agents with dstack, ERC-8004 compliance, and seamless deployment on Phala Cloud.
The template has been narrowed to a single opinionated workflow that mirrors how we operate the subjective oracle stack today:
- Request Scheduler (
scripts/schedule_oracle_requests.py) runs continuously, pulling BTC spot data from DiaData and callingTeeOracle.requestPriceon Base Sepolia. The cadence, lookahead, and spread are controlled through environment variables (seedocker/.env.docker.example). - Agent Service (
deployment/local_agent_server.py) boots a FastAPI server, ensures the resolver key is registered (manual mode), watchespendingRequests(), and immediately generates + analyses a settlement script for each new question, logging the code and confidence score while it waits for the grace period to expire. - AI Resolution is handled locally through Ollama (Gemma 3 4B). When the execution window opens, the pre-generated script runs to fetch DIA prices, produces structured evidence (including the analysis metadata), and submits
settlePrice. Evidence is persisted understate/evidence/and exposed via the/evidenceexplorer. - Docker Compose (
docker-compose.yml) bundles both components (agent + scheduler) so a developer can simply rundocker compose --env-file docker/.env.docker up --buildand observe the full loop end-to-end.
The sections below are being updated to match this more focused setup and to flag legacy scaffolding slated for removal.
- π Automated UMA Flow β scheduler + AI settlements run continuously on Base Sepolia.
- π§ Local AI Resolver β default Gemma3 Ollama backend, no external API dependency.
- π§Ύ Evidence Explorer β browse/download settlement artifacts via
/evidence. - π³ Docker-First Runtime β single compose file with shared named volume for agent state.
- βοΈ Configurable Runtime β
.env/docker/.env.dockercontrol RPC URLs, cadence, and AI parameters.
-
Copy the Docker env template
cp docker/.env.docker.example docker/.env.docker
Fill in the Base Sepolia RPC URL and the funded resolver private key. Optional knobs (cadence, spread, AI temperature) live in the same file.
-
Bring up the stack
docker compose --env-file docker/.env.docker up --build
This starts three services:
ollama(Gemma backend),agent(FastAPI + resolver), andscheduler(price requests). The agent and scheduler share theagent-statevolume. -
Observe the flow
docker compose logs -f agentdocker compose logs -f scheduler- http://localhost:8000/health, http://localhost:8000/evidence, http://localhost:8000/docs
-
Shut down
docker compose down docker volume rm erc-8004-oracle-agent-dstack_agent-state # optional reset rm docker/.env.docker # optional cleanup
- Seed configuration
- Run
cp docker/.env.docker.example docker/.env.docker. - Fill in
BASE_SEPOLIA_RPC_URL,RPC_URL, andRESOLVER_PRIVATE_KEYwith funded credentials. Keep this file out of git. - Optional: set
OLLAMA_BOOTSTRAP_MODELS(comma separated) to preload additional models.
- Run
- Launch the stack
- Execute
docker compose --env-file docker/.env.docker up --build. - The first boot downloads ~3.3β―GB for
gemma3:4b; expect a several-minute pull before the agent starts.
- Execute
- Confirm readiness
docker compose psshould showollama,agent, andschedulerasUp.docker compose logs -f ollamaends withReady. Serving models.; the agent log showsβ AGENT SERVER READY.- Visit http://localhost:8000/evidence to ensure the FastAPI service responds.
- Monitor activity
- Tail
docker compose logs -f schedulerforQueued questionentries anddocker compose logs -f agentforSettlement submittedlines. - Evidence artifacts appear under the
agent-statevolume (state/evidence/inside the container).
- Tail
- Clean up safely
- Use
docker compose downto stop services. - Remove
erc-8004-oracle-agent-dstack_agent-stateto reset agent state anderc-8004-oracle-agent-dstack_ollama-datato reclaim model storage.
- Use
| Component / Endpoint | Purpose | Notes |
|---|---|---|
docker/.env.docker |
Central configuration (RPC URLs, cadence, AI parameters, resolver key). | Copy from .example; never commit real secrets. |
ollama service |
Hosts the local Gemma3 model (ollama/ollama container). |
Exposes ${OLLAMA_HOST_PORT:-11434}; edit compose for GPU flags if needed. |
scripts/schedule_oracle_requests.py |
Issues requestPrice calls against TeeOracle on a schedule. |
Uses DIA BTC price feed; interval/lookahead configurable. |
FastAPI /health |
Liveness probe for the agent container. | Returns JSON heartbeat. |
FastAPI /api/status |
Displays on-chain registration & resolver status. | Useful when debugging manual CLI runs. |
FastAPI /evidence |
HTML explorer for state/evidence/ artifacts (view/download). |
Evidence includes AI script, metadata, and txHash. |
CLI python scripts/agent_cli.py run |
Manually trigger a settlement cycle (AI by default, optional override). | Reads the same environment variables as the container. |
Named volume agent-state |
Persists agent ID, evidence, debug files between restarts. | Remove via docker volume rm β¦ for a clean slate. |
erc-8004-oracle-agent-dstack/
βββ docker-compose.yml # Agent + scheduler services
βββ docker/ # Entrypoints and env templates
βββ scripts/ # CLI utilities and scheduler
βββ deployment/ # FastAPI application
βββ src/ # Core agent libraries
βββ docs/ # Runbooks and references
βββ state/ # (ignored) runtime state for local/dev runs
We target the Base Sepolia deployment published in contracts/deployments/base_sepolia_deployment.json. The scheduler and agent expect those addresses unless overridden in the environment.
The repository still contains template-era scaffolding that we intend to remove. The following tasks are queued so the agent remains lightweight:
- Drop RedPill/attestation code paths β
src/agent/ai_generator.pyand the verifier helpers (verify_ai_attestation.py) still contain unused logic. Remove once we fully commit to Ollama-only flows. - Cull unused FastAPI routes β endpoints like
/tasks,/api/metadata/update, and legacy A2A flows are dormant. Audit and remove to reduce attack surface. - Retire legacy front-end assets β the dashboards in
static/and references to/developerare stale; simplify to/healthand/evidence. - Trim documentation β files such as
DEPLOYMENT.md,agent_config.json, and VibeVM instructions describe superseded workflows. Update or archive. - Simplify TEE verifier proof mode β proof registration is still stubbed. Either implement fully or cut until we have a concrete requirement.
Please open a GitHub issue before tackling any of these so we can coordinate sequencing.
See docs/cleanup-plan.md for the detailed scope and owners.
The sections below are carried over from the broader template. Treat them as background only until the cleanup plan above retires or rewrites them.
-
DEV_GUIDE.md - Comprehensive developer guide covering:
- Local development with VibeVM
- Customizing your agent
- Testing and debugging
- Production deployment workflow
-
DEPLOYMENT.md - Production deployment checklist:
- Pre-deployment requirements
- Phala CVM configuration
- Post-deployment validation
-
QUICKSTART.md - Get started in 3 minutes
- Key Derivation - TEE derives wallet from
domain + salt - Local Development - Test in VibeVM with simulated TEE
- Funding - Add Base Sepolia ETH to derived wallet
- Registration - Register agent on-chain (0.0001 ETH fee)
- TEE Attestation - Submit cryptographic proof to verifier
- Production - Deploy to Phala CVM with real TEE attestation
- Agent Live - Accessible at
/agent.jsonendpoint
- TEE: Intel TDX via Phala CVM/dstack
- Blockchain: Base Sepolia (testnet) / Base (mainnet)
- Backend: Python 3, FastAPI
- Contracts: Solidity ^0.8.20
- Development: VibeVM for local testing
- Deployment: Docker, Phala Cloud
β
Standard /agent.json endpoint (registration-v1)
β
CAIP-10 wallet address format
β
A2A protocol endpoints
β
TEE attestation support
β
On-chain registry integration
β
Verifiable code measurement
Edit agent_config.json:
{
"name": "Your Agent Name",
"description": "What your agent does",
"endpoints": {
"a2a": {"enabled": true},
"mcp": {"enabled": false}
}
}Modify files in src/agent/:
- Add custom endpoints in
deployment/local_agent_server.py - Implement custom logic in
src/agent/base.py - Configure blockchain interactions in
src/agent/registry.py
Update entrypoint.sh for custom setup:
# Add model downloads, DB initialization, etc.
echo "π€ Downloading ML model..."
wget https://example.com/model.bin -O /app/model.binSee DEV_GUIDE.md for detailed customization instructions.
Before deploying to production:
- Test thoroughly in VibeVM
- Update
agent_config.jsonwith production values - Ensure
entrypoint.shhas all required setup steps - Commit production code to GitHub
- Note commit hash for deployment
- Set secrets on Phala:
GITHUB_REPO,GIT_COMMIT_HASH,AGENT_SALT - Configure CVM (2+ CPU, 4GB+ RAM, 10GB+ storage)
- Fund agent wallet with Base Sepolia ETH
See DEPLOYMENT.md for complete checklist.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Phala Discord: discord.gg/phala
- VibeVM Docs: github.com/Phala-Network/VibeVM
MIT
- ERC-8004 Spec: eips.ethereum.org/EIPS/eip-8004
- Phala Network: phala.network
- VibeVM: github.com/Phala-Network/VibeVM
- Base Sepolia: base.org
- Reference Implementation: dstack-erc8004-poc
Ready to build? Start with DEV_GUIDE.md or jump into QUICKSTART.md π