Roundel Copilot: Multi-Agent AI System for Retail Media Optimization

$40M in attached OKRs, $2k/day immediate spend increase, set product standard for agentic systems
11/11/20248 min read
LangGraphFastAPIBigQueryMongoDBPostgreSQLElasticsearchRedisOpenAI GPT-4Vercel AI SDKChart.jsDocker

Executive Summary

Built an AI-powered agentic system for Target's Roundel advertising platform that autonomously identifies revenue opportunities and generates data-driven narratives for account managers. The system achieved $40M in attached OKRs and immediately drove a $2k/day spend increase in the first manual test.

Key Achievement: Designed and implemented a dual multi-agent architecture combining real-time conversational intelligence with autonomous nightly analysis, processing billions of advertising data points to surface actionable insights.

The Business Problem

Retail media platforms face a critical revenue leakage problem: campaign cap-out. When high-performing advertising campaigns hit their budget limits, they stop spending—leaving revenue on the table for both the platform and the advertiser.

The Challenge

Account managers at Roundel faced three core problems:

  1. Data Complexity: Thousands of campaigns across hundreds of advertisers, each with multidimensional metrics (ROAS, daily sales, spend velocity, budget utilization)
  2. Opportunity Blindness: High-value upsell opportunities were buried in data, requiring manual analysis across disconnected systems
  3. Narrative Gap: Even when opportunities were found, translating data into compelling, actionable stories for advertisers was time-intensive and inconsistent

The goal: Build an AI system that could autonomously identify opportunities, analyze performance patterns, and generate persuasive, data-backed narratives that account managers could immediately act on.

Solution Architecture

I designed a dual multi-agent system using LangGraph, combining real-time conversational intelligence with autonomous batch processing.

Technology Stack

  • Orchestration: LangGraph (multi-agent framework)
  • API Layer: FastAPI
  • Data Sources: BigQuery (campaign data via Trino), MongoDB (session/presentation storage), PostgreSQL (application state)
  • Vector Store: Elasticsearch (RAG for context-aware responses)
  • Caching: Redis
  • LLM: OpenAI GPT-4
  • Frontend: Vercel AI SDK with Generative UI, Chart.js for visualizations
  • Infrastructure: Docker, cron-based scheduling

Multi-Agent Architecture

Agent System 1: Real-Time Data Exploration

Purpose: Interactive conversational interface for account managers to explore campaign data and discover trends.

Real-Time Data Exploration Flow

Interactive conversational interface for account managers. Drag to pan, scroll to zoom.

React Flow mini map

Agent Flow

Query to Response Agent Flow

Real-time data exploration from user query to synthesized insights. Drag to pan, scroll to zoom.

React Flow mini map

Key Technical Decisions

1. Dynamic SQL Generation

Built a specialized tool that writes SQL queries based on natural language intent. The Historical Data Agent analyzes user requests and contextual needs to construct optimized BigQuery queries with query validation and caching (Redis) to minimize costs.

2. Generative UI with Server-Side Rendering

Used Vercel AI SDK to generate React Server Components on-the-fly. The Visualization Agent converts trend data into JSON schemas, which are rendered as Chart.js visualizations. Graphs are automatically saved to MongoDB for reuse in presentations.

3. Subgraph Design

Each agent is implemented as a LangGraph subgraph for modularity. The Supervisor uses conditional routing based on user intent and conversation state, maintaining context across agent handoffs using shared state.

Example Flow

// Conceptual representation of the agent flow

User: "Show me cap-out trends for electronics advertisers in Q4"Supervisor: Routes to Historical Data AgentHistorical Data Agent: Generates SQL
    SELECT advertiser_id, campaign_id, budget_cap, actual_spend, 
           missed_spend_opportunity, category, date
    FROM roundel.campaign_performance
    WHERE category = 'electronics' 
      AND date BETWEEN '2024-10-01' AND '2024-12-31'
      AND (actual_spend / budget_cap) > 0.95Trend Detection Agent: Identifies patterns
    - 23 campaigns hit 95%+ budget utilization
    - Average missed opportunity: $1,847/day
    - ROAS for capped campaigns: 4.2x (above platform average)
    ↓
