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.Create a new project from the Galileo console using the `New Project` button
Get your Galileo API Keys

Setting the metrics you want to track

- 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
Sign up for a Stripe Developer Account
Get your Stripe API Keys
sk_test_
) and paste it into your .env file as STRIPE_SECRET_KEY.Set up the project
Now let’s get the code and set up your development environment.Clone the project in your IDE of choice
sdk-examples/typescript/agent/stripe-agent-tool
folder in the cloned repo.Navigate to the folder using the command line:Install dependencies
Configure your .env file
.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:Build the project
Running the agent
Now let’s start the agent and see it in action!Start the interactive CLI mode
- 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 examplesquit
orexit
- Exit the applicationclear
- Clear the terminal screen!end
- Force flush Galileo traces (developer command)
Start the web mode
http://localhost:3000
Observing 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
Navigate to your Galileo Dashboard
View traces and sessions

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
Missing environment variables
Galileo initialization failed
Stripe API errors
Agent not responding
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