Skip to content

Commit c3e10fe

Browse files
authored
Merge pull request #47 from openai/f/add-supervisor-agent-demo
Add customerServiceWithSupervision example
2 parents e843464 + ca22e32 commit c3e10fe

File tree

11 files changed

+568
-8
lines changed

11 files changed

+568
-8
lines changed

src/app/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ function App() {
248248
? null
249249
: {
250250
type: "server_vad",
251-
threshold: 0.5,
251+
threshold: 0.9,
252252
prefix_padding_ms: 300,
253-
silence_duration_ms: 200,
253+
silence_duration_ms: 500,
254254
create_response: true,
255255
};
256256

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import { AgentConfig } from "@/app/types";
2+
import { getNextResponse } from "./supervisorAgent";
3+
4+
const mainAgentInstructions = `
5+
You are a helpful junior customer service agent. Your task is to help a customer resolve a user's issue in a way that's helpful, efficient, and correct, deferring heavily to the supervisor agent.
6+
7+
# General Instructions
8+
- You are very new and can only handle basic tasks, and will rely heavily on the supervisor agent via the getNextResponse tool
9+
- By default, you must always use the getNextResponse tool to get your next response, except for very specific exceptions.
10+
- You represent a company called NewTelco.
11+
- Maintain an extremely professional, unexpressive, and to-the-point tone at all times.
12+
- Always greet the user with "Hi, you've reached NewTelco, how can I help you?"
13+
- If the user says "hi", "hello", or similar greetings in later messages, respond naturally and briefly (e.g., "Hello!" or "Hi there!") instead of repeating the canned greeting.
14+
- In general, don't say the same thing twice, always vary it to ensure the conversation feels natural.
15+
- Do not use any of the information or values from the examples as a reference in conversation.
16+
17+
# Tools
18+
- You can ONLY call getNextResponse
19+
- Even if you're provided other tools in this prompt as a reference, NEVER call them directly.
20+
21+
# Allow List of Permitted Actions
22+
You can take the following actions directly, and don't need to use getNextReseponse for these.
23+
24+
## Basic chitchat
25+
- Handle greetings (e.g., "hello", "hi there").
26+
- Engage in basic chitchat (e.g., "how are you?", "thank you").
27+
- Respond to requests to repeat or clarify information (e.g., "can you repeat that?").
28+
29+
## Collect information for supervisor agent tool calls
30+
- Request user information needed to call tools. Refer to the Supervisor Tools section below for the full definitions and schema.
31+
32+
### Supervisor Agent Tools
33+
NEVER call these tools directly, these are only provided as a reference for collecting parameters for the supervisor model to use.
34+
35+
lookupPolicyDocument:
36+
description: Look up internal documents and policies by topic or keyword.
37+
params:
38+
topic: string (required) - The topic or keyword to search for.
39+
40+
getUserAccountInfo:
41+
description: Get user account and billing information (read-only).
42+
params:
43+
phone_number: string (required) - User's phone number.
44+
45+
findNearestStore:
46+
description: Find the nearest store location given a zip code.
47+
params:
48+
zip_code: string (required) - The customer's 5-digit zip code.
49+
50+
**You must NOT answer, resolve, or attempt to handle ANY other type of request, question, or issue directly. For absolutely everything else, you MUST use the getNextResponse tool to get your response. This includes ANY factual, account-specific, or process-related questions, no matter how minor they may seem.**
51+
52+
# getNextResponse Usage
53+
- For ALL requests that are not strictly and explicitly listed above, you MUST ALWAYS use the getNextResponse tool, which will ask the supervisor agent for a high-quality response you can use.
54+
- For example, this could be to answer factual questions about accounts or business processes, or asking to take actions.
55+
- Do NOT attempt to answer, resolve, or speculate on any other requests, even if you think you know the answer or it seems simple.
56+
- You should make NO assumptions about what you can or can't do. Always defer to getNextResponse() for all non-trivial queries.
57+
- Before calling getNextResponse, you MUST ALWAYS say something to the user (see the 'Sample Filler Phrases' section). Never call getNextResponse without first saying something to the user.
58+
- Filler phrases must NOT indicate whether you can or cannot fulfill an action; they should be neutral and not imply any outcome.
59+
- After the filler phrase YOU MUST ALWAYS call the getNextResponse tool.
60+
- This is required for every use of getNextResponse, without exception. Do not skip the filler phrase, even if the user has just provided information or context.
61+
- You will use this tool extensively.
62+
63+
## How getNextResponse Works
64+
- This asks supervisorAgent what to do next. supervisorAgent is a more senior, more intelligent and capable agent that has access to the full conversation transcript so far and can call the above functions.
65+
- You must provide it with key context, ONLY from the most recent user message, as the supervisor may not have access to that message.
66+
- This should be as concise as absolutely possible, and can be an empty string if no salient information is in the last user message.
67+
- That agent then analyzes the transcript, potentially calls functions to formulate an answer, and then provides a high-quality answer, which you should read verbatim
68+
69+
# Sample Filler Phrases
70+
- "Just a second."
71+
- "Let me check."
72+
- "One moment."
73+
- "Let me look into that."
74+
- "Give me a moment."
75+
- "Let me see."
76+
77+
# Example
78+
- User: "Hi"
79+
- Assistant: "Hi, you've reached NewTelco, how can I help you?"
80+
- User: "I'm wondering why my recent bill was so high"
81+
- Assistant: "Sure, may I have your phone number so I can look that up?"
82+
- User: 206 135 1246
83+
- Assistant: "Okay, let me look into that" // Required filler phrase
84+
- getNextResponse(relevantContextFromLastUserMessage="Phone number is 206 123 1246)
85+
- getNextResponse(): "# Message\nOkay, I've pulled that up. Your last bill was $xx.xx, mainly due to $y.yy in international calls and $z.zz in data overage. Does that make sense?"
86+
- Assistant: "Okay, I've pulled that up. It looks like your last bill was $xx.xx, which is higher than your usual amount because of $x.xx in international calls and $x.xx in data overage charges. Does that make sense?"
87+
- User: "Okay, yes, thank you."
88+
- Assistant: "Of course, please let me know if I can help with anything else."
89+
- User: "Actually, I'm wondering if my address is up to date, what address do you have on file?"
90+
- Assistant: "1234 Pine St. in Seattle, is that your latest?"
91+
- User: "Yes, looks good, thank you"
92+
- Assistant: "Great, anything else I can help with?"
93+
- User: "Nope that's great, bye!"
94+
- Assistant: "Of course, thanks for calling NewTelco!"
95+
96+
# Additional Example (Filler Phrase Before getNextResponse)
97+
- User: "Can you tell me what my current plan includes?"
98+
- Assistant: "One moment."
99+
- getNextResponse(relevantContextFromLastUserMessage="Wants to know what current plan includes")
100+
- getNextResponse(): "# Message\nYour current plan includes unlimited talk and text, plus 10GB of data per month. Would you like more details or information about upgrading?"
101+
- Assistant: "Your current plan includes unlimited talk and text, plus 10GB of data per month. Would you like more details or information about upgrading?"
102+
`;
103+
104+
const mainAgent: AgentConfig = {
105+
name: "mainAgent",
106+
publicDescription: "Customer service agent for NewTelco.",
107+
instructions: mainAgentInstructions,
108+
tools: [
109+
{
110+
type: "function",
111+
name: "getNextResponse",
112+
description:
113+
"Determines the next response whenever the agent faces a non-trivial decision, produced by a highly intelligent supervisor agent. Returns a message describing what to do next.",
114+
parameters: {
115+
type: "object",
116+
properties: {
117+
relevantContextFromLastUserMessage: {
118+
type: "string",
119+
description:
120+
"Key information from the user described in their most recent message. This is critical to provide as the supervisor agent with full context as the last message might not be available.",
121+
},
122+
},
123+
required: ["relevantContextFromLastUserMessage"],
124+
additionalProperties: false,
125+
},
126+
},
127+
],
128+
toolLogic: {
129+
getNextResponse,
130+
},
131+
downstreamAgents: [],
132+
};
133+
134+
const agents = [mainAgent];
135+
136+
export default agents;
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
export const exampleAccountInfo = {
2+
accountId: "NT-123456",
3+
name: "Alex Johnson",
4+
phone: "+1-206-135-1246",
5+
6+
plan: "Unlimited Plus",
7+
balanceDue: "$42.17",
8+
lastBillDate: "2024-05-15",
9+
lastPaymentDate: "2024-05-20",
10+
lastPaymentAmount: "$42.17",
11+
status: "Active",
12+
address: {
13+
street: "1234 Pine St",
14+
city: "Seattle",
15+
state: "WA",
16+
zip: "98101"
17+
},
18+
lastBillDetails: {
19+
basePlan: "$30.00",
20+
internationalCalls: "$8.00",
21+
dataOverage: "$4.00",
22+
taxesAndFees: "$0.17",
23+
notes: "Higher than usual due to international calls and data overage."
24+
}
25+
};
26+
27+
export const examplePolicyDocs = [
28+
{
29+
id: "ID-010",
30+
name: "Family Plan Policy",
31+
topic: "family plan options",
32+
content:
33+
"The family plan allows up to 5 lines per account. All lines share a single data pool. Each additional line after the first receives a 10% discount. All lines must be on the same account.",
34+
},
35+
{
36+
id: "ID-020",
37+
name: "Promotions and Discounts Policy",
38+
topic: "promotions and discounts",
39+
content:
40+
"The Summer Unlimited Data Sale provides a 20% discount on the Unlimited Plus plan for the first 6 months for new activations completed by July 31, 2024. The Refer-a-Friend Bonus provides a $50 bill credit to both the referring customer and the new customer after 60 days of active service, for activations by August 31, 2024. A maximum of 5 referral credits may be earned per account. Discounts cannot be combined with other offers.",
41+
},
42+
{
43+
id: "ID-030",
44+
name: "International Plans Policy",
45+
topic: "international plans",
46+
content:
47+
"International plans are available and include discounted calling, texting, and data usage in over 100 countries.",
48+
},
49+
{
50+
id: "ID-040",
51+
name: "Handset Offers Policy",
52+
topic: "new handsets",
53+
content:
54+
"Handsets from brands such as iPhone, Samsung, and Google are available. Special pricing may be available for new activations or upgrades. For current offers, refer to the website or a retail location.",
55+
},
56+
];
57+
58+
export const exampleStoreLocations = [
59+
// NorCal
60+
{
61+
name: "NewTelco San Francisco Downtown Store",
62+
address: "1 Market St, San Francisco, CA",
63+
zip_code: "94105",
64+
phone: "(415) 555-1001",
65+
hours: "Mon-Sat 10am-7pm, Sun 11am-5pm"
66+
},
67+
{
68+
name: "NewTelco San Jose Valley Fair Store",
69+
address: "2855 Stevens Creek Blvd, Santa Clara, CA",
70+
zip_code: "95050",
71+
phone: "(408) 555-2002",
72+
hours: "Mon-Sat 10am-8pm, Sun 11am-6pm"
73+
},
74+
{
75+
name: "NewTelco Sacramento Midtown Store",
76+
address: "1801 L St, Sacramento, CA",
77+
zip_code: "95811",
78+
phone: "(916) 555-3003",
79+
hours: "Mon-Sat 10am-7pm, Sun 12pm-5pm"
80+
},
81+
// SoCal
82+
{
83+
name: "NewTelco Los Angeles Hollywood Store",
84+
address: "6801 Hollywood Blvd, Los Angeles, CA",
85+
zip_code: "90028",
86+
phone: "(323) 555-4004",
87+
hours: "Mon-Sat 10am-9pm, Sun 11am-7pm"
88+
},
89+
{
90+
name: "NewTelco San Diego Gaslamp Store",
91+
address: "555 5th Ave, San Diego, CA",
92+
zip_code: "92101",
93+
phone: "(619) 555-5005",
94+
hours: "Mon-Sat 10am-8pm, Sun 11am-6pm"
95+
},
96+
{
97+
name: "NewTelco Irvine Spectrum Store",
98+
address: "670 Spectrum Center Dr, Irvine, CA",
99+
zip_code: "92618",
100+
phone: "(949) 555-6006",
101+
hours: "Mon-Sat 10am-8pm, Sun 11am-6pm"
102+
},
103+
// East Coast
104+
{
105+
name: "NewTelco New York City Midtown Store",
106+
address: "350 5th Ave, New York, NY",
107+
zip_code: "10118",
108+
phone: "(212) 555-7007",
109+
hours: "Mon-Sat 9am-8pm, Sun 10am-6pm"
110+
},
111+
{
112+
name: "NewTelco Boston Back Bay Store",
113+
address: "800 Boylston St, Boston, MA",
114+
zip_code: "02199",
115+
phone: "(617) 555-8008",
116+
hours: "Mon-Sat 10am-7pm, Sun 12pm-6pm"
117+
},
118+
{
119+
name: "NewTelco Washington DC Georgetown Store",
120+
address: "1234 Wisconsin Ave NW, Washington, DC",
121+
zip_code: "20007",
122+
phone: "(202) 555-9009",
123+
hours: "Mon-Sat 10am-7pm, Sun 12pm-5pm"
124+
},
125+
{
126+
name: "NewTelco Miami Beach Store",
127+
address: "1601 Collins Ave, Miami Beach, FL",
128+
zip_code: "33139",
129+
phone: "(305) 555-1010",
130+
hours: "Mon-Sat 10am-8pm, Sun 11am-6pm"
131+
}
132+
];

0 commit comments

Comments
 (0)