Visualization Agent: Generates Chart.js component
    [Bar chart: Campaign Budget Utilization + Line: Missed Revenue]
    ↓
Supervisor: Returns narrative + visualization
    "I found 23 electronics campaigns experiencing cap-out in Q4. 
     These campaigns are performing 15% above platform average ROAS 
     but are missing ~$42k/day in potential spend. See visualization..."

Agent System 2: Nightly Deep-Dive Agent

Purpose: Autonomous overnight analysis to surface opportunities and generate presentation-ready narratives for account managers.

Nightly Deep-Dive Agent Flow

Autonomous overnight analysis surfacing opportunities. Drag to pan, scroll to zoom.

React Flow mini map

Key Technical Decisions

1. Session-Based Context

The system ingests Redux state updates from user sessions stored in MongoDB. The Activity Analysis Agent identifies what campaigns and advertisers the manager recently viewed, prioritizing opportunities aligned with the manager's current focus areas.

2. Opportunity Detection Logic

The Data Analysis Agent runs a multi-stage analysis:

# Opportunity scoring algorithm (conceptual)
def calculate_opportunity_score(campaign):
    score = 0
    
    # Budget utilization > 90%
    if campaign.budget_utilization > 0.90:
        score += 30
    
    # ROAS > platform median
    if campaign.roas > platform_median_roas:
        score += 25
    
    # Consistent daily sales velocity
    if campaign.sales_consistency > 0.85:
        score += 20
    
    # Historical headroom (performed well at higher budgets)
    if campaign.historical_performance_at_higher_budget:
        score += 25
    
    return score

# Process pipeline
1. Query all active campaigns for manager's accounts
2. Calculate opportunity score for each campaign
3. Rank opportunities by revenue impact potential
4. Filter for "story-worthy" opportunities (clear narrative angle)

3. Narrative Generation

The Narrative Agent creates persuasive stories using a structured approach:

  • Hook: The opportunity cost ("You're leaving $X on the table")
  • Evidence: Historical performance data proving campaign efficacy
  • Projection: Data-driven forecast of impact if budget increased
  • Call-to-Action: Specific budget recommendation

Example narrative structure:

Campaign ELECTRONICS-Q4-CAPOUT-001

Advertiser: TechGear Co.

Budget Cap

Performance Over Past 14 Days

Current ROAS

5.2x

+30% vs portfolio avg

Days at Budget Cap

12/14

86% constrained

Sales Generated

$47k

Despite constraints

Estimated Missed Opportunity: $8.3k/day

Historical Context

When budget was increased by 25% in Q2, this campaign maintained a 4.8x ROAS.

Recommendation

Daily Budget

$2,000$2,500

+25%

Projected Daily Sales

+$2,500

@ 4.9x ROAS

High Confidence

Based on 90 days of consistent performance data

4. Automated Presentation Assembly

The Slideshow Agent retrieves saved visualizations from MongoDB (or generates new ones) and assembles slides with titles, narratives, supporting graphs, and recommendation summaries. The output is presentation-ready for morning review with iterative refinement available through the conversational interface.

Technical Implementation Details

LangGraph Multi-Agent Patterns

Supervisor Pattern

# Simplified conceptual structure
supervisor_graph = StateGraph(AgentState)

supervisor_graph.add_node("supervisor", supervisor_agent)
supervisor_graph.add_node("historical_data", historical_data_agent)
supervisor_graph.add_node("trend_detection", trend_detection_agent)
supervisor_graph.add_node("visualization", visualization_agent)

# Conditional routing based on supervisor decisions
supervisor_graph.add_conditional_edges(
    "supervisor",
    route_to_agent,  # Function that determines next agent
    {
        "historical_data": "historical_data",
        "trend_detection": "trend_detection",
        "visualization": "visualization",
        "end": END
    }
)

Tool Integration

Built custom tools for BigQuery SQL generation and execution. Tools return structured data that flows through agent state, with retry logic and fallback queries for robustness.

State Management

Shared state object carries conversation context, retrieved data, and generated artifacts across agent transitions. Redux-style updates stored to MongoDB for session persistence and activity analysis.

RAG Implementation

Used Elasticsearch as a vector store for:

  • Campaign metadata embeddings: Quickly retrieve similar campaigns for benchmarking
  • Historical narrative embeddings: Retrieve successful past recommendations to inform new narratives
  • Context injection: Provide agents with relevant historical context for more accurate analysis

Performance Optimization

Challenge: BigQuery queries on large campaign datasets could exceed acceptable latency for conversational UX.

Solution:

  • Redis caching layer for common query patterns
  • Precomputed aggregations for frequently accessed metrics
  • Query result streaming for large datasets
  • Asynchronous agent execution where real-time response not required

Results & Impact

Quantitative Outcomes

  • $40M in attached OKRs: The system became a cornerstone of Roundel's premium insights offering
  • $2k/day immediate spend increase: First manual test of MVP outputs led to advertiser budget increase for campaign duration
  • Set product standard: Established "think beyond a chatbot" approach, influencing product strategy across teams

Qualitative Impact

  1. Shifted from reactive to proactive: Account managers now start their day with curated opportunities rather than drowning in dashboards
  2. Narrative consistency: Data-driven stories replaced ad-hoc pitches, increasing advertiser confidence
  3. Time savings: Eliminated hours of manual data analysis and presentation creation per opportunity

Key Success Factors

  • Agent specialization: Each agent had a narrow, well-defined responsibility (data retrieval, trend detection, narrative, etc.)
  • Context continuity: Session data and activity analysis ensured relevance to account manager's actual workflow
  • Generative UI: Visual components made complex data immediately digestible
  • Autonomous batch processing: Overnight analysis meant managers always had fresh insights

Lessons Learned & Design Principles

1. Agent Boundaries Matter

Early iterations had agents with overlapping responsibilities. Refactoring to single-responsibility agents improved reliability and made debugging exponentially easier.

2. Human-in-the-Loop for High-Stakes Outputs

While the nightly agent generated complete presentations, account managers always reviewed before sending to advertisers. This balance between automation and human judgment was critical for trust.

3. State Persistence is Non-Negotiable

Storing all agent interactions and decisions in MongoDB enabled:

  • Activity-based personalization
  • Debugging and improvement of agent behavior
  • Audit trail for high-value recommendations

4. Cost Management for LLM + Data Systems

  • BigQuery costs were initially higher than expected; caching and query optimization reduced costs by ~60%
  • Prompt engineering to reduce token usage in agent communication
  • Batch processing for non-urgent analysis reduced API costs

Future Enhancements

  • Feedback loop: Capture advertiser responses to recommendations to fine-tune opportunity scoring
  • Multi-modal analysis: Incorporate creative performance (ad imagery, copy) into recommendations
  • Predictive modeling: Move from reactive cap-out detection to predictive budget optimization
  • Cross-platform insights: Extend beyond Roundel to incorporate off-platform advertising data

Conclusion

The Roundel Copilot demonstrates how multi-agent AI systems can transform business intelligence from reactive dashboards to proactive, narrative-driven decision support. By combining real-time conversational exploration with autonomous overnight analysis, the system delivered measurable business impact while establishing a new product paradigm.

The architectural patterns—specialized agents, dynamic SQL generation, generative UI, and session-based personalization—are applicable to any domain requiring complex data analysis and stakeholder communication.

Core Innovation: Moving beyond "chatbot with database access" to a fully autonomous system that thinks, analyzes, and communicates like a senior analyst working overnight to prepare actionable recommendations.


Technical Competencies Demonstrated

  • Multi-agent orchestration (LangGraph, complex state management)
  • LLM tool integration (dynamic SQL generation, function calling)
  • Distributed systems architecture (FastAPI, BigQuery, MongoDB, Redis, Elasticsearch)
  • Generative UI (Vercel AI SDK, server-side React components)
  • RAG implementation (vector embeddings, context injection)
  • Product thinking (MVP prioritization, iterative refinement, stakeholder collaboration)
  • Business impact ($40M OKRs, measurable revenue outcomes)