Inspiration
I've been building AI agents and watching the payments space closely. I kept seeing tools that solved the "Who is allowed to spend...?" and "Is this agent authorized....?" problems. But nobody was watching what the agent actually does after it gets in. If an agent splits a $50 budget across 10 sketchy merchants, or gets stuck in a retry loop, current payment gateways just see valid requests. I wanted to build the layer that actually watches the behavior. Plus, as a developer who has never actually used a payment method in code before, I asked the question the insiders forgot to ask, after you say yes, who is watching the machine...?
What it does
Witness is a behavioral audit layer for AI shopping agents. It records an authorized agent's full action sequence, analyzes the pattern across transactions (not just individual ones), and produces a structured report. Then, it closes the loop. You can revoke the agent's credential, or submit the AI-generated report directly to the PayPal Sandbox as evidence for a dispute. It catches things like budget splitting, excessive browsing, and probing retries and then locks the agent down.
How we built it
I used FastAPI for the backend because it handles async requests and JSON validation beautifully. The credential Gate uses JWT (JSON Web Tokens) to issue scoped, expiring tokens with a spending cap. For the database, I used SQLite with SQLAlchemy to keep a persistent audit trail. For the AI analysis, I integrated Groq to analyze the action stream and return strict JSON findings. The frontend is Next.js, React, and Tailwind CSS, using Lucide for icons and Recharts for visualizing the agent's spending behavior. The whole thing communicates in real-time using WebSockets.
Challenges we ran into
Honestly, the AI APIs were a nightmare. Google Gemini kept deprecating models or throwing 503 "high demand" errors. I switched to NVIDIA NIM, which gave me a 404. I finally settled on Groq, which has been lightning fast and reliable. On the frontend, Next.js 16 (Turbopack) is incredibly strict. It threw constant errors about usePathname and cookies() needing Suspense boundaries, and I had to refactor the entire layout and auth wrapper just to get the pages to render. I also had to write a custom JWT gate because the initial library I tried (swarmauth) had a completely different API than I expected.
Accomplishments that we're proud of
I'm really proud of the closed-loop UX. When you click "Submit to PayPal," it actually hits the real PayPal Sandbox API, generates a real sandbox order ID, and then automatically flips the agent's status to "Suspended" in the database. If you try to run the agent again, the Gate rejects it with a 403. It's not just a dashboard; it actually takes action and enforces security.
What we learned
I learned a ton about how AI agents behave and how easily they can drift. I also learned that building a production grade UI in Next.js 16 is a completely different beast than building a simple prototype you have to handle every loading state, auth boundary, and server/client mismatch. And I learned that real-time WebSockets make a demo feel ten times more alive.
What's next for Witness
Next, I want to build out the multi-tenant dashboard so businesses can manage a whole fleet of agents, not just one. I also want to implement the full OAuth2 flow for the PayPal integration so users can link their actual sandbox accounts, and add natural language rules (e.g., "Alert me if an agent browses more than 20 items without buying"). The vision is to make Witness the standard forensic tool for the agentic web.
Built With
- fastapi
- groq
- jwt
- nextjs
- paypal-sandbox-api
- python
- react
- sqlalchemy
- sqlite
- tailwindcss
- websockets