Easily Build Autonomous AI Agents with GPT-4o

In this blog post, discover how to easily build powerful autonomous AI agents with GPT-4 using the Fi-data framework. Learn to create advanced agents with long-term memory, contextual knowledge, and the ability to take actions through function calling. Optimize your AI systems for efficiency and productivity.

February 22, 2025

party-gif

Discover the power of building autonomous AI agents with GPT-4o! This blog post will guide you through the process of easily creating intelligent assistants that can tackle a wide range of tasks, from web searches to financial analysis and data exploration. Unlock the potential of cutting-edge language models and unlock new possibilities for your projects.

How to Build Autonomous AI Agents with GPT-4

In this section, we will explore how to build intricate autonomous AI systems that have long-term memory, contextual knowledge, and the ability to take actions from function calling. We will use the Fi-data framework, which provides a powerful way to create autonomous AI assistance with function calling.

First, we will create a basic assistant without any tools. This assistant will use the GPT-4 model, which is one of the best models in the market right now. We can then add additional functionality to the assistant, such as the ability to search the web using the Duco tool.

Next, we will build a finance assistant that can access various tools like Yahoo Finance to get stock prices, recommendations, company information, and news. We will then demonstrate how to build your own custom tools, using the Hacker News API as an example.

Finally, we will explore more complex assistants, such as a data analysis assistant that can use DuckDB to analyze data in CSV and Parquet files, and a research assistant that can use Exa to search the web and generate a report in a specified format.

Throughout the process, we will emphasize the importance of conciseness and focus, ensuring that the content is easy to understand and implement. The code for these examples can be found in the Fi-data repository, and the steps to set up the environment are provided in the README.

Building a Basic Assistant

To build a basic assistant, we first need to import the necessary components from the fidata library. We'll be using the LLMAssistant class to create our assistant.

from fidata.assistants.llm_assistant import LLMAssistant
from fidata.llms.openai import OpenAIChat

Next, we'll create an instance of the LLMAssistant class, passing in the OpenAI GPT-4 language model as the llm parameter.

assistant = LLMAssistant(llm=OpenAIChat(model_name="gpt-4"))

Now, we can define the description and instructions for our assistant. These will be used to set the system prompt for the language model.

description = "You are a helpful assistant tasked with providing a simple breakfast recipe."
instructions = "Provide a concise breakfast recipe."

Finally, we can call the run method of the assistant object, passing in the description and instructions. This will execute the assistant and return the response.

response = assistant.run(description=description, instructions=instructions)
print(response)

This will output a simple breakfast recipe generated by the GPT-4 language model.

Adding Web Search Functionality

To add web search functionality to our AI assistant, we will import the Duco tool from the f_tools module. This tool allows the assistant to search the web and retrieve relevant information.

First, we add the Duco tool to our assistant:

from f_tools.duco import Duco
assistant.add_tool(Duco())

Next, we set the show_tool_calls parameter to True so that we can see the tool calls happening behind the scenes.

We then give the assistant a task to search for news from France and write a short poem about it:

assistant.run_task("Search for the news from France and write a short poem about it.")

As you can see, the assistant uses the Duco tool to retrieve the news from France, and then generates a short poem based on the information it has gathered. This demonstrates how the assistant can leverage web search capabilities to gather information and use it to complete tasks.

Creating a Finance Assistant

To create a finance assistant, we'll be using the Yahoo Finance tool from the F-tools library. This tool provides access to various financial data and functions, such as getting stock prices, company information, recommendations, and news.

First, we'll import the necessary tools:

from f_tools.yahoo_finance import YahooFinance

Next, we'll create the finance assistant and add the desired tools to it:

finance_assistant = Assistant(model=gpt4, name="Finance Assistant")
finance_assistant.add_tool(YahooFinance(
    get_stock_price=True,
    get_recommendations=True,
    get_company_info=True,
    get_company_news=True
))

In this example, we're enabling the get_stock_price, get_recommendations, get_company_info, and get_company_news functions from the Yahoo Finance tool.

Now, we can give the assistant tasks to perform, such as getting the stock price of a company and writing a comparison between two companies:

finance_assistant.run_task("What is the stock price of Nvidia?")
finance_assistant.run_task("Write a comparison between Nvidia and AMD using all the available tools.")

The assistant will use the provided tools to gather the necessary information and generate a comprehensive response, which will be returned in Markdown format for better readability.

This finance assistant can be further customized by adding more tools, adjusting the tool configurations, or modifying the task instructions to suit your specific needs.

Building Custom Tools

One of the key features of the Fi data framework is the ability to build custom tools that can be integrated into your AI agents. This allows you to extend the capabilities of your agents beyond the default tools provided, and tailor them to your specific needs.

In the video, the creator demonstrates how to build a custom tool to access the Hacker News API. Here's how it's done:

  1. Describe the function that will be used to interact with the API, including the arguments and return values.
  2. Add the function to the Fi data assistant, providing the description and specifying the input/output parameters.
  3. Use the custom tool in the assistant's tasks, just like the default tools.

The video also shows how to enable debug mode, which provides detailed logs of the assistant's internal processes. This can be very helpful when troubleshooting or understanding how the custom tool is being used.

Overall, the ability to build custom tools is a powerful feature of the Fi data framework, allowing you to create highly specialized and autonomous AI agents tailored to your specific needs.

Analyzing Data with DuckDB

This section showcases how the assistant can leverage the DuckDB tool to analyze data in CSV and Parquet files. The assistant demonstrates the following capabilities:

  1. Automatically loads the data into tables when the tables don't exist.
  2. Runs SQL queries to get the average movie rating and generates a histogram of the ratings.
  3. Chooses an appropriate bucket size for the histogram based on the data.
  4. Displays the SQL queries and the resulting visualizations in a clear and concise manner.

The assistant's ability to seamlessly integrate DuckDB and present the analysis results is a testament to the power of the framework being demonstrated. This section highlights how the assistant can be empowered with data analysis capabilities to tackle a wide range of tasks.

Generating a Research Report

The assistant is tasked with writing a research report on the topic of OpenGPT-4. It follows these steps:

  1. Searches the web using the Exa tool to find the top 10 relevant links about OpenGPT-4.
  2. Carefully reads through the search results.
  3. Prepares a well-formatted article in the requested structure:
    • Rough outline
    • Detailed report covering the key points about OpenGPT-4
  4. Saves the final report in a Markdown file named "news_article.md".

The assistant demonstrates its ability to:

  • Conduct web research and gather relevant information
  • Synthesize the findings into a structured, well-written report
  • Format the report in Markdown for easy readability
  • Save the output to a file as requested

This showcases the assistant's research capabilities, natural language processing skills, and ability to follow instructions to produce a high-quality deliverable.

FAQ