PYAE1994's picture
Upload folder using huggingface_hub
dd480ef verified
/**
* Intent Interpreter Agent — UPGRADED
* Deeply understands user's workflow request using provider-agnostic LLM Gateway
* NO direct OpenAI dependency
*/
import { type LLMGateway } from '@wfo/integrations/llm-providers/index';
import type { WorkflowIntent } from '../types/workflow';
import { INTENT_INTERPRETER_PROMPT } from '../prompts/intentInterpreter';
export class IntentInterpreterAgent {
private llm: LLMGateway;
constructor(llm: LLMGateway) {
this.llm = llm;
}
async interpret(userRequest: string): Promise<WorkflowIntent> {
const raw = await this.llm.completeJSON<Partial<WorkflowIntent>>([
{ role: 'system', content: INTENT_INTERPRETER_PROMPT },
{
role: 'user',
content: `Analyse this workflow request and return structured JSON:\n\n${userRequest}`,
},
], {
temperature: 0.1,
retries: 3,
});
return this.validateAndNormalize(raw);
}
private validateAndNormalize(raw: Partial<WorkflowIntent>): WorkflowIntent {
return {
workflowType: raw.workflowType ?? 'general',
requiresAI: raw.requiresAI ?? false,
integrations: Array.isArray(raw.integrations) ? raw.integrations : [],
riskLevel: raw.riskLevel ?? 'medium',
requiresHumanApproval: raw.requiresHumanApproval ?? true,
syncVsAsync: raw.syncVsAsync ?? 'sync',
scalingRequirements: raw.scalingRequirements ?? 'low',
identifiedRisks: Array.isArray(raw.identifiedRisks) ? raw.identifiedRisks : [],
estimatedComplexity: raw.estimatedComplexity ?? 'moderate',
domain: raw.domain ?? 'general',
triggerType: raw.triggerType ?? 'webhook',
triggerHint: raw.triggerHint,
};
}
}