-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy path70-ce-support-agent.ts
More file actions
386 lines (351 loc) · 11.4 KB
/
Copy path70-ce-support-agent.ts
File metadata and controls
386 lines (351 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/**
* 70 - Customer Engineering Support Agent.
*
* Takes a Zendesk ticket number and investigates across Zendesk, JIRA,
* HubSpot, Notion (runbooks), and GitHub to produce a solution with a
* priority rating.
*
* Required credentials (set via `conductor secret put`):
* ZENDESK_SUBDOMAIN, ZENDESK_EMAIL, ZENDESK_API_TOKEN
* JIRA_BASE_URL, JIRA_EMAIL, JIRA_API_TOKEN
* HUBSPOT_ACCESS_TOKEN
* NOTION_API_KEY, NOTION_RUNBOOK_DB_ID
* GITHUB_TOKEN, GITHUB_ORG
*
* Requirements:
* - Conductor server
* - CONDUCTOR_SERVER_URL=http://localhost:8080/api
* - CONDUCTOR_AGENT_LLM_MODEL=openai/gpt-4o-mini
*/
import { Agent, AgentRuntime, RegexGuardrail, agentTool, tool } from '@io-orkes/conductor-javascript/agents';
import { llmModel } from './settings';
// -- Credential lists --------------------------------------------------------
const ZENDESK_CREDS = ['ZENDESK_SUBDOMAIN', 'ZENDESK_EMAIL', 'ZENDESK_API_TOKEN'];
const JIRA_CREDS = ['JIRA_BASE_URL', 'JIRA_EMAIL', 'JIRA_API_TOKEN'];
const HUBSPOT_CREDS = ['HUBSPOT_ACCESS_TOKEN'];
const NOTION_CREDS = ['NOTION_API_KEY', 'NOTION_RUNBOOK_DB_ID'];
const GITHUB_CREDS = ['GITHUB_TOKEN', 'GITHUB_ORG'];
const ALL_CREDS = [...ZENDESK_CREDS, ...JIRA_CREDS, ...HUBSPOT_CREDS, ...NOTION_CREDS, ...GITHUB_CREDS];
// -- Zendesk tools -----------------------------------------------------------
const getZendeskTicket = tool(
async (args: { ticketId: string }) => {
// In production, this would call the Zendesk API
return { id: args.ticketId, subject: 'API timeout errors', status: 'open', priority: 'high' };
},
{
name: 'get_zendesk_ticket',
description: 'Fetch a Zendesk support ticket by its ID.',
inputSchema: {
type: 'object',
properties: {
ticketId: { type: 'string' },
},
required: ['ticketId'],
},
credentials: ZENDESK_CREDS,
},
);
const searchZendeskTickets = tool(
async (args: { query: string }) => {
return { count: 0, tickets: [] };
},
{
name: 'search_zendesk_tickets',
description: 'Search Zendesk for tickets matching a query.',
inputSchema: {
type: 'object',
properties: {
query: { type: 'string' },
},
required: ['query'],
},
credentials: ZENDESK_CREDS,
},
);
// -- JIRA tools --------------------------------------------------------------
const searchJiraIssues = tool(
async (args: { jql: string }) => {
return { total: 0, issues: [] };
},
{
name: 'search_jira_issues',
description: 'Search JIRA issues using JQL.',
inputSchema: {
type: 'object',
properties: {
jql: { type: 'string' },
},
required: ['jql'],
},
credentials: JIRA_CREDS,
},
);
const getJiraIssue = tool(
async (args: { issueKey: string }) => {
return { key: args.issueKey, summary: 'Not found', status: 'unknown' };
},
{
name: 'get_jira_issue',
description: 'Get full details of a specific JIRA issue.',
inputSchema: {
type: 'object',
properties: {
issueKey: { type: 'string' },
},
required: ['issueKey'],
},
credentials: JIRA_CREDS,
},
);
// -- HubSpot tools -----------------------------------------------------------
const searchHubspotCompany = tool(
async (args: { companyName: string }) => {
return { count: 0, companies: [] };
},
{
name: 'search_hubspot_company',
description: 'Search HubSpot for a company by name.',
inputSchema: {
type: 'object',
properties: {
companyName: { type: 'string' },
},
required: ['companyName'],
},
credentials: HUBSPOT_CREDS,
},
);
const getHubspotContact = tool(
async (args: { email: string }) => {
return { id: null, name: '', email: args.email };
},
{
name: 'get_hubspot_contact',
description: 'Look up a HubSpot contact by email address.',
inputSchema: {
type: 'object',
properties: {
email: { type: 'string' },
},
required: ['email'],
},
credentials: HUBSPOT_CREDS,
},
);
// -- Notion tools ------------------------------------------------------------
const searchNotionRunbooks = tool(
async (args: { query: string }) => {
return { count: 0, runbooks: [] };
},
{
name: 'search_notion_runbooks',
description: 'Search Notion runbooks database for articles matching a query.',
inputSchema: {
type: 'object',
properties: {
query: { type: 'string' },
},
required: ['query'],
},
credentials: NOTION_CREDS,
},
);
const getNotionPageContent = tool(
async (args: { pageId: string }) => {
return { page_id: args.pageId, content: '' };
},
{
name: 'get_notion_page_content',
description: 'Retrieve the full content of a Notion page/runbook by its ID.',
inputSchema: {
type: 'object',
properties: {
pageId: { type: 'string' },
},
required: ['pageId'],
},
credentials: NOTION_CREDS,
},
);
// -- GitHub tools ------------------------------------------------------------
const searchGithubIssues = tool(
async (args: { query: string; repo?: string }) => {
return { total_count: 0, items: [] };
},
{
name: 'search_github_issues',
description: 'Search GitHub issues and pull requests.',
inputSchema: {
type: 'object',
properties: {
query: { type: 'string' },
repo: { type: 'string' },
},
required: ['query'],
},
credentials: GITHUB_CREDS,
},
);
const searchGithubCode = tool(
async (args: { query: string; repo?: string }) => {
return { total_count: 0, files: [] };
},
{
name: 'search_github_code',
description: "Search GitHub code across the organization's repositories.",
inputSchema: {
type: 'object',
properties: {
query: { type: 'string' },
repo: { type: 'string' },
},
required: ['query'],
},
credentials: GITHUB_CREDS,
},
);
const getGithubReleases = tool(
async (args: { repo: string; limit?: number }) => {
return { repo: args.repo, releases: [] };
},
{
name: 'get_github_releases',
description: 'Get recent releases for a GitHub repository.',
inputSchema: {
type: 'object',
properties: {
repo: { type: 'string' },
limit: { type: 'number' },
},
required: ['repo'],
},
credentials: GITHUB_CREDS,
},
);
const getGithubPullRequest = tool(
async (args: { repo: string; prNumber: number }) => {
return { number: args.prNumber, title: 'Not found', state: 'unknown' };
},
{
name: 'get_github_pull_request',
description: 'Get details of a specific GitHub pull request.',
inputSchema: {
type: 'object',
properties: {
repo: { type: 'string' },
prNumber: { type: 'number' },
},
required: ['repo', 'prNumber'],
},
credentials: GITHUB_CREDS,
},
);
// -- PII guardrail -----------------------------------------------------------
const piiGuardrail = new RegexGuardrail({
name: 'ce_support_pii_guardrail',
patterns: [
'\\b\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}\\b', // credit card
'\\b\\d{3}-\\d{2}-\\d{4}\\b', // SSN
],
mode: 'block',
position: 'output',
onFail: 'retry',
message: 'Do not include credit card numbers or SSNs in the output. Redact any PII.',
});
// -- Agent definitions -------------------------------------------------------
export const zendeskAgent = new Agent({
name: 'zendesk_investigator',
model: llmModel,
instructions:
'You are a Zendesk specialist. Fetch the given ticket and extract the core issue. ' +
'Search for similar/related tickets to identify patterns.',
tools: [getZendeskTicket, searchZendeskTickets],
credentials: ZENDESK_CREDS,
});
export const jiraAgent = new Agent({
name: 'jira_investigator',
model: llmModel,
instructions:
'You are a JIRA specialist. Search for related engineering tickets. ' +
'Check if there\'s an existing fix in progress.',
tools: [searchJiraIssues, getJiraIssue],
credentials: JIRA_CREDS,
});
export const hubspotAgent = new Agent({
name: 'hubspot_investigator',
model: llmModel,
instructions:
'You are a HubSpot CRM specialist. Look up the company and contact. ' +
'Return plan tier, ARR, lifecycle stage, and account owner.',
tools: [searchHubspotCompany, getHubspotContact],
credentials: HUBSPOT_CREDS,
});
export const runbookAgent = new Agent({
name: 'runbook_searcher',
model: llmModel,
instructions:
'You are a Notion runbook specialist. Search for runbooks matching the symptoms. ' +
'Read the most relevant ones for resolution instructions.',
tools: [searchNotionRunbooks, getNotionPageContent],
credentials: NOTION_CREDS,
});
export const githubAgent = new Agent({
name: 'github_investigator',
model: llmModel,
instructions:
'You are a GitHub code specialist. Search for related issues, PRs, and code. ' +
'Check recent releases for fixes or regressions.',
tools: [searchGithubIssues, searchGithubCode, getGithubReleases, getGithubPullRequest],
credentials: GITHUB_CREDS,
});
const ORCHESTRATOR_INSTRUCTIONS =
'You are a Customer Engineering Support Agent. Investigate a Zendesk ' +
'support ticket and deliver a comprehensive analysis with a prioritized solution.\n\n' +
'WORKFLOW:\n' +
'1. Use the zendesk_investigator to fetch the ticket and find related tickets\n' +
'2. In PARALLEL, use the other investigators to gather context\n' +
'3. Synthesize all findings into a solution\n\n' +
'PRIORITY GUIDE:\n' +
'- P0: Production down for enterprise customer, data loss, security breach\n' +
'- P1: Major feature broken for high-tier customer, significant revenue impact\n' +
'- P2: Important feature degraded, workaround exists but painful\n' +
'- P3: Non-critical feature issue, minor inconvenience\n' +
'- P4: Enhancement request, cosmetic issue, documentation question';
export const ceSupportAgent = new Agent({
name: 'ce_support_agent',
model: llmModel,
instructions: ORCHESTRATOR_INSTRUCTIONS,
tools: [
agentTool(zendeskAgent, { description: 'Investigate the Zendesk ticket' }),
agentTool(hubspotAgent, { description: 'Look up customer context in HubSpot' }),
agentTool(jiraAgent, { description: 'Search JIRA for related engineering issues' }),
agentTool(runbookAgent, { description: 'Search Notion runbooks for resolution procedures' }),
agentTool(githubAgent, { description: 'Search GitHub for related issues, PRs, code, and releases' }),
],
credentials: ALL_CREDS,
guardrails: [piiGuardrail.toGuardrailDef()],
maxTurns: 15,
temperature: 0.2,
});
// -- Run ---------------------------------------------------------------------
const ticketId = process.argv[2] ?? '12345';
const prompt = `Investigate Zendesk ticket #${ticketId} and provide a full analysis with solution and priority.`;
async function main() {
const runtime = new AgentRuntime();
try {
console.log(`\n--- Investigating ticket #${ticketId} ---\n`);
const result = await runtime.run(ceSupportAgent, prompt);
result.printResult();
// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(ceSupportAgent);
// CLI alternative:
// conductor deploy --package examples/agents --agents ce_support_agent
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(ceSupportAgent);
} finally {
await runtime.shutdown();
}
}
main().catch(console.error);