Agents for OpenBB

repository·main·Indexed 43 days ago

https://github.com/openbb-finance/agents-for-openbb

Examples and guidance for building custom AI agents that integrate with the OpenBB Workspace using the OpenBB AI SDK. Includes implementations for a Financial Prompt Optimizer and various Vanilla Agents supporting raw widget data, reasoning steps, citations, charts, tables, and PDF data processing.

Tokens
24K
Snippets
74
Records
96
Agent score
56%

What's inside Agents for OpenBB

  1. Integrate custom agents into the OpenBB Workspace

    main

    This repository serves as an example collection for building and integrating custom agents into the OpenBB Workspace. To build compatible agents, you should use the OpenBB AI SDK.

    For production-oriented agents, the project recommends referencing Agent Rita, which is implemented in TypeScript using Bun.

  2. How the Vanilla Agent Dashboard Widgets agent works

    main

    This agent is designed for widget discovery and listing within the OpenBB Workspace. It does not fetch actual widget data; instead, it focuses on exposing the metadata and parameters of available widgets.

    Key Capabilities:

    • Metadata Exposure: It exposes agents.json with widget-dashboard-search enabled. This allows the Workspace to send dashboard widget metadata to the agent (e.g., via widgets.secondary).
    • Widget Listing: It lists widgets from both explicit context (primary) and dashboard context (secondary).
    • Detailed Information: For each widget, it provides:
      • Metadata: name, description, ID, category, and UUID.
      • Parameters: A structured table containing type, default, current values, options, and descriptions.
    • Organization: It organizes dashboard widgets into tabs to improve visibility.
  3. How the Vanilla Agent Feedback agent works

    main

    The Vanilla Agent Feedback agent is designed to demonstrate how an agent can receive and persist user feedback (thumbs up/down) sent from the OpenBB Workspace frontend.

    To enable feedback support, the agent must declare "feedback": true within its agents.json features. This tells the OpenBB Workspace that the agent is capable of handling feedback directly, preventing the feedback from being routed solely to general analytics. When a user rates an AI response, the Workspace calls the agent's /v1/feedback endpoint, and this specific implementation persists that data to a local feedback.json file.

  4. Understand the structured MCP response format

    main

    To help users distinguish between raw data and AI interpretation, the agent uses a specific structured response format when MCP tools are used:

    ## MCP OUTPUT
    [Raw data from MCP tool execution]
    
    ## AI OUTPUT
    [AI analysis and interpretation of the tool results]

    This separation ensures that the actual tool data is clearly isolated from the AI's generated insights.

  5. How dynamic skill loading works in a Vanilla Agent

    main

    The Vanilla Agent with Dynamic Skill Loading implements a two-step handshake to load specialized capabilities (skills) on demand. This prevents the model from being overwhelmed by a massive toolset by only providing a lightweight catalog initially.

    The Handshake Process:

    1. Catalog Phase: The model is presented with a skills_catalog containing lightweight metadata.
    2. Request Phase: When the model identifies a need for a specific skill, it calls the get_skill_content function.
    3. Loading Phase: The client (frontend) intercepts this request, fetches the full skill content, and sends it back to the agent as a tool result.
    4. Execution Phase: The agent uses the newly provided instructions/content to answer the user's request.

    Note: This specific implementation is designed for a single skill per request flow. If multiple skills are provided in selected_skills, only the first one is utilized.

  6. How MCP tool integration works in the agent

    main

    The agent integrates Model Context Protocol (MCP) tools through a multi-step orchestration process that allows the AI to interact with external data sources:

    1. Tool Discovery: The agent detects available MCP tools from connected servers via request.tools.
    2. Schema Parsing: It reads tool input schemas to understand required parameters.
    3. Function Definition: It converts these schemas into OpenAI function definitions.
    4. Execution Flow:
      • The user requests an action.
      • The agent calls the appropriate MCP tool with parameters.
      • The frontend executes the tool on the MCP server.
      • Results are returned to the agent.
    5. Response Generation: The AI analyzes the tool output to provide insights.

    Configuration

    • Feature Flag: Enable MCP tool support by setting "mcp-tools": true in the agent configuration.
    • Automatic Detection: Tools are discovered automatically from the request.tools object.
  7. How custom features are detected in the agent

    main

    This agent demonstrates how to interface with the OpenBB Workspace UI by reading configuration values from workspace_options. It reports the status of specific custom features that users can toggle or modify within the UI.

    The agent tracks the following four custom features:

    • Deep Research: A boolean feature for deep research capabilities (defaults to disabled).
    • Web Search: A boolean feature for web search capabilities (defaults to enabled).
    • Model: A selection option that determines the model value sent to the agent.
    • Agent Name: A text option that sets the display name used in the agent's responses.
  8. Install and run the Vanilla Agent with Tables example

    main

    This example agent uses OpenAI to perform question answering and returns tables that are rendered by the OpenBB Workspace.

    Prerequisites

    • poetry installed for dependency management.
    • An OPENAI_API_KEY.

    Setup Steps

    1. Clone the repository.
    2. Set your OpenAI API key in your shell configuration (.zshrc or .bashrc):
      export OPENAI_API_KEY=<your-api-key>
    3. Install dependencies using poetry:
      poetry install --no-root
    4. Start the FastAPI server:
      cd 34-vanilla-agent-tables
      poetry run uvicorn vanilla_agent_tables.main:app --port 7777 --reload

    The server will be accessible at http://localhost:7777.

    # Install dependencies
    poetry install --no-root
    
    # Start the API server
    cd 34-vanilla-agent-tables
    poetry run uvicorn vanilla_agent_tables.main:app --port 7777 --reload
  9. Setup the Portfolio Commentary Agent

    main

    The Portfolio Commentary Agent is an AI-powered agent for OpenBB Workspace that analyzes portfolio performance, allocation, and risk metrics using dashboard widget data.

    Prerequisites

    • Python 3.10 or higher
    • Poetry or pip
    • Docker (optional)
    • OpenRouter API key

    Environment Configuration

    Create a .env file in the project root with the following variables:

    OPENROUTER_API_KEY=your_openrouter_api_key_here
    OPENROUTER_MODEL=deepseek/deepseek-chat-v3-0324
    OPENROUTER_MODEL_PERPLEXITY=perplexity/sonar
    cd 99-advanced-examples/portfolio-commentary-with-search-feature