LangAlpha Documentation

repository·main·Indexed 23 days ago

https://github.com/ginlix-ai/langalpha

An AI agent harness for financial market interpretation and investment decision support. LangAlpha utilizes persistent workspaces and Programmatic Tool Calling (PTC) to enable iterative research through Python code execution and MCP servers. It includes a core library (langalpha-core v0.1.0), a comprehensive REST API for managing threads, workspaces, and market data, and a PTC CLI for interactive agent sessions with sandbox integration.

Tokens
158.6K
Snippets
247
Records
559
Agent score
81%

What's inside LangAlpha

  1. Overview of LangAlpha Web features

    main

    LangAlpha Web provides a comprehensive interface for interacting with AI-powered financial research and trading agents. Key capabilities include:

    • Real-time Agent Interaction: SSE streaming chat with subagent task cards, tool call displays, and reasoning blocks.
    • Human-in-the-loop (HITL): Ability to review and approve/reject agent plans before execution.
    • Configurable Dashboard: A drag-and-drop workspace with 30+ widgets (watchlist, portfolio, news, TradingView heatmaps, etc.) using @dnd-kit.
    • Financial Charting: Interactive candlestick charts (TradingView-style) with an integrated AI chat sidebar for analysis.
    • Automations: Management of recurring agent tasks via cron scheduling.
    • Research & Artifacts: Inline rendering of PDFs, Excel, CSV, and HTML; a Memo Library for uploading research notes; and a Monaco Code Editor for code artifacts.
    • Data Layer: Powered by @tanstack/react-query with a hierarchical cache key factory and prefix-based invalidation.
  2. Overview of the User Profile Skill

    main

    The user-profile skill provides three unified tools for managing user-specific data, including profiles, preferences, watchlists, and portfolios.

    Important: You should call these tools directly instead of using the ExecuteCode tool.

    Available Tools:

    • get_user_data: Read user data.
    • update_user_data: Create or update user data (uses upsert semantics).
    • remove_user_data: Delete user data.
  3. Overview of the dcf-model skill

    main
    The dcf-model skill is designed to create institutional-quality Discounted Cash Flow (DCF) models for equity valuation, adhering to investment banking standards. The output is a detailed Excel model that includes free cash flow projections, WACC (Weighted Average Cost of Capital) calculations, terminal value, and sensitivity analysis.
  4. What is LangAlpha and its core philosophy

    main

    LangAlpha is an agent harness designed for 'vibe investing'. Unlike traditional AI financial tools that treat investment as one-off Q&A sessions, LangAlpha treats investment as a continuous process of updating hypotheses based on new data.

    It implements a Workspace Architecture inspired by software engineering: instead of a single prompt, agents operate within a persistent workspace. This allows research to accumulate over time, where every session builds upon previous files, threads, and research artifacts, similar to how a codebase evolves with commits.

  5. Overview of LangAlpha

    main

    LangAlpha is an agent harness designed for financial market understanding and investment decision support. It moves beyond single-turn AI interactions by providing agents with a persistent workspace, allowing research to accumulate over time much like a codebase.

    Key characteristics include:

    • Vibe Investing: Instead of one-off prompts, agents maintain a continuous context of research, files, and threads within specific workspaces (e.g., "Q2 Rebalancing" or "Energy Sector Rotation").
    • Programmatic Tool Calling (PTC): Agents process financial data by writing and executing Python code rather than just streaming raw data into the context window, which reduces token consumption and enables complex multi-step analysis.
    • Multi-Layered Data Ecosystem: Uses a combination of native tools for quick reference and MCP (Model Context Protocol) servers for heavy data processing, charting, and multi-year analysis within a sandbox.
    • Agent Swarm & Live Steering: Supports parallel asynchronous subagents with separate context windows and allows users to provide real-time direction (live steering) to agents while they are working.
  6. UI Component Patterns for Financial Dashboards

    main

    LangAlpha provides reusable CSS and component patterns specifically designed for building financial dashboards. These patterns are categorized into two tiers:

    1. Simple Tier: Uses vanilla HTML, CSS, and JavaScript for lightweight integration.
    2. Complex Tier: Uses React and Tailwind CSS for more robust, scalable dashboard applications.

    These patterns include base themes, KPI cards, responsive grids, financial tables, and more.

  7. Core features of LangAlpha

    main

    LangAlpha provides several advanced capabilities for financial research and automated investing:

    • Programmatic Tool Calling (PTC): Agents write and execute Python code to process financial data from MCP servers, enabling complex multi-step analysis while minimizing token usage.
    • Progressive Tool Discovery: MCP tools are provided to the agent as summaries; full documentation is stored in the workspace and accessed only when needed. JSON tools can be bound to specific Skills and only exposed when the skill is active.
    • Persistent Workspace: Each workspace includes a dedicated sandbox, a structured directory, and an agent.md note file to accumulate research across sessions. It also utilizes long-term memory storage (.agents/user/memory/, .agents/workspace/memory/) and user-managed memo storage (.agents/user/memo/) for PDFs and markdown notes.
    • Financial Research Skills: Pre-built workflows (e.g., DCF models, earnings analysis, morning reports) that can be triggered via slash commands or auto-activated.
    • Agent Clusters & Real-time Steering: Supports parallel asynchronous subagents with isolated contexts. Users can perform real-time steering by sending messages to correct or redirect an agent while it is running.
    • Automations: Supports scheduled tasks and price-triggered automations (e.g., executing a task when a stock hits a specific price).
    • Secretary (Flash Agent): A specialized agent for managing workspaces, dispatching deep PTC analysis, and tracking tasks via conversational commands with human-in-the-loop approval.
    • Security: Uses pgcrypto for static encryption, automatically detects/desensitizes credential leaks, and executes code in isolated sandboxes with independent secret storage.
  8. Use the XLSX skill for spreadsheet tasks

    main

    The xlsx skill is used whenever a spreadsheet file (.xlsx, .xlsm, .csv, or .tsv) is the primary input or output. Use this skill to:

    • Open, read, edit, or fix existing spreadsheet files.
    • Create new spreadsheets from scratch or from other data sources.
    • Convert between tabular file formats.
    • Clean or restructure messy tabular data (malformed rows, misplaced headers, etc.).
    • Perform data analysis, formatting, charting, or formula computation.

    Note: Do NOT use this skill if the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration.

  9. Adopt the Research Desk design tone

    main

    When producing visual output for financial research, aim for a 'Research Desk' aesthetic rather than a 'Marketing Page' look. The goal is to create dense, scannable, and credible information design suitable for portfolio managers and analysts.

    Key Principles:

    • Information Density: Prioritize high signal-per-screen ratio over excessive whitespace.
    • Restraint: Avoid hero gradients, oversized rounded cards, or decorative elements. Use hairline borders (rules) instead of heavy shadows or boxes.
    • Data-Centricity: Numbers, tables, and charts should be the protagonists of the layout.
    • Credibility: Ensure all sources are cited, dates are stamped, and units are clearly labeled.
  10. Use Plan Mode for Controlled Execution

    main

    Plan mode allows you to review the agent's intended actions before they are executed.

    • Activation: Enable via the --plan-mode flag at startup or by pressing Shift+Tab during a session.
    • Workflow: The agent submits a plan displayed in a panel. You can navigate with arrow keys to Accept or Reject the plan. If you reject, you can provide feedback to guide the agent.
  11. Best practices for openpyxl and pandas

    main

    openpyxl Best Practices

    • Cell Indexing: Indices are 1-based (row=1, column=1 is A1).
    • Reading Values: Use load_workbook('file.xlsx', data_only=True) to read calculated values. Warning: If you save a workbook opened with data_only=True, formulas will be permanently replaced by their values.
    • Performance: Use read_only=True for reading large files or write_only=True for writing large files.
    • Formulas: Formulas are preserved but not evaluated; use scripts/recalc.py to update values.

    pandas Best Practices

    • Data Types: Specify types to avoid inference issues: pd.read_excel('file.xlsx', dtype={'id': str}).
    • Memory Efficiency: For large files, read specific columns: pd.read_excel('file.xlsx', usecols=['A', 'C', 'E']).
    • Dates: Handle dates properly: pd.read_excel('file.xlsx', parse_dates=['date_column']).
  12. Calculate WACC using CAPM

    main

    The Weighted Average Cost of Capital (WACC) is calculated by combining the cost of equity and the after-tax cost of debt based on their market value weights.

    1. Cost of Equity (CAPM)

    Cost of Equity = Risk-Free Rate + Beta * Equity Risk Premium

    • Risk-Free Rate: Use the current 10-Year Treasury Yield.
    • Beta: 5-year monthly stock beta.
    • Equity Risk Premium: Typically 5.0-6.0%.

    2. After-Tax Cost of Debt

    After-Tax Cost of Debt = Pre-Tax Cost of Debt * (1 - Tax Rate)

    3. Capital Structure Weights

    • Market Value Equity: Current Stock Price * Shares Outstanding
    • Net Debt: Total Debt - Cash & Equivalents
    • Enterprise Value: Market Cap + Net Debt
    • Equity Weight: Market Cap / Enterprise Value
    • Debt Weight: Net Debt / Enterprise Value

    Final Formula: WACC = (Cost of Equity * Equity Weight) + (After-Tax Cost of Debt * Debt Weight)

    Note: If the company has a Net Cash position (Cash > Debt), Net Debt is negative, and the Debt Weight may be negative.

    Cost of Equity = Risk-Free Rate + Beta × Equity Risk Premium
    
    After-Tax Cost of Debt = Pre-Tax Cost of Debt × (1 - Tax Rate)
    
    Equity Weight = Market Cap / Enterprise Value
    Debt Weight = Net Debt / Enterprise Value
    
    WACC = (Cost of Equity × Equity Weight) + (After-Tax Cost of Debt × Debt Weight)