Inspiration
When a customer disputes a payment, merchants need to understand why the payment was disputed, review the available transaction information, and determine how to respond.
This process can be time-consuming, especially for small merchants who may not have dedicated teams to investigate disputes or understand the relevant policies.
I wanted to build an AI-powered assistant that could bring dispute information, policy research, and actionable recommendations together in one place.
That idea became PayPal Copilot.
What it does
PayPal Copilot is an AI-powered merchant dispute analysis assistant that combines PayPal Sandbox APIs, Retrieval-Augmented Generation (RAG), and an LLM-powered agent.
It helps merchants investigate disputes and understand possible next steps.
The workflow:
- Retrieves disputes: Connects to the PayPal Sandbox Disputes API to retrieve available disputes.
- Inspects details: Fetches individual dispute information, including its reason, status, and available transaction details.
- Searches policies: Uses RAG to retrieve relevant information from a curated PayPal dispute knowledge base.
- Analyzes the dispute: An AI agent combines the retrieved dispute information and relevant policy context.
- Generates recommendations: Produces one of five structured recommendations:
- FIGHT
- REFUND
- OFFER
- GATHER_MORE_EVIDENCE
- ESCALATE
- Supports human review: Presents the analysis and recommendations in a Streamlit dashboard for the merchant to inspect.
The agent uses tool calling to decide when to retrieve disputes, inspect dispute details, and search the policy knowledge base.
The goal is to provide useful, explainable assistance rather than blindly trusting an LLM's response.
How I built it
- AI Agent: Built a custom Groq-powered function-calling agent with a multi-step tool execution loop. Smolagents is used for defining the agent tools.
- Agent Tools: Implemented three tools: PayPal dispute retrieval, individual dispute-detail retrieval, and policy search.
- RAG Pipeline: Developed a custom Retrieval-Augmented Generation pipeline using Sentence Transformers and FAISS.
- Embeddings: Used
all-MiniLM-L6-v2to generate semantic embeddings. - Vector Search: Used FAISS with normalized embeddings and similarity search to retrieve relevant policy chunks.
- PayPal Integration: Implemented OAuth 2.0 authentication and PayPal Disputes API integration using Sandbox credentials.
- LLM: Used Groq with
openai/gpt-oss-120bfor agent reasoning and function calling. - Frontend: Developed an interactive Streamlit dashboard for dispute selection, details, and AI analysis.
- Testing: Created pytest tests covering authentication, dispute retrieval, dispute details, policy retrieval, and end-to-end agent execution.
- Deployment: Deployed the application using Streamlit Community Cloud.
Challenges
1. Agent tool-calling reliability
Initially, integrating the agent through the LiteLLM/Smolagents execution path caused tool-calling compatibility issues.
I replaced that execution path with a custom Groq SDK function-calling loop. This gave me direct control over tool selection, argument parsing, execution, and multi-step interactions.
2. Building the RAG pipeline
I needed the agent to retrieve relevant policy information instead of generating answers from its general knowledge alone.
I built a custom pipeline that processes the knowledge base, generates embeddings, stores them in FAISS, and retrieves relevant chunks for each query.
3. PayPal Sandbox integration
Connecting authentication, retrieving dispute lists, and fetching individual dispute details required testing the actual API workflow.
I implemented and tested the OAuth and dispute endpoints independently before integrating them into the agent.
4. Cloud deployment
The application worked locally, but Streamlit Community Cloud exposed dependency and environment-configuration issues.
I updated the dependency configuration and adapted environment-variable handling to support both local .env files and Streamlit Secrets.
Accomplishments
- Built a working AI-powered dispute analysis application.
- Integrated PayPal Sandbox authentication and dispute APIs.
- Developed a custom RAG pipeline using Sentence Transformers and FAISS.
- Implemented an LLM agent capable of selecting and executing multiple tools.
- Integrated policy retrieval into the agent's analysis workflow.
- Implemented five structured dispute recommendations.
- Passed all five core pytest test modules, including the end-to-end agent test.
- Successfully deployed the application on Streamlit Community Cloud.
- Created project documentation, architecture explanations, and application screenshots.
Live Demo: https://paypal-copilot-agenta.streamlit.app/
What I learned
- An AI agent becomes more useful when it can access reliable external tools and structured information.
- Retrieval quality and document organization have a major impact on RAG performance.
- Function calling requires careful handling of tool schemas, arguments, execution results, and errors.
- Safety constraints should be enforced through application design, not just prompt instructions.
- Testing individual components before integrating them makes debugging much easier.
- A project that works locally still needs proper dependency and secrets management to work reliably in the cloud.
What's next
- Evidence-document ingestion and analysis.
- More advanced evidence-gap identification.
- Improved recommendation confidence and explainability.
- Support for additional dispute types and regional policy differences.
- Persistent dispute history and audit logging.
- Merchant authentication and account isolation.
- Human-approved action workflows.
- Production-grade security and scalability.
Important: PayPal Copilot currently uses PayPal Sandbox integration. It generates recommendations for human review and does not automatically submit evidence, issue refunds, or execute dispute-resolution actions.
The knowledge base contains summaries of publicly available PayPal documentation and should not be treated as official or guaranteed-current PayPal policy.
PayPal Copilot is an independent project and is not affiliated with, endorsed by, or officially associated with PayPal, Inc.