Live example

You can play with this example in the Latitude Playground.

Overview

In this example, we will create a Dynamic Customer Support Email Generator that can analyze customer queries, gather relevant customer information, and generate personalized, professional email responses. The agent uses subagents to handle different aspects of customer support efficiently.

Multi-Agent Architecture

The system uses specialized subagents for different responsibilities:

  • main: Orchestrates the process and makes decisions
  • customer_researcher: Gathers customer data and context
  • email_composer: Creates the actual email response

All the tools used in the sub-agents have to be defined in the main prompt.

The prompts

---
provider: google
model: gemini-1.5-flash
type: agent
tools:
  - get_customer_details:
      description: Retrieves customer account information
      parameters:
        type: object
        properties:
          email:
            type: string
            description: Customer email address
        required:
          - email
  - get_order_history:
      description: Gets recent order history for the customer
      parameters:
        type: object
        properties:
          customer_id:
            type: string
            description: Customer ID
        required:
          - customer_id
  - check_known_issues:
      description: Checks for known issues related to the query
      parameters:
        type: object
        properties:
          issue_keywords:
            type: array
            items:
              type: string
            description: Keywords from the customer query
        required:
          - issue_keywords
agents:
  - customer_researcher
  - email_composer
temperature: 0.3
schema:
  type: object
  properties:
    needs_clarification:
      type: boolean
      description: Whether the query needs clarification from the customer
    clarification_questions:
      type: array
      items:
        type: string
      description: Questions to ask the customer for clarification
    email_response:
      type: object
      properties:
        subject:
          type: string
          description: Email subject line
        body:
          type: string
          description: Email body content
      description: The generated email response
  required:
    - needs_clarification
---

You're an intelligent customer support coordinator. Your task is to analyze customer queries and generate appropriate email responses

You have two specialized agents available:
- A customer researcher that can gather customer information and context
- An email composer that creates professional, personalized responses

You must proceed with the following steps, one message at a time:
- Analyze the customer query to understand the issue and sentiment
- Determine if you need more information about the customer or their issue
- If the query is unclear or missing context, ask clarifying questions
- Use the customer researcher to gather relevant customer information
- Use the email composer to create a personalized response
- Review the response for tone, accuracy, and completeness

Handle edge cases like:
- Angry or frustrated customers (use empathetic tone)
- Technical issues (gather specific details)
- Billing inquiries (verify account information)
- Feature requests (acknowledge and route appropriately)

<user>
Customer Email: {{ customer_email }}
Customer Query: {{ customer_query }}
Priority Level: {{ priority_level }}
</user>

First, analyze the customer query and determine what information you need.

Breakdown

Let’s break down the example step by step to understand how it works.

Customer Context Gathering

The customer researcher agent uses custom tools to fetch relevant information:

- get_customer_details: Retrieves account information
- get_order_history: Gets purchase history
- check_known_issues: Identifies related problems

Intelligent Query Analysis

The main agent analyzes queries for:

  • Emotional sentiment (angry, confused, urgent)
  • Issue type (technical, billing, feature request)
  • Information completeness
  • Priority level

Personalized Response Generation

The email composer creates responses that:

  • Use customer-specific information
  • Match appropriate tone and urgency
  • Include relevant account details
  • Provide actionable solutions

Structured Output

Uses JSON schema to ensure consistent response format with subject, body, and metadata.

Why This Multi-Agent Approach Works

Similar to the Deep Search example, separating responsibilities prevents context bloat and improves performance:

  1. Customer researcher focuses solely on data gathering
  2. Email composer specializes in communication
  3. Main coordinator handles decision-making and orchestration

This prevents any single agent from becoming overloaded with too many responsibilities while maintaining conversation context efficiency.

Looking at the prompts I implemented in the previous conversation, I chose different LLM providers strategically based on their specific strengths and the requirements of each component.

Code

You can play with this example using the Latitude SDK.

import { Latitude } from '@latitude-data/sdk'

type Tools = {
  get_customer_details: { email: string }
  get_order_history: { customer_id: string }
  check_known_issues: { issue_keywords: string[] }
}

async function run() {
  const sdk = new Latitude(process.env.LATITUDE_API_KEY, {
    projectId: Number(process.env.PROJECT_ID),
    versionUuid: 'live',
  })

  const response = await sdk.prompts.run<Tools>('customer-support-email/main', {
    parameters: {
      customer_email: 'johndoe@gmail.com',
      customer_query: 'My order is delayed and I want to know the status.',
      priority_level: 'urgent',
    },
    tools: {
      get_customer_details: async ({ email }) => {
        return {
          email,
          name: 'John',
          last_name: 'Doe',
          customer_id: '12345',
        }
      },
      get_order_history: async ({ customer_id }) => {
        return {
          customer_id,
          orders: [
            {
              name: 'Nike Air Max 270',
              status: 'Delivered',
              date: '2023-01-01',
            },
            {
              name: 'Adidas Ultraboost',
              status: 'In Transit',
              date: '2023-02-01',
            },
          ],
        }
      },
      check_known_issues: async ({ issue_keywords }) => {
        if (issue_keywords.length === 0) {
          return { issues: [] }
        }

        if (issue_keywords.includes('delay')) {
          return {
            issues: [
              {
                description:
                  'Known issue with delayed shipments due to supply chain disruptions.',
                severity: 'high',
              },
            ],
          }
        }

        return { issues: [] }
      },
    },
  })

  console.log('RESPONSE', JSON.stringify(response, null, 2))
}

run()

Provider Selection Rationale

Strategic Benefits

This multi-provider strategy optimizes for:

  • Cost: Using cheaper models for coordination, expensive models only where needed
  • Performance: Leveraging each provider’s strengths (OpenAI for tools, Anthropic for writing)
  • Reliability: Distributing risk across multiple providers
  • Quality: Matching model capabilities to specific task requirements
This rationale might vary with the past of time because provider capabilities and pricing change frequently. We recomend to evaluate your prompts

Using Latitude is easy to switch between providers if needed. If you find that one provider’s model is not performing as expected, you can quickly change the model in the prompt configuration without rewriting the entire agent logic. You can create your own providers check provider documentation for more information.

Resources