import { createWorkflow, Agent, openai } from '@runflow-ai/sdk';
import { z } from 'zod';
// Sentiment analyzer
const sentimentAgent = new Agent({
name: 'Sentiment Analyzer',
instructions: 'Analyze feedback sentiment (positive/neutral/negative) and extract key themes.',
model: openai('gpt-4o-mini'),
});
// Action recommender
const actionAgent = new Agent({
name: 'Action Recommender',
instructions: 'Recommend specific actions based on feedback analysis.',
model: openai('gpt-4o'),
});
const feedbackWorkflow = createWorkflow({
id: 'feedback-analysis',
inputSchema: z.object({
feedback: z.string(),
customerEmail: z.string(),
customerName: z.string(),
source: z.string(),
}),
outputSchema: z.any(),
})
// Analyze sentiment
.agent('analyze', sentimentAgent, {
promptTemplate: 'Analyze: {{input.feedback}}',
})
// Recommend actions
.agent('recommend', actionAgent, {
promptTemplate: `Feedback: {{input.feedback}}
Sentiment: {{analyze.text}}
What actions should we take?`,
})
// Conditional: Create ticket if negative
.condition(
'check-negative',
(ctx) => ctx.stepResults.get('analyze').text.toLowerCase().includes('negative'),
// Negative feedback path
[
{
id: 'create-ticket',
type: 'connector',
config: {
connector: 'hubspot',
resource: 'tickets',
action: 'create',
parameters: {
subject: 'Negative Feedback - {{input.customerName}}',
content: '{{input.feedback}}\n\nAnalysis: {{analyze.text}}\n\nRecommended actions: {{recommend.text}}',
priority: 'high',
category: 'feedback',
},
},
},
],
// Positive/neutral feedback path
[
{
id: 'log-positive',
type: 'function',
config: {
execute: async (input, ctx) => {
console.log('Positive feedback logged');
return { logged: true };
},
},
},
]
)
.build();
// Process feedback
const result = await feedbackWorkflow.execute({
feedback: 'The support team was unhelpful and the product is buggy',
customerEmail: 'unhappy@customer.com',
customerName: 'Jane Doe',
source: 'email',
});