This file provides guidance to AI coding agents when working with code in this repository.
This file is symlinked to CLAUDE.md, GEMINI.md and .cursorrules to be automatically read by AI coding assistants.
The Allocator Bot is a portfolio optimization copilot for OpenBB Workspace that provides AI-powered asset allocation recommendations using modern portfolio theory and efficient frontier algorithms.
Development installation
uv sync --extra devProduction installation
pip install git+https://github.com/piiq/allocator-bot.gitopenbb-api --app allocator_bot.__main__:get_app --factoryRun tests
uv run pytestCode formatting
uv run ruff format .Linting
uv run ruff check .Type checking
uv run ty check .- Always use UV commands - never edit pyproject.toml directly
- Add dependencies:
uv add package-name - Add dev dependencies:
uv add --group dev package-name - Sync dependencies:
uv sync --extra dev
User Request → FastAPI Endpoint (/v1/query) → Agent Execution Loop → Portfolio Optimization → SSE Stream Response
- Web Framework: FastAPI with Server-Sent Events (SSE)
- AI/LLM: Magentic library with OpenRouter integration (DeepSeek Chat v3)
- Portfolio Optimization: PyPortfolioOpt for efficient frontier calculations
- Data Source: OpenBB Platform for financial market data
- Package Management: UV for fast Python dependency management
- Copilot interface at
/v1/queryendpoint - Widget interface at
/widgets.jsonprogrammatically generated byopenbb-apilauncher - Widget configuration embedded in OpenAPI specifications via
openapi_extra - Bearer token authentication pattern
- Hybrid approach: Local file storage with optional S3 cloud storage
- Environment-driven: S3 enabled via
S3_ENABLEDenvironment variable - Graceful fallback: Falls back to local storage when S3 unavailable
- Full async/await pattern for all LLM interactions
- Server-Sent Events for real-time user feedback
- Streaming responses with progress indicators
- Strict Pydantic models for all data structures
- Field-level validation with custom validators
- Type safety throughout the application
- Multi-step LLM workflow: task detection → structure parsing → execution
- Function-free approach with explicit logic exposure to LLM
- Retry mechanisms for LLM reliability
OPENROUTER_API_KEY: LLM access via OpenRouterFMP_API_KEY: Financial data via Financial Modeling PrepS3_*: Cloud storage configuration (if S3_ENABLED=true)AGENT_HOST_URL: Application host URLAPP_API_KEY: API access tokenAGENT_MODEL: The model slug used by the agent (optional, defaults toqwen/qwen3.5-397b-a17b)
DATA_FOLDER_PATH: Local storage path (default: "data")
- Multi-stage Dockerfile using UV for optimized builds
- Runs on port 4299
- Non-root user for security
- Complete manifests in
/k8s/directory - Separate ConfigMap for non-sensitive variables
- Secret template for sensitive environment variables
- Unit tests for core portfolio functions
- Mocking for external dependencies (OpenBB, S3)
- Integration tests for storage systems
- Located in
/tests/with pytest framework