This agent uses a knowledge graph and external data sources to provide informed answers about companies, their competitors, and their products.

How it Works

The agent is built using the following components, which you can find in the cookbook/stock_analysis directory:

`infoagent.py`

The main script that creates and runs the agent. It initializes the a1facts tool, which acts as the bridge between the agent and the knowledge graph.

`company.yaml`

This file defines the schema of our knowledge graph. It specifies the types of entities (e.g., Company, Product_Service) and the relationships between them (e.g., competes_with).

`sources.yaml`

This file configures the external data sources. In this case, it’s set up to use the Financial Modeling Prep (FMP) API and yfinance.

`fmp_functions.py` & `yfinance_functions.py`

These files contain the Python functions that interact with the FMP and yfinance APIs to fetch data.
When you run infoagent.py, it initializes an agent with the a1facts tool. The agent is then asked a question: "what do you know about how UnitedHealth competes with CVS?". The a1facts tool uses the information from company.yaml and sources.yaml to understand the query, fetch relevant data from the external APIs, and then provide a precise answer.

Running the Example

1

Set up your environment

Create a .env file in the a1facts/cookbook/stock_analysis directory and add your API keys:
.env
OPENAI_API_KEY="your_openai_api_key"
EXA_API_KEY="your_exa_api_key"
FMP_API_KEY="your_fmp_api_key"
You will need to sign up for a free API key from Financial Modeling Prep to run this example.
2

Run the agent

Navigate to the a1facts/cookbook/stock_analysis directory and run the following command:
uv run python infoagent.py
3

Expected Output

The agent will run the query and print the answer to the console. The output will be a detailed explanation of how UnitedHealth competes with CVS, based on the data retrieved from the knowledge graph and external sources.