https://github.com/langwatch/langwatch-flagsmith-demo
https://github.com/langwatch/langwatch-flagsmith-demo
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/langwatch/langwatch-flagsmith-demo
- Owner: langwatch
- Created: 2025-11-21T11:28:05.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-11-25T15:50:33.000Z (9 months ago)
- Last Synced: 2025-11-28T21:35:16.566Z (8 months ago)
- Language: TypeScript
- Size: 5.04 MB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Agents: AGENTS.md
Awesome Lists containing this project
README
# Banking Agent Demo
This project demonstrates a banking agent built with [Mastra](https://mastra.ai), integrated with [LangWatch](https://langwatch.ai) for monitoring and testing, and [Flagsmith](https://flagsmith.com) for feature flagging.
## Overview
The agent provides customer support for businesses, with capabilities including:
- **Deep Research**: Analyze customer history.
- **Account Management**: Manage transactions, move funds, and understand quarterly results.
- **Support**: Handle common support issues.
- **Dispute Resolution**: A feature-flagged tool for handling transaction disputes.
## Tech Stack
- **Framework**: Mastra (TypeScript)
- **Monitoring & Testing**: LangWatch
- **Feature Flags**: Flagsmith
- **Test Runner**: Vitest
## Setup
1. **Install Dependencies**:
```bash
pnpm install
```
2. **Environment Variables**:
Copy `.env.example` to `.env` and add your API keys (OpenAI, LangWatch, Flagsmith).
*Note: The keys are already provided in the `.env` file for this demo.*
3. **Mastra Setup**:
The project is initialized with Mastra.
## Development
### Quick Start โ
Start the Mastra server:
```bash
pnpx mastra dev
```
This starts:
- ๐ฎ **Playground UI** at http://localhost:3003 (or http://localhost:4111)
- ๐ **Agent API** at `http://localhost:3003/api/agents/bankingAgent/generate`
- ๐ **Automatic LangWatch tracing**
### Test the API
**Via curl:**
```bash
curl -X POST http://localhost:3003/api/agents/bankingAgent/generate \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "user", "content": "What is my account balance?"}
]
}'
```
**Via Web UI:**
Open `examples/chat.html` in your browser for a beautiful chat interface!
### API Endpoint
```
POST http://localhost:3003/api/agents/bankingAgent/generate
```
**Request:**
```json
{
"messages": [
{"role": "user", "content": "Your message here"}
]
}
```
**Response:**
```json
{
"text": "Agent response...",
"usage": {...},
"steps": [...]
}
```
### Notes
- โ
**No separate Express server needed** - Mastra handles everything
- โ
**Automatic observability** - LangWatch traces are sent automatically
- โ
**Conversation context** - Pass the full message history in each request
- โ
**Built-in playground** - Test agents visually in the browser
### Testing
We use **Scenario** (by LangWatch) for end-to-end agent testing.
To run the scenarios:
```bash
npx tsx tests/scenarios/banking_agent.test.ts
```
(Adjust path as needed)
### Prompts
Prompts are managed via the LangWatch Prompt CLI.
To sync prompts:
```bash
langwatch prompt sync
```
To create a new prompt:
```bash
langwatch prompt create
```
## Features & Flags
- **Transaction Dispute**: This feature is controlled by a Flagsmith flag.
- Flag: `transaction_dispute`
- When enabled, the agent can help users dispute transactions.
## Quick Links
- ๐ [API Documentation](./API.md) - Complete API reference
- ๐ [Quick Start Guide](./QUICKSTART.md) - Get up and running in 5 minutes
- ๐งช [Agent Guidelines](./AGENTS.md) - Development best practices
## Project Structure
```
src/
โโโ server.ts # Express API server (new!)
โโโ mastra/
โ โโโ agents/
โ โ โโโ banking-agent.ts # Banking agent implementation
โ โโโ tools/
โ โโโ banking.ts # Banking tools (accounts, transactions, etc.)
โโโ data/
โ โโโ mockData.ts # Mock customer data
โโโ utils/
โโโ flags.ts # Flagsmith integration
examples/
โโโ client.ts # TypeScript API client example
โโโ chat.html # Web interface for testing
tests/
โโโ scenarios/
โ โโโ banking_agent.test.ts # Agent behavior scenarios
โ โโโ api.test.ts # API integration tests
โโโ evaluations/
โโโ example_eval.ipynb # Evaluation notebooks
scripts/
โโโ test-api.sh # API testing script
```
## License
ISC