OpenBB LLM Agents

repository·main·Indexed 23 days ago

https://github.com/openbb-finance/experimental-openbb-platform-agent

A framework for creating autonomous financial analyst agents using Large Language Models and the OpenBB Platform. It provides synchronous and asynchronous functions (`openbb_agent` and `aopenbb_agent`) to perform complex financial research and temporal queries using real-time data. The library supports tool restriction, custom Python tool integration, and automated tool discovery via FAISS vector indexing of OpenBB functions.

Tokens
3.3K
Snippets
9
Records
30
Agent score
80%

What's inside openbb-agents

  1. Develop and lint openbb-agents

    main

    To develop the project, use poetry for environment management and ruff for linting and formatting.

    Setup Development Environment:

    poetry install

    Linting and Formatting with ruff:

    • Run checks: ruff check
    • Fix errors: ruff check --fix
    • Format code: ruff format
    • Install pre-commit hooks: pre-commit install

    Testing: Run tests using pytest:

    pytest -n 8 tests/
  2. Set up OpenBB Agents with API keys

    main

    To use openbb-agents, you need to provide credentials for the OpenBB Platform data providers. You can fetch these using an OPENBB_PAT (Personal Access Token) from your environment variables, or set up API keys locally. If you rely only on yfinance, some functions may be unavailable.

    import os
    OPENBB_PAT = os.environ.get('OPENBB_PAT')
    import os
    OPENBB_PAT = os.environ.get('OPENBB_PAT')
  3. Configure OpenBB credentials for the agent

    main

    The agent can access OpenBB data through two methods:

    1. OpenBB Hub (via PAT): Pass the openbb_pat argument to the agent function. This is the recommended way to manage credentials remotely.
    2. Local Credentials: If openbb_pat is not provided, the agent will attempt to use credentials already configured in your local OpenBB environment.

    When a openbb_pat is provided, the agent internally calls obb.account.login(pat=openbb_pat) to authenticate.

  4. Configure logging with configure_logging()

    main

    The configure_logging(verbose: bool) function sets up the global logging configuration for the openbb_agents package.

    When verbose=True:

    • openbb_agents.agent, openbb_agents.utils, openbb_agents.tools, and openbb_agents.chains log at the INFO level.
    • The root logger logs at the WARNING level.

    When verbose=False:

    • All specified loggers and the root logger log at the CRITICAL level.

    Logs are directed to sys.stdout using a standard formatter: %(asctime)s - %(levelname)s - %(name)s - %(message)s.

  5. Use the asynchronous agent with aopenbb_agent

    main

    For asynchronous workflows, use aopenbb_agent. This can improve performance in certain scenarios by allowing the agent to run within an async event loop.

    from openbb_agents.agent import aopenbb_agent
    
    await aopenbb_agent("What is the stock price of AAPL and MSFT?")
    from openbb_agents.agent import aopenbb_agent
    
    await aopenbb_agent("What is the stock price of AAPL and MSFT?")
  6. Use aopenbb_agent to answer queries asynchronously

    main

    The aopenbb_agent function is the asynchronous variant of openbb_agent. It is designed for use in asyncio environments, allowing for concurrent processing of subquestions to improve performance.

    Parameters

    • query (str): The question to be answered.
    • openbb_tools (list[str] | None): A list of specific OpenBB function names to restrict the agent's toolset.
    • openbb_pat (str | None): The OpenBB PAT for retrieving credentials from the OpenBB Hub.
    • extra_tools (list[Callable] | None): A list of additional Python functions to add to the agent's tool index.
    • verbose (bool): Whether to print additional information about the agent's behavior.