BeliefCraft is a research-oriented toolkit that uses retrieval-augmented generation as a knowledge model to improve belief/state estimation and decision making in partially observable environments. It combines document retrieval with provenance-aware passages, particle-based or learned belief updates, and policy learners (actor-critic / PPO) so agents can make more informed, auditable decisions. The project delivers an end-to-end pipeline: ingest and index domain texts, expose a RAG API, augment agent beliefs at runtime, and evaluate decision performance in controlled simulations.
Architecture
graph TD
UI[UI] --> ENV[Environment API]
UI --> RAG[RAG Service]
AGENT[Agent Service] --> ENV
AGENT --> RAG
subgraph Services
UI
ENV
RAG
AGENT
end
subgraph Shared Packages
COMMON[packages/common]
DB[packages/database]
end
ENV --> COMMON
RAG --> COMMON
AGENT --> COMMON
ENV --> DB
RAG --> DB
AGENT --> DB
Repo Layout
services/: deployable services (isolated dependencies per service)services/environment-api/: FastAPI service for environmentsservices/rag-service/: FastAPI service for retrievalservices/agent-service/: FastAPI service for agentsservices/ui/: Next.js UI shellpackages/common/: shared schemas and utilitiespackages/database/: shared database models and connection helpersinfrastructure/: Docker and scriptsdocs/: design docsdocs/configuration-workflow.md: YAML config loading, validation, and env placeholder expansion
tests/: test suites
Quick Start
- Copy env templates:
cp .env.example .envcp services/environment-api/.env.example services/environment-api/.envcp services/rag-service/.env.example services/rag-service/.envcp services/agent-service/.env.example services/agent-service/.envcp services/ui/.env.example services/ui/.env
- Install local dependencies for all services with
make setup. - Start development mode with hot reload using
make dev. - Verify stack health with
powershell -ExecutionPolicy Bypass -File infrastructure/scripts/health/check-services.ps1.
Service health endpoints (host ports):
- Environment API:
http://localhost:8000/health - RAG Service:
http://localhost:8001/health - Agent Service:
http://localhost:8003/health - UI:
http://localhost:3000/health
Make Commands
make setup- install all Python and UI dependenciesmake dev- run full Docker Compose stack in development modemake test- run test suitemake lint- run lintersmake format- auto-format codemake lint-format- run formatter and linters in one commandmake clean- remove containers, networks, and volumes
Database Startup Flow
- PostgreSQL starts with initialization script at
infrastructure/scripts/postgres/init-databases.sh. - Databases are created automatically (
environment_api,rag_service). - Migration container
db-migrateapplies SQL files frominfrastructure/scripts/postgres/migrationsbefore API services start.
Troubleshooting
- Common issues and fixes are documented in
docs/troubleshooting.md.
Development Notes
- Python services use
uvfor dependency management withpyproject.toml. - Each service keeps its own
pyproject.tomlorpackage.jsonfor isolated dependencies. - Docker Compose runs everything from the repo root via
docker-compose.yml.
LangSmith Tracing
LangSmith enables trace inspection, cost monitoring, and evaluation for all LLM calls in the agent-service.
To enable it locally, add these variables to services/agent-service/.env:
LANGCHAIN_TRACING_V2=true
LANGCHAIN_API_KEY=ls__your_api_key_here
LANGCHAIN_PROJECT=beliefcraft-devGet your API key at https://smith.langchain.com/. See agent-service README for full setup instructions.