How it Works
The agent is built using the following components, which you can find in thecookbook/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.
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
2
Run the agent
Navigate to the
a1facts/cookbook/stock_analysis directory and run the following command: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.