A self-contained TypeScript agent using Stripe Agent Toolkit with Galileo monitoring.
- Stripe Integration: Complete payment processing capabilities
- AI Agent: Powered by OpenAI GPT-4o-mini for intelligent customer interactions
- Loop Prevention: Advanced circular tool usage detection prevents infinite loops
- Conversation Memory: 5-minute product/price caching reduces redundant API calls
- Buffered Logging: Galileo traces are buffered and flushed efficiently
- Galileo Agent Reliability: Comprehensive logging and analytics
- Recommended metrics to use in Galileo to track agent reliability:
- Tool Error: detects errors or failures during the execution of Tools.
- Tool Selection Quality: determines whether the agent selected the correct tool and for each tool the correct arguments.
- Context Adherence: a measurement of closed-domain hallucinations: cases where your model said things that were not provided in the context.
- See all metrics here
- Recommended metrics to use in Galileo to track agent reliability:
- Interactive Modes: CLI and web server options
- Self-contained: All dependencies and assets included
stripe-agents-sdk-example/
├── src/
│ ├── agents/ # Agent implementation
│ ├── config/ # Configuration files
│ ├── errors/ # Custom error classes
│ ├── types/ # TypeScript type definitions
│ ├── utils/ # Utility functions
│ ├── index.ts # Main entry point
│ ├── interactive.ts # Interactive CLI mode
│ └── server.ts # Web server mode
├── tests/ # Test files
├── public/ # Static assets
├── dist/ # Compiled JavaScript output
├── package.json # Dependencies and scripts
└── tsconfig.json # TypeScript configuration
- Clone the repository
- Install dependencies
- Configure environment
- Build the project
- Run the project
- Node.js 18+
- npm or yarn
- Stripe account with API keys
- OpenAI API key
- Galileo account
-
Install dependencies:
npm install
-
Configure environment:
cp .env.example .env
Edit
.envwith the keys for your project# Stripe Configuration STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key_here # OpenAI Configuration OPENAI_API_KEY=your_openai_api_key_here # Galileo Configuration GALILEO_API_KEY=your_galileo_api_key_here #Your Galileo API Key GALILEO_PROJECT=stripe-agent-demo #Your Galileo Project Name GALILEO_LOG_STREAM=production #Your Galileo Log Stream Name # OPTIONAL # Provide the console URL below if you are using a custom deployment, and not using app.galileo.ai # This is most common with enterprise, or on prem deployments where you may have your own custom cluster # GALILEO_CONSOLE_URL=https://console.galileo.ai # OPTIONAL # Set the verbosity level of the Galileo SDK (from most to least verbose): # debug, info, warn, error, silent (default) # GALILEO_LOG_LEVEL=debug # Agent Configuration AGENT_NAME=StripePaymentAgent AGENT_DESCRIPTION=An AI agent that helps with Stripe payment operations
-
Build the project:
npm run build
This project includes a comprehensive space-themed product catalog for "Galileo's Gizmos". To set up the product catalog:
-
Ensure your Stripe API key is configured in your
.envfile -
Run the setup script:
npm run setup-products
This will create 20 space-themed products including:
- Astronomical Equipment: Telescopes, binoculars, camera adapters
- Space Exploration Gear: Training suits, VR helmets, Mars rovers
- Educational Items: Mars rocks, star maps, mission patches
- Space Food: Astronaut meals, energy bars, freeze-dried treats
- Home & Lifestyle: Nebula projectors, space bedding, cosmic art
🔭 Astronomical Equipment ($29.99 - $1,299.99)
- Galileo's Premium Telescope
- Stellar Binoculars Pro
- Cosmic Camera Adapter
- Planetary Filter Set
👨🚀 Space Exploration Gear ($199.99 - $2,499.99)
- Astronaut Training Suit
- Zero Gravity Simulator
- Space Helmet VR
- Mars Rover Remote Control
📚 Educational & Collectibles ($29.99 - $89.99)
- Mars Rock Collection
- Cosmic Discovery Box
- Galileo's Star Map
- Space Mission Patch Set
🍽️ Space Food & Nutrition ($19.99 - $79.99)
- Astronaut Food Pack
- Cosmic Energy Bars
- Zero-G Coffee Mug
- Space Ice Cream
🏠 Home & Lifestyle ($44.99 - $159.99)
- Nebula Projector
- Space-Themed Bedding Set
- Cosmic Wall Art
- Astronaut Alarm Clock
npm run interactivenpm run webnpm testThe agent now includes advanced circular tool usage detection that:
- Monitors the last four tool calls for repeated patterns
- Detects when tools are being called in loops (e.g., A → B → A → B)
- Gracefully handles circular calls with appropriate error messages
- Prevents runaway loops that could exhaust API quotas
Improved memory system with:
- five-minute caching of product and price data
- Conversation history maintained across interactions
- Context awareness using the last 6 messages for better responses
- Reduced API calls through intelligent caching
Galileo logging improvements:
- Buffered traces are queued and flushed efficiently
- Developer override command
!endto force flush during testing - Session management with proper cleanup and error handling
- Performance optimized logging reduces response times
When using interactive mode, these special commands are available:
help- Show available commands and examplesquitorexit- Exit the application gracefullyclear- Clear the terminal screen!end- Developer command: Force flush all buffered Galileo traces
AgentExecutor Configuration:
// Updated configuration
maxIterations: 8; // Increased to handle complex interactions
earlyStoppingMethod: "force"; // Stop when agent decides it's completeNew Caching Methods:
// Cache management
private isCacheValid(): boolean
private updateCache(products: any[]): void
private clearCache(): void
// Memory properties
private cachedProducts: any[] = []
private cachedPrices: any[] = []
private cacheTimestamp: number = 0
private readonly CACHE_DURATION = 5 * 60 * 1000 // 5 minutesnpm run build- Compile TypeScript to JavaScriptnpm run dev- Runs automated testing examples — no interactive mode/user input.- walks through demo script of: Payment link creation, customer creation, product listing, and subscription creation.
npm run interactive- Start interactive CLI modenpm run web- Start web server modenpm run test- Run test suitenpm run setup-products- Set up space-themed product catalog in Stripe
All compiled JavaScript files are output to the dist/ directory, making the project ready for deployment.