OpenAI Agent Integration
Follow this step-by-step guide to build a “Homework Assistant” AI agent pipeline using Galileo’s OpenAI integrations.
OpenAI Agent Walkthrough
Create Project Folder
Create a new project folder and navigate to it in your terminal.
Install Dependencies
Install the Galileo SDK and other necessary dependencies using the following command in your terminal.
Create Project Files
In your project folder, create a new blank application file and .env
file.
Set Environment Variables
In your .env
file, set your environment variables by filling in your API keys, Project name, and Log Stream name.
By using these exact variable names, Galileo will automatically use them in your application.
- NOTE: The Project name and Log Stream name are customizable. Change them as needed for your own experiments. You can view all your Projects and Log Streams in the Galileo Console.
Import Libraries
In your application file, add the following code to import all required libraries.
Define Output Structure
Add the code below to your application file to define an output structure.
The Guardrail agent uses this structure to reject invalid outputs by type. For example, an int
would be an invalid output in response to the question “Who was the first president of the United States?”
This is achieved in Python using BaseModel
, or in TypeScript using an interface
.
- BaseModel: A Python class from the
pydantic
library which automatically validates whether groups of values are the correct types.
Create Tutor Agents
Add the code below to your application file to create two specialized “tutor agents”. One handles math questions, and the other handles history.
- Agent: An AI module that receives inputs and provides specialized outputs based on predefined instructions.
Create Guardrail Agent
Add the code below to your application file to set up a Guardrail agent that will filter out non-homework questions.
- Guardrail Agent: A specialized agent for evaluating inputs and determining whether they meet specific criteria.
Define Guardrail Function
Add the code below to your application file to define the Guardrail agent’s logic for accepting valid inputs (in this case, homework questions) and rejecting invalid ones.
- Tripwire: A condition that triggers if the guardrail criteria are not met, preventing further processing.
Create Triage Agent
Add the code below to your application file to set up a Triage agent to pass the input question to the appropriate tutor agent.
- Triage Agent: An agent that analyzes the input and determines which specialized agent should handle the request.
Run the Agents
Add the code below to your application file. It runs the complete system by sending sample inputs and observing which agents handles the questions.
- Runner: A utility that executes the agents with provided input and context.
Complete Application Code
Below is the final combined code for the “Homework Assistant” AI agent application. Review it and compare it with your code.
Open Project & Log Stream
In your browser, open the Galileo Console. Then, select the Project and Log Stream whose names you used in your .env
file.
You will see new Traces, each containing data logged from running your AI agent pipeline.
- NOTE: Learn more about using Projects and Log Streams in the Getting Started Guide.
View Results
In the Galileo Console, click on one of the new Trace entries to see all of the data and steps executed by running your “Homework Assistant” application.
You should see:
- Each agent involved and when it was used
- All agent inputs, outputs, and handoffs
- Whether Guardrail Tripwires were passed or triggered
- The time of execution, Project ID, Run ID, Trace ID, and Parent ID (viewable in the “Parameters” tab in the top-right)
OPTIONAL: Test the Guardrail Tripwire
To see the Tripwire get triggered, modify one of the inputs to be a question that is not about homework.
- NOTE: This will cause an error because the Guardrail agent rejects questions that trigger the Tripwire.
Congratulations!
Your OpenAI agent pipeline is complete and ready to use.