Inspiration
As an MLE working in tech, I’ve repeatedly struggled with two questions: Where do agents actually add value, and how do I build them to stay reliable as the data and requirements change?
Getting an agent to produce an answer is only the beginning. I wanted a system that could investigate data, train models, test its recommendations, and explain its decisions—and that I could extend without rebuilding the entire workflow each time.
Commerce gave that challenge measurable consequences. A recommendation can become an order, a delivery, a refund, and a financial outcome. Each step creates evidence that an agent should learn from.
That became Market Metro — Agentic Commerce That Learns: an environment where agents can take on commerce workflows, face realistic constraints, and show their work.
What it does
Market Metro is an interactive commerce simulation with merchants, shoppers, inventory, budgets, purchases, deliveries, and refunds. Those interactions generate a transaction warehouse that agents can investigate.
The campaign workflow connects:
Market activity → ontology → analysis → model training → campaign testing → shopper purchases → payment evidence
The planner chooses what to investigate, which historical data and features to use, and which models to train. It proposes campaigns and reviews their measured outcomes. A financial verifier determines whether a tested proposal can be published or whether the existing policy should remain.
Judges can follow a complete campaign, inspect individual shopper activity, explore new seeded markets using the recorded policy, and request fresh agent investigations in AG Studio.
How I built it
I separated the system into clear responsibilities:
- Three.js renders the market and makes shopper activity visible.
- Node.js and SQLite manage the economy, transaction records, and workflow checkpoints.
- Python, NumPy, and scikit-learn train and evaluate predictive models.
- Gemini on Vertex AI chooses investigations, modeling actions, campaigns, and analytical views.
- PayPal Sandbox executes selected test payments and provides native receipts.
- AG Studio, AG Grid, and AG Charts expose the evidence through interactive dashboards and agent-driven investigations.
The ontology gives these components a shared understanding of commerce. It distinguishes a shopper’s checkout from each merchant’s portion, a recommendation from a general inquiry, and historical signals from later outcomes.
That distinction matters. In one investigation, the ontology reconciled 125 merchant orders into 114 shopper checkouts. Counting every merchant order as a purchase would have overstated the result. In model training, the same approach determines which examples and features are appropriate for the prediction task.
The agents operate through typed tools and saved checkpoints. Numerical calculations, data validation, and publication checks remain deterministic. This makes it possible to inspect a decision, reject unsupported claims, and add capabilities through defined interfaces.
Why PayPal is central
I wanted success to be measured through completed commerce: purchases that survive refunds, merchant contribution, and modeled payment-platform economics.
PayPal connects that analysis to verifiable payment execution.
The featured campaign follows a shopper who returns after 16 days and buys a $96 side table. The same order is linked to a completed PayPal Sandbox capture showing:
- $96.00 gross payment
- $3.56 processing fee
- $92.44 in test merchant proceeds
The receipt traces back to the warehouse order and is counted once. It provides concrete integration evidence using fictitious funds.
Bringing the agents into AG Studio
I extended the architecture into an interactive analytical workspace using AG Studio’s Agent Framework.
A commerce-planning agent chooses a merchant cohort. Studio’s native query tool retrieves the data. An ontology verifier reconciles the returned values and their meaning. An insight-editing agent selects supported findings and useful views, and a checked publisher updates the dashboard.
The interface makes that process visible through agent roles, native delegation, tool calls, checkpoints, editable layouts, and a custom PayPal receipt widget.
Two fresh investigations produced different results:
- A refund investigation selected three merchants and published five verified views.
- A sales investigation selected six merchants, reconciled 1,280 checkouts with 1,666 merchant orders, and published a different five-view dashboard.
Together, those four model calls cost an estimated $0.004180 in inference.
Results I can show
In the featured 12-merchant, 600-shopper campaign, the planner and verifier improved results over fixed rules by:
- 16 additional retained purchases
- $1,024.86 in additional merchant contribution
- $114.96 in additional modeled PayPal net, after model cost—a 3.47% increase
In a separate six-market reactivation study, the checked single planner improved all three outcomes over fixed rules in six out of six simulated markets.
These are controlled simulation results. Merchant contribution includes inventory value, and modeled PayPal net is not actual PayPal profit. The separate dashboard investigations demonstrate analysis and publication; they are not counted as additional campaign gains.
Challenges and what I learned
The hardest lesson was that better predictions do not automatically produce better business decisions.
In the featured review, the verifier changed the planner’s preferred ranking model after comparing financial outcomes. That experience shaped the architecture: models provide predictions, agents choose experiments, and measured results govern publication.
More agents also did not consistently improve campaign returns. I kept the strongest campaign configuration and introduced separate agent roles where the handoff had a clear purpose, such as cohort investigation and insight design.
Data consistency was equally challenging. Split baskets, delayed outcomes, refunds, and mismatched merchant fields could distort both training and evaluation. Building the ontology and verification boundaries became as important as choosing the model.
My biggest takeaway is that reliable autonomy depends on the whole system: clear data definitions, appropriate tools, bounded execution, inspectable decisions, and honest evaluation.
What’s next
I want to extend Market Metro to consented merchant data, additional business questions, and controlled real-world experiments. The foundation is now in place to add capabilities while preserving the evidence and safeguards that make the agents’ decisions understandable.
Built With
- ag-charts
- ag-grid
- ag-studio
- css
- docker
- gemini
- github-actions
- google-cloud
- google-cloud-build
- google-cloud-run
- html5
- javascript
- json-schema
- node.js
- numpy
- paypal
- paypal-sandbox
- python
- scikit-learn
- sqlite
- three.js
- vertex-ai