Skip to content

arvind-narain/returns-refunds-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Returns & Refunds Agent - AgentCore Runtime

License: MIT Python 3.10+ AWS

A production-ready AI agent for handling customer returns and refunds, built with Amazon Bedrock AgentCore Runtime.

🎯 Overview

This project demonstrates a complete end-to-end implementation of an enterprise-grade AI agent with:

  • 🧠 Memory Integration - Persistent conversation history and user preferences
  • πŸ”— Gateway Integration - External API calls via Lambda functions
  • πŸ“š Knowledge Base - Document retrieval for policy information
  • πŸ› οΈ Custom Tools - Business logic for eligibility and refund calculations
  • ☁️ Production Deployment - Serverless on AgentCore Runtime
  • πŸ“Š Full Observability - CloudWatch Logs, X-Ray traces, GenAI dashboards

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    AgentCore Runtime                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚         Returns & Refunds Agent                      β”‚   β”‚
β”‚  β”‚  β€’ Memory (Preferences, History, Summaries)          β”‚   β”‚
β”‚  β”‚  β€’ Gateway (Order Lookup via Lambda)                 β”‚   β”‚
β”‚  β”‚  β€’ Knowledge Base (Policy Documents)                 β”‚   β”‚
β”‚  β”‚  β€’ Custom Tools (Eligibility, Refund Calc)           β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                    β”‚                    β”‚
         β–Ό                    β–Ό                    β–Ό
   AgentCore            AgentCore            Lambda Function
     Memory              Gateway            (Order Lookup)

πŸ“‹ Prerequisites

  • AWS Account with appropriate permissions
  • Python 3.10+
  • AWS CLI configured
  • Bedrock model access (Claude Sonnet 4.5)

πŸš€ Quick Start

1. Clone the Repository

git clone https://github.com/arvind-narain/returns-refunds-agent.git
cd returns-refunds-agent

2. Install Dependencies

pip install -r requirements.txt

3. Deploy Infrastructure

# Create Memory
python3 src/infrastructure/03_create_memory.py
python3 src/infrastructure/04_seed_memory.py

# Setup Authentication
python3 src/infrastructure/08_create_cognito.py

# Create IAM Roles
python3 src/infrastructure/09_create_gateway_role.py
python3 src/infrastructure/16_create_runtime_role.py

# Setup Gateway
python3 src/infrastructure/10_create_lambda.py
python3 src/infrastructure/11_create_gateway.py
python3 src/infrastructure/12_add_lambda_to_gateway.py

4. Deploy Agent

# Deploy to AgentCore Runtime
python3 scripts/19_deploy_agent.py

# Check deployment status
python3 scripts/20_check_status.py

# Test the agent
python3 scripts/21_invoke_agent.py

5. Launch UI

cd src/ui
./run_streamlit.sh

Access at: http://localhost:8501

πŸ“ Project Structure

returns-refunds-agent/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ agents/              # Agent implementations
β”‚   β”‚   β”œβ”€β”€ 01_returns_refunds_agent.py
β”‚   β”‚   β”œβ”€β”€ 06_memory_enabled_agent.py
β”‚   β”‚   β”œβ”€β”€ 14_full_agent.py
β”‚   β”‚   └── 17_runtime_agent.py
β”‚   β”œβ”€β”€ infrastructure/      # AWS infrastructure setup
β”‚   β”‚   β”œβ”€β”€ 03_create_memory.py
β”‚   β”‚   β”œβ”€β”€ 04_seed_memory.py
β”‚   β”‚   β”œβ”€β”€ 08_create_cognito.py
β”‚   β”‚   β”œβ”€β”€ 09_create_gateway_role.py
β”‚   β”‚   β”œβ”€β”€ 10_create_lambda.py
β”‚   β”‚   β”œβ”€β”€ 11_create_gateway.py
β”‚   β”‚   β”œβ”€β”€ 12_add_lambda_to_gateway.py
β”‚   β”‚   β”œβ”€β”€ 13_list_gateway_targets.py
β”‚   β”‚   └── 16_create_runtime_role.py
β”‚   β”œβ”€β”€ tests/               # Test scripts
β”‚   β”‚   β”œβ”€β”€ 02_test_agent.py
β”‚   β”‚   β”œβ”€β”€ 05_test_memory.py
β”‚   β”‚   β”œβ”€β”€ 07_test_memory_agent.py
β”‚   β”‚   └── 15_test_full_agent.py
β”‚   └── ui/                  # User interface
β”‚       β”œβ”€β”€ streamlit_app.py
β”‚       └── run_streamlit.sh
β”œβ”€β”€ scripts/                 # Deployment & operations
β”‚   β”œβ”€β”€ 19_deploy_agent.py
β”‚   β”œβ”€β”€ 20_check_status.py
β”‚   β”œβ”€β”€ 21_invoke_agent.py
β”‚   β”œβ”€β”€ 22_get_dashboard.py
β”‚   └── 23_get_logs_info.py
β”œβ”€β”€ docs/                    # Documentation
β”œβ”€β”€ agentcore-mcp-server/    # MCP server implementation
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ requirements_streamlit.txt
β”œβ”€β”€ LICENSE
└── README.md

πŸ”§ Custom Tools

The agent includes three custom business logic tools:

  1. check_return_eligibility - Validates return eligibility based on purchase date and category
  2. calculate_refund_amount - Calculates refund based on price, condition, and return reason
  3. format_policy_response - Formats policy information in a customer-friendly way

πŸ“Š Monitoring & Observability

CloudWatch Dashboard

python3 scripts/22_get_dashboard.py

View Logs

python3 scripts/23_get_logs_info.py

Real-time Log Tailing

aws logs tail /aws/bedrock-agentcore/runtimes/returns_refunds_agent-* --follow

πŸ§ͺ Testing

Local Testing

# Test original agent
python3 src/tests/02_test_agent.py

# Test memory integration
python3 src/tests/07_test_memory_agent.py

# Test full agent with all features
python3 src/tests/15_test_full_agent.py

Production Testing

# Invoke deployed agent
python3 scripts/21_invoke_agent.py

πŸ” Security

  • OAuth 2.0 authentication via Cognito
  • IAM roles with least-privilege permissions
  • Secure credential management via environment variables
  • Configuration files excluded from version control

πŸ“ˆ Features

  • βœ… Memory - Persistent conversation history and preferences
  • βœ… Gateway - External API integration via Lambda
  • βœ… Knowledge Base - Document retrieval for policies
  • βœ… Custom Tools - Business logic implementation
  • βœ… Streaming - Real-time response streaming
  • βœ… Authentication - OAuth 2.0 with Cognito
  • βœ… Observability - CloudWatch Logs, X-Ray traces
  • βœ… Auto-scaling - Serverless with automatic scaling
  • βœ… Error Handling - Comprehensive error handling and logging

πŸ“š Documentation

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“§ Contact

For questions or support, please open an issue on GitHub.


Built with ❀️ using Amazon Bedrock AgentCore Runtime

About

Generated via Kiro prompts using Vibe Coding. Ultimately utilize spec driven development for learning

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors