Quant Invests Memory and context persistence full architecture
Memory and context persistence across conversations are achieved through a multi-layered database and state architecture. The primary database layer utilizes a PostgreSQL agent_interaction_log table to save complete prompt-and-response chat histories, allowing the FastAPI gateway to reload prior turns and maintain continuity rather than acting as a one-shot interface. This is supported by the ai_knowledge_record table, which acts as the system's persistent source of truth for trained market facts. Within the multi-agent committee, state persistence is governed by a unified AgentState that carries an InvestDebateState and a RiskDebateState alongside a persistent past_context block to track cross-ticker lessons. Furthermore, an automated background scheduler triggers an AI Knowledge Refresher task daily at 01:00 AM UTC, ensuring the local LLM’s context window is continuously updated and grounded with the latest macroeconomic regimes. For terminal operations, a local .geminirc configuration file is deployed to act as "permanent memory," forcing the AI assistant to remember non-negotiable rules—like the same-sign allocation guardrail, lowercase data casing, and VRAM limits—across independent terminal sessions.
Built-in tool access enables the system to actively execute tasks rather than just generate text. We integrated targeted programmatic toolsets directly into the agent environments:
- Our Quantitative Researcher agent uses custom registered tools such as
pandas_ledger_parserandexecute_model_weight_adjustmentto autonomously read local portfolio CSV ledgers, recalculate performance ratios, and adjust alpha multipliers. - Standalone committee agents also leverage a customized
web_searchtool for real-time market intelligence gathering. - On the execution side, tool access is wired to our unified BrokerService registry, which maps trading signals to production-ready adapters for Questrade, Alpaca, and Webull.
- To maintain persistent, unattended operations 24/7/365, a background token rotation daemon uses Redis to secure and rotate Questrade OAuth tokens every 25 minutes, ensuring emergency stop-loss and rebalancing orders can be triggered without manual intervention.
System autonomy is achieved by utilizing a multi-agent orchestration framework powered by Google’s Agent Development Kit (ADK) and LangGraph. Rather than forcing the user to spell out every step, they simply provide a high-level goal (e.g., "Analyze TSLA with moderate risk and long-term horizon on Questrade"), and the AgentCoordinator layer distributes the cognitive load across specialized, collaborative personas:
- The Primary Coordinator (financial_coordinator) maps user goals, routes context, and orchestrates the workflow.
- The Data Analyst (data_analyst) autonomously retrieves SEC filings and news.
- The Trading Analyst (trading_analyst) evaluates technical setups against 5 quantitative strategies.
- The Risk Analyst (risk_analyst) acts as the gatekeeper, verifying that allocations align with strict drawdown circuit breakers and sector concentration caps.
- The Execution Analyst (execution_analyst) optimizes order routing to specific brokers.
- The Quantitative Researcher (quantitative_researcher) performs post-trade audits, executing forensic "Whipsaw Analysis" to identify stopped-out trades that prematurely reversed; if whipsaw rates exceed 20%, it autonomously triggers a "WIDEN_STOP_LOSS" event to increase the system's ATR multiplier from 2.0x to 2.50x.
To finalize a decision, the coordinator pits the aggressive, alpha-seeking "Hunter" perspectives against the defensive "Guardian" constraints, filters the debate through reinforcement learning DQN Q-values, and synthesizes the outputs into a structured "Balanced Institutional Verdict" for execution.
🎧 I could turn this architectural breakdown into an audio overview you can listen to on the go.