Overview
In this tutorial, you’ll learn how to set up and run a complete AI agent that integrates with Stripe’s payment processing API via the Stripe Agent Toolkit while using Galileo for AI Agent Reliability. This tutorial is intended for TypeScript developers building AI agents with payment processing capabilities. It assumes you have basic knowledge of:- Some familiarity with TypeScript, Node.js, and the command line
- Node.js 18+ and npm or yarn
- Code editor of choice (VS Code, Cursor, Warp, etc.)
- API keys for:
- Set up a complete Stripe AI agent with Galileo observability
- Handle natural language conversations for payment operations
- Track all interactions and performance with Galileo
- Monitor agent reliability and tool usage patterns
What you’ll build
For the sake of jumping right into action — we’ll be starting from an existing TypeScript application and demonstrating how to build a complete AI agent with payment processing capabilities. The Stripe AI Agent is a TypeScript-based application that can handle payment operations through natural language conversations. The agent includes:- Product Management: List products and prices from Stripe
- Payment Processing: Create payment links for customers
- Customer Management: Handle customer data and operations
- Natural Language Interface: Process conversational requests
- Galileo Observability: Track all interactions and performance
Prerequisites
Before you start, you’ll need to set up accounts and get API keys for the services we’ll be using.Create a new Galileo project
In order to set up agent reliability tracking, we’ll need a Galileo project to log interactions to first.1
Create a new project from the Galileo console using the `New Project` button
If you haven’t already, create a free Galileo account on app.galileo.ai. When prompted, add an organization name. To dive right into this tutorial, you can skip past the onboarding screen by clicking on the Galileo logo in the upper left hand corner.Create a new project by clicking on the New Project button on the upper right hand screen. You will be prompted to add a project name, as well as a Log stream name.
Note: You will not be able to come back to this screen again, however there are helpful instructions to getting started in the Galileo Docs.
2
Get your Galileo API Keys
Once that is created, click on the profile icon in the upper right hand side of the page, navigate on the drop-down menu to API keys. From the API Keys screen, select Create New Key. Save the key within your environment file with the project name and Log stream name you’ve created.

3
Setting the metrics you want to track
Before running your application, set the metrics you want to track in your application by adding metrics to your Log stream.Navigate to your project home inside of Galileo.Look for the name of your project, and open it up to the Log stream you’ve got your traces in.Click on the Trace view and see your most recent runs listed below, it should look something like below.From this view, navigate to the upper right hand side of your screen and click on the Configure Metrics button. A side panel should appear with a set of different metrics from you to choose from.
Based on the Galileo documentation, here are some suggestions:

- Tool Error: Detects errors during tool execution
- Tool Selection Quality: Determines if the agent selected the correct tool and arguments
- Context Adherence: Measures closed-domain hallucinations
Create a Stripe Developer Sandbox Account
1
Sign up for a Stripe Developer Account
Go to Stripe Dashboard and sign up for a free account. This will give you access to the Stripe sandbox environment for testing.
2
Get your Stripe API Keys
Navigate to the Developers section in your Stripe dashboard on the bottom left hand side of the screen. Copy your test secret key (starts with
sk_test_) and paste it into your .env file as STRIPE_SECRET_KEY. Note: Make sure you’re using the test keys, not the live keys, for this tutorial. The test environment allows you to simulate payments without processing real transactions.
Set up the project
Now let’s get the code and set up your development environment.1
Clone the project in your IDE of choice
The starter project is in the
sdk-examples/typescript/agent/stripe-agent-tool folder in the cloned repo.Navigate to the folder using the command line:2
Install dependencies
Install the required dependencies for the project.
3
Configure your .env file
Copy the example environment file and rename it to
.env, then add your own API keys. Be sure the variables are added to your .gitignore file.When complete, it should look something like this:.env
Note: Replace the placeholder values with your actual API keys and be sure to have your .gitignore file updated to exclude the .env file.
4
Build the project
Compile the application to prepare to run locally on your machine.
Running the agent
Now let’s start the agent and see it in action!1
Start the interactive CLI mode
Start the interactive command-line interface to test your agent:This will:Available Commands:
- Initialize the agent with Galileo’s agent reliability tools
- Start a conversation session
- Allow you to interact with the agent using natural language
help- Show available commands and examplesquitorexit- Exit the applicationclear- Clear the terminal screen!end- Force flush Galileo traces (developer command)
2
Start the web mode
Check out the interface by running it in the browser, aiming to run this locally on your machine.The application will run on
http://localhost:3000Observing your agent in Galileo
Now let’s see how Galileo tracks your agent’s performance and interactions.What’s tracked
Your agent automatically tracks:- Conversations and tool usage
- Agent Errors and failure patterns
- Session information
- Tool selection quality and accuracy
Viewing your data
1
Navigate to your Galileo Dashboard
Go to your Galileo Dashboard and navigate to your project.
2
View traces and sessions
Click on your Log stream to view traces, sessions, and metrics. You’ll be able to monitor agent performance over time.

Understanding the agent architecture
Now that you’ve seen the agent in action, let’s dive deeper into how it works internally.Project structure
The project follows a clean, modular architecture designed for maintainability and observability:Key components
The Stripe Agent consists of several key components:🧠 Agent core (agents/StripeAgent.ts)
Handles the main agent logic, coordinates tools, and processes requests. This is where the LangChain agent is initialized with Stripe tools and Galileo callbacks.
🛠️ Tools (Stripe Agent Toolkit)
Specialized modules for specific payment operations:- Product Tools: List products and prices from Stripe
- Payment Tools: Create payment links and process transactions
- Customer Tools: Manage customer data and operations
- Subscription Tools: Handle recurring billing operations
📝 Configuration (config/environment.ts)
Defines the agent’s environment variables and configuration settings for Stripe, OpenAI, and Galileo integration.
🔍 Instrumentation (interactive.ts and server.ts)
Wraps the agent with Galileo monitoring for observability. This is where we add tracing and metrics.
📑 Types (types/index.ts)
Contains TypeScript type definitions for the agent’s data structures and API responses.
Main agent workflow
The main workflow inagents/StripeAgent.ts ties everything together and adds Galileo instrumentation for observability.
Key Ingredients:
- Galileo context management
- LangChain agent with Stripe tools
- Session tracking
- Error handling and loop prevention
-
Setting up the Galileo Callback:
This initializes Galileo and creates a callback handler for tracking agent interactions.
-
Creating the main agent:
This creates a LangChain agent with Stripe tools and structured chat capabilities.
-
Tool execution with tracing:
Each tool call is automatically traced by Galileo through the LangChain callback:
-
Session management:
The agent maintains session context for better user experience:
- Entrypoint span: Contains the entire conversation session with user inputs
- Workflow span: Tracks the main agent logic and decision-making
- Tool spans: Monitor individual Stripe API calls and success rates
- Session spans: Track conversation context and user interaction patterns
The Stripe tools
Let’s examine the Stripe tools to understand how they work and where Galileo fits in. Key Ingredients:- Stripe API integration
- LangChain tool definitions
- Error handling
- Response parsing
- API Integration: The tools make requests to the Stripe API to perform payment operations.
-
Tool Definition:
This gets all available Stripe tools from the Stripe Agent Toolkit.
-
Request processing:
The tools handle various Stripe operations:
- List products: Fetches available products and pricing
- Create payment links: Generates payment URLs for customers
- Customer management: Creates and manages customer records
- Subscription handling: Processes recurring billing
- Error handling: The tools include robust error handling to gracefully manage API failures and provide meaningful error messages.
- Capture the user’s natural language input
- Record the agent’s tool selection and reasoning
- Track tool execution time and success rates
- Provide context for debugging and optimization
The conversation memory system
This system provides intelligent caching and context management for improved user experience. Key Ingredients:- 5-minute caching system
- Session context tracking
- Conversation history management
- Performance optimization
-
Caching strategy:
The agent implements a 5-minute cache for frequently accessed data:
-
Session context:
Each conversation session maintains context for better continuity:
-
Loop prevention:
Advanced circular tool usage detection prevents infinite loops:
- Session duration and activity patterns
- Conversation flow and context switches
- Tool usage patterns across sessions
- Performance metrics over time
- How users interact with the payment system
- Common conversation patterns and pain points
- Tool selection effectiveness
Customization
Now that you understand how the agent works, let’s explore how to customize it for your specific needs.Adding new tools
To add new Stripe tools, modify the agent initialization:Modifying prompts
To customize the agent’s behavior, modify the prompt template:Environment variables
Additional configuration options:Troubleshooting
If you encounter issues, here are some common solutions.Common issues
1
Missing environment variables
Check your .env file exists and verify all required variables are set:
2
Galileo initialization failed
Check your Galileo API key and internet connection:
3
Stripe API errors
Verify your Stripe key format and test the connection:
4
Agent not responding
Check your OpenAI API key and test the connection:
Debug Mode
Enable verbose logging for troubleshooting:Manual Trace Flushing
Force flush Galileo traces in interactive mode:Summary
In this tutorial, you learned how to:- Set up a complete Stripe AI agent with Galileo observability
- Handle natural language conversations for payment operations
- Track all interactions and performance with Galileo
- Monitor agent reliability and tool usage patterns
- Customize and extend the agent’s capabilities
Next steps
- Check out other cookbooks in the Galileo cookbook library
- Explore how to create custom metrics in Galileo using code
- Learn more about the different out-of-the-box-metrics available in Galileo
- Extend your agent with additional Stripe operations (refunds, subscriptions, etc.)
- Implement user authentication and payment webhook handling