Skip to main content
This comprehensive guide shows you how to build an AI agent that can execute custom Python functions using the OpenAI Responses API.

Prerequisites

  • cycls installed
  • OpenAI API key

Step 1: Define a Tool

Create a standard Python function. In this example, we’ll create a mock weather function.

Step 2: Define the Schema

OpenAI needs to know what your tool does. You define this in a JSON schema format.
Note: The description fields are crucial—they tell the LLM when to use your tool.

Step 3: Create the Agent

Step 4: Set Up Environment

Create a .env file with your OpenAI API key:

Step 5: Run the Agent

Full Code

Here is the complete app.py: