Skip to main content
Follow this step-by-step guide to build a “Homework Assistant” AI agent pipeline using Galileo’s OpenAI integrations.

OpenAI Agent walkthrough

1

Create Project Folder

Create a new project folder and navigate to it in your terminal.
2

Install Dependencies

Install the Galileo SDK and other necessary dependencies using the following command in your terminal.
3

Create Project Files

In your project folder, create a new blank application file and .env file.
4

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.
5

Import Libraries

In your application file, add the following code to import all required libraries.
6

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.
  • BaseModel: A Python class from the pydantic library which automatically validates whether groups of values are the correct types.
7

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.
8

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.
9

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.
10

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.
11

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.This code also sets a custom OpenAI trace processor. This call replaces the built in OpenAI trace processor with a Galileo one that logs traces to Galileo.To learn more, check out the Python GalileoTracingProcessor SDK docs.
  • Runner: A utility that executes the agents with provided input and context.
12

Complete Application Code

Below is the final combined code for the “Homework Assistant” AI agent application. Review it and compare it with your code.
13

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.
14

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) View Trace
15

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.
16

Congratulations!

Your OpenAI Agent Pipeline is complete and ready to use.

Next steps

  • Create your own project with new instructions to define your own specialized agents.
  • Include Metadata and Tags in your logs to track results and add automations.
  • Add Metrics to your experiment to evaluate results.
  • Create Datasets to improve evaluation accuracy and compare performance improvements.