Show Alpaca: Infinite Bagholder, An Open-Source Pluggable Agentic AI Harness for LLM-Powered Trading

Hey Alpaca Community!

I wanted to share a new open-source project I’ve been working on called Infinite Bagholder.

It is an autonomous, pluggable development framework and agentic AI harness designed specifically for LLM-powered stock trading. It integrates out of the box with the Alpaca API (supporting both paper and live trading), features a real-time web dashboard, and runs background agent and news loops.


:light_bulb: Why Build This?

Whenever developers want to experiment with Large Language Models (LLMs) for automated trading, they hit a wall of engineering overhead:

  1. Writing reliable database adapters and state management.
  2. Managing prompt context limits and compounding message structures.
  3. Implementing custom polling intervals and event-driven loops.
  4. Setting up visual telemetry/dashboards to monitor what the LLM is actually doing in real time.

Infinite Bagholder provides this production-ready architecture out of the box, allowing you to focus entirely on designing, backtesting, and refining your trading strategies in pure Markdown.


:building_construction: Technical Architecture

The framework is built around a decoupled, event-logged pattern using FastAPI, SQLite (WAL mode), and a modular background worker architecture:

  • Background Agent Worker Loop: Constructs system prompts injecting account balances, open positions, and active strategy guidelines. It handles tool execution and validates LLM commands against safety rules.
  • Background News Worker Loop: A dedicated loop running pluggable catalysts feeds (e.g., SEC EDGAR filings, Alpaca News API, Reddit WSB sentiment feeds).
  • Technical Indicator Engine: Exposes built-in calculations for Relative Volume (RVOL), Moving Averages (SMAs), Volume Z-Scores, and trade signals directly to your agent. No need to implement these indicators inside the LLM prompt.
  • Unified LLM Adapter Layer: Supports standard cloud APIs (OpenAI, Anthropic, Gemini, OpenRouter) and local models (Ollama, Llama.cpp) with token cost logging and automatic latency fallbacks.
  • Web UI Cockpit: A sleek, interactive dashboard to inspect agent thoughts, track token telemetry, review transaction logs, and visualize performance metrics.

:electric_plug: Extensibility (Write Your Own Plugins)

We designed the framework to be modular. You can extend it without modifying core files using abstract base classes:

  • Pluggable News Sources: Build scrapers for custom SEC filers or social media signals.
  • Pluggable Brokerage Connectors: Swap or parallel-run connections outside Alpaca (e.g., a local simulated mock broker).
  • Pluggable Agent Tools: Register custom Python capabilities/functions for the LLM to call.
  • Pluggable UI Dashboard Widgets: Create sandboxed <iframe> widgets to inject custom analytics directly into the main cockpit.

:shield: Safety & Capital Protection First

LLMs can hallucinate, experience API delays, or fail to parse. Infinite Bagholder implements safety boundaries:

  • Programmatic Safety Guardrails: Hardcoded Python safety checks (like penny stock blocks, stop-loss triggers, and max portfolio allocation caps) execute locally. We do not trust the LLMs to enforce these bounds through prompting alone.
  • Mock and Paper Brokerage Modes: Testing is safe. You can run strategies against a local mock simulator or Alpaca’s Paper Trading environment before risking live capital.

:speech_balloon: We’d Love Your Feedback!

This project is licensed under the GNU AGPLv3 and is fully open source.

We would love to hear what the Alpaca community thinks, see what plugins or news sources you build, and collaborate on making LLM-based agentic trading more robust and safe. Check out the repo, try it in paper trading, and let us know your thoughts!