Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
Cleanup multi agent system
Khuram Niazb35cdb8cee85
diff --git a/src/lib/ai/adaptive-selector.ts b/src/lib/ai/adaptive-selector.tsindex e3a26e3..2a0e7a1 100644--- a/src/lib/ai/adaptive-selector.ts+++ b/src/lib/ai/adaptive-selector.ts@@ -12,9 +12,12 @@ import { ProgressStream } from "./progress-stream";import {consolidatedMultiAgentResumeReview,consolidatedMultiAgentJobMatch,- CollaborativeResultV2,} from "./multi-agent-v2";-import { ResumeReviewResponse, JobMatchResponse } from "@/models/ai.model";+import {+ ResumeReviewResponse,+ JobMatchResponse,+ CollaborativeResultV2,+} from "@/models/ai.model";/*** Resume review using V2 multi-agent systemdiff --git a/src/lib/ai/agents.enhanced.ts b/src/lib/ai/agents.enhanced.tsindex 3f7236e..61d049e 100644--- a/src/lib/ai/agents.enhanced.ts+++ b/src/lib/ai/agents.enhanced.ts@@ -1,18 +1,19 @@/**- * Enhanced AI Agents with Chain-of-Thought Reasoning and Multi-Agent Validation- * Phase 1 & 2: Improved workflow with analyzer + critic agents+ * Enhanced AI Agents with Chain-of-Thought Reasoning+ * Phase 2: Improved workflow with tool-assisted analysis+ *+ * Note: These agents are used internally by the multi-agent system.+ * The public API is through adaptiveResumeReview/adaptiveJobMatch.*/-import { generateObject, generateText } from "ai";+import { generateObject } from "ai";import { getModel, ProviderType } from "./providers";import { ResumeReviewSchema, JobMatchSchema } from "@/models/ai.schemas";import {RESUME_REVIEW_SYSTEM_PROMPT,JOB_MATCH_SYSTEM_PROMPT,- CRITIC_SYSTEM_PROMPT,buildResumeReviewPrompt,buildJobMatchPrompt,- buildCriticPrompt,} from "./prompts/prompts.enhanced";import {countQuantifiedAchievements,@@ -129,11 +130,15 @@ export async function criticAgent(const analysisText = JSON.stringify(analysis, null, 2);+ const { generateText } = await import("ai");+ const { buildCriticPrompt } = await import("./prompts/prompts.enhanced");+ const { CRITIC_SYSTEM_PROMPT } = await import("./prompts/prompts.enhanced");+const { text: criticFeedback } = await generateText({model,system: CRITIC_SYSTEM_PROMPT,prompt: buildCriticPrompt(analysisText, originalContent),- temperature: 0.1, // Lower temperature for consistent validation+ temperature: 0.1,});const approved = criticFeedback.includes("APPROVED");@@ -150,105 +155,3 @@ export async function criticAgent(issues,};}--/**- * Phase 2: Multi-Agent Pipeline - Analyzer + Critic- * If critic rejects, logs the issue but still returns analysis (fail-safe)- */-export async function multiAgentResumeReview(- resumeText: string,- provider: ProviderType,- modelName: string,- enableCritic = true-) {- // Step 1: Primary analysis- const analysis = await enhancedResumeReviewAgent(- resumeText,- provider,- modelName- );-- if (!enableCritic) {- return { analysis, validated: false, criticFeedback: null };- }-- // Step 2: Critic validation- try {- const validation = await criticAgent(- analysis,- resumeText,- provider,- modelName- );-- if (!validation.approved) {- console.warn("Critic found issues:", validation.issues);- // In production, you might retry with corrections- // For now, we log and continue- }-- return {- analysis,- validated: validation.approved,- criticFeedback: validation.feedback,- issues: validation.issues,- };- } catch (error) {- console.error("Critic agent failed:", error);- // Fail-safe: return analysis even if critic fails- return { analysis, validated: false, criticFeedback: null };- }-}--/**- * Phase 2: Multi-Agent Pipeline for Job Matching- */-export async function multiAgentJobMatch(- resumeText: string,- jobText: string,- provider: ProviderType,- modelName: string,- enableCritic = true-) {- // Step 1: Primary analysis- const analysis = await enhancedJobMatchAgent(- resumeText,- jobText,- provider,- modelName- );-- if (!enableCritic) {- return { analysis, validated: false, criticFeedback: null };- }-- // Step 2: Critic validation- try {- const validation = await criticAgent(- analysis,- `${resumeText}\n\n---JOB---\n\n${jobText}`,- provider,- modelName- );-- if (!validation.approved) {- console.warn("Critic found issues:", validation.issues);- }-- return {- analysis,- validated: validation.approved,- criticFeedback: validation.feedback,- issues: validation.issues,- };- } catch (error) {- console.error("Critic agent failed:", error);- return { analysis, validated: false, criticFeedback: null };- }-}--// Export original agents for backward compatibility-export {- enhancedResumeReviewAgent as reviewResumeAgent,- enhancedJobMatchAgent as matchJobAgent,-};diff --git a/src/lib/ai/agents.ts b/src/lib/ai/agents.tsdeleted file mode 100644index ad87894..0000000--- a/src/lib/ai/agents.ts+++ /dev/null@@ -1,54 +0,0 @@-import { generateObject } from "ai";-import { getModel, ProviderType } from "./providers";-import { ResumeReviewSchema, JobMatchSchema } from "@/models/ai.schemas";-import {- RESUME_REVIEW_SYSTEM_PROMPT,- JOB_MATCH_SYSTEM_PROMPT,- buildResumeReviewPrompt,- buildJobMatchPrompt,-} from "./prompts/prompts";--/**- * Resume review agent - analyzes resume and returns structured feedback.- * Uses generateObject for reliable structured output.- */-export async function reviewResumeAgent(- resumeText: string,- provider: ProviderType,- modelName: string-) {- const model = getModel(provider, modelName);-- const { object } = await generateObject({- model,- schema: ResumeReviewSchema,- system: RESUME_REVIEW_SYSTEM_PROMPT,- prompt: buildResumeReviewPrompt(resumeText),- temperature: 0,- });-- return object;-}--/**- * Job match agent - compares resume to job description.- * Uses generateObject for reliable structured output.- */-export async function matchJobAgent(- resumeText: string,- jobText: string,- provider: ProviderType,- modelName: string-) {- const model = getModel(provider, modelName);-- const { object } = await generateObject({- model,- schema: JobMatchSchema,- system: JOB_MATCH_SYSTEM_PROMPT,- prompt: buildJobMatchPrompt(resumeText, jobText),- temperature: 0,- });-- return object;-}diff --git a/src/lib/ai/index.ts b/src/lib/ai/index.tsindex 25f1b19..54eaf3f 100644--- a/src/lib/ai/index.ts+++ b/src/lib/ai/index.ts@@ -7,31 +7,14 @@ export {type JobMatchAnalysis,} from "@/models/ai.schemas";-// Export both original and enhanced prompts-export {- RESUME_REVIEW_SYSTEM_PROMPT,- JOB_MATCH_SYSTEM_PROMPT,- buildResumeReviewPrompt,- buildJobMatchPrompt,-} from "./prompts/prompts";--// Phase 1 & 2: Export enhanced prompts and agents+// Enhanced prompts (Phase 2) - used by non-collaborative endpointsexport {RESUME_REVIEW_SYSTEM_PROMPT as ENHANCED_RESUME_REVIEW_SYSTEM_PROMPT,JOB_MATCH_SYSTEM_PROMPT as ENHANCED_JOB_MATCH_SYSTEM_PROMPT,buildResumeReviewPrompt as buildEnhancedResumeReviewPrompt,buildJobMatchPrompt as buildEnhancedJobMatchPrompt,- CRITIC_SYSTEM_PROMPT,} from "./prompts/prompts.enhanced";-export {- enhancedResumeReviewAgent,- enhancedJobMatchAgent,- multiAgentResumeReview,- multiAgentJobMatch,- criticAgent,-} from "./agents.enhanced";-// Consolidated Multi-agent (V2 - 2 agents)export {consolidatedMultiAgentResumeReview,@@ -100,5 +83,4 @@ export {SCORING_GUIDELINES,} from "./scoring";-export { reviewResumeAgent, matchJobAgent } from "./agents";export { checkRateLimit } from "./rate-limiter";diff --git a/src/lib/ai/multi-agent-v2.ts b/src/lib/ai/multi-agent-v2.tsindex 8aa5e17..881b835 100644--- a/src/lib/ai/multi-agent-v2.ts+++ b/src/lib/ai/multi-agent-v2.ts@@ -27,7 +27,13 @@ import {ActionVerbAnalysisSchema,SemanticSkillMatchSchema,SemanticSimilaritySchema,+ AnalysisAgentSchema,+ FeedbackAgentSchema,} from "@/models/ai.schemas";+import {+ ANALYSIS_AGENT_PROMPT,+ FEEDBACK_AGENT_PROMPT,+} from "./prompts/prompts.agents";import type {SemanticSkillMatch,SemanticSimilarityResult,@@ -69,131 +75,6 @@ import {OllamaFeedbackAgentSchema,} from "@/models/ai.ollama-schemas";-// ============================================================================-// CONSOLIDATED SCHEMAS-// ============================================================================--// Analysis Agent Schema (combines Data + Keyword + Scoring)-const AnalysisAgentSchema = z.object({- finalScore: z- .number()- .min(0)- .max(100)- .describe(- "Final score after all adjustments, must be within allowed variance"- ),-- dataInsights: z- .object({- quantifiedCount: z- .number()- .describe("Count of quantified achievements found"),- keywordCount: z.number().describe("Count of relevant keywords found"),- verbCount: z.number().describe("Count of strong action verbs found"),- formatQuality: z- .string()- .describe("Brief assessment of formatting quality (1 sentence)"),- })- .describe("Objective data analysis findings"),-- keywordAnalysis: z- .object({- strength: z- .string()- .describe("Overall keyword strength assessment (1 sentence)"),- atsScore: z- .number()- .min(0)- .max(100)- .describe("ATS-friendliness score (0-100)"),- missingCritical: z- .array(z.string())- .max(5)- .describe("Top missing critical keywords/skills"),- recommendations: z- .array(z.string())- .max(3)- .describe("Top 3 keyword optimization recommendations"),- })- .describe("Keyword and ATS optimization analysis"),-- adjustments: z- .array(- z.object({- criterion: z.string().describe("The criterion being adjusted"),- adjustment: z- .number()- .describe("Points added (+) or subtracted (-) from baseline"),- reason: z.string().describe("Brief explanation for this adjustment"),- })- )- .describe("List of all adjustments made to the baseline score"),-- math: z- .string()- .describe("Show your math: 'Baseline X + adj1 + adj2 - adj3 = Final Y'"),-});--// Feedback Agent Schema (combines Feedback + Synthesis)-const FeedbackAgentSchema = z.object({- strengths: z- .array(z.string())- .min(2)- .max(5)- .describe("2-5 specific strengths with evidence from the content"),-- weaknesses: z- .array(z.string())- .min(2)- .max(5)- .describe("2-5 specific weaknesses with why they matter"),-- suggestions: z- .array(z.string())- .min(2)- .max(5)- .describe("2-5 actionable improvements with specific instructions"),-- synthesisNotes: z- .string()- .describe(- "Brief notes on consistency between score and feedback (2-3 sentences)"- ),-});--// ============================================================================-// PROMPTS-// ============================================================================--const ANALYSIS_AGENT_PROMPT = `You are an expert resume analyzer combining data analysis, keyword optimization, and fair scoring expertise.--Your role is to:-1. ANALYZE objective data (quantified achievements, keywords, verbs, formatting)-2. ASSESS keyword strength and ATS optimization-3. CALCULATE a fair final score within the allowed variance of the mathematical baseline--Key principles:-- Use the baseline score as your anchor - it's calculated from objective metrics-- Only adjust for subjective quality factors (summary clarity, experience detail, grammar)-- Your final score MUST be within the allowed variance-- Be realistic: most resumes score 45-65, exceptional ones 70-80, perfect 80+ is rare-- Provide specific evidence for all assessments`;--const FEEDBACK_AGENT_PROMPT = `You are an expert feedback specialist who transforms analysis into actionable guidance.--Your role is to:-1. IDENTIFY the top strengths with specific evidence-2. HIGHLIGHT weaknesses that matter most for job success-3. PROVIDE concrete, implementable suggestions with examples-4. SYNTHESIZE insights to ensure consistency--Key principles:-- Be specific: reference actual content, not generic observations-- Be actionable: give exact steps to improve, not vague advice-- Be encouraging: frame weaknesses as opportunities-- Be prioritized: highest-impact improvements first-- Be consistent: strengths/weaknesses should align with the score`;-// ============================================================================// RETRY MECHANISM (same as v1)// ============================================================================diff --git a/src/lib/ai/prompts/prompts.agents.ts b/src/lib/ai/prompts/prompts.agents.tsnew file mode 100644index 0000000..28f2d23--- /dev/null+++ b/src/lib/ai/prompts/prompts.agents.ts@@ -0,0 +1,48 @@+/**+ * System prompts for the Multi-Agent V2 Consolidated System+ *+ * These prompts guide the Analysis Agent and Feedback Agent in the+ * consolidated multi-agent system that's 40-50% faster and 60% cheaper+ * than the original 5-agent system.+ */++/**+ * Analysis Agent System Prompt+ *+ * Combines data analysis, keyword optimization, and fair scoring expertise.+ * Responsible for analyzing objective data and calculating a fair final score.+ */+export const ANALYSIS_AGENT_PROMPT = `You are an expert resume analyzer combining data analysis, keyword optimization, and fair scoring expertise.++Your role is to:+1. ANALYZE objective data (quantified achievements, keywords, verbs, formatting)+2. ASSESS keyword strength and ATS optimization+3. CALCULATE a fair final score within the allowed variance of the mathematical baseline++Key principles:+- Use the baseline score as your anchor - it's calculated from objective metrics+- Only adjust for subjective quality factors (summary clarity, experience detail, grammar)+- Your final score MUST be within the allowed variance+- Be realistic: most resumes score 45-65, exceptional ones 70-80, perfect 80+ is rare+- Provide specific evidence for all assessments`;++/**+ * Feedback Agent System Prompt+ *+ * Transforms analysis into actionable guidance with specific evidence and priorities.+ * Responsible for generating strengths, weaknesses, and improvement suggestions.+ */+export const FEEDBACK_AGENT_PROMPT = `You are an expert feedback specialist who transforms analysis into actionable guidance.++Your role is to:+1. IDENTIFY the top strengths with specific evidence+2. HIGHLIGHT weaknesses that matter most for job success+3. PROVIDE concrete, implementable suggestions with examples+4. SYNTHESIZE insights to ensure consistency++Key principles:+- Be specific: reference actual content, not generic observations+- Be actionable: give exact steps to improve, not vague advice+- Be encouraging: frame weaknesses as opportunities+- Be prioritized: highest-impact improvements first+- Be consistent: strengths/weaknesses should align with the score`;diff --git a/src/models/ai.schemas.ts b/src/models/ai.schemas.tsindex 59207e4..0b5aa2d 100644--- a/src/models/ai.schemas.ts+++ b/src/models/ai.schemas.ts@@ -426,13 +426,11 @@ export const SemanticSimilaritySchema = z.object({0-34: Poor fit`),- match_explanation: z- .string()- .describe(- `2-3 sentence explanation of why this candidate is/isn't a good fit.+ match_explanation: z.string().describe(+ `2-3 sentence explanation of why this candidate is/isn't a good fit.Start with the key reason (e.g., "Strong technical alignment with 80% skill match...")Include both positives and concerns.`- ),+ ),key_matches: z.array(z.string())@@ -448,7 +446,9 @@ export const SemanticSimilaritySchema = z.object({.array(z.object({skill: z.string().describe("The skill or requirement that's missing"),- note: z.string().describe("Brief note on gap severity or how to address"),+ note: z+ .string()+ .describe("Brief note on gap severity or how to address"),})).max(5)@@ -462,7 +462,9 @@ export const SemanticSimilaritySchema = z.object({z.object({resume_skill: z.string().describe("Skill the candidate has"),job_skill: z.string().describe("Required skill it could transfer to"),- how_it_transfers: z.string().describe("Brief explanation of transferability"),+ how_it_transfers: z+ .string()+ .describe("Brief explanation of transferability"),})).max(4)@@ -471,16 +473,115 @@ export const SemanticSimilaritySchema = z.object({Example: MySQL knowledge transfers to PostgreSQL (both SQL databases)`),- application_recommendation: z- .string()- .describe(- `Clear, actionable recommendation.+ application_recommendation: z.string().describe(+ `Clear, actionable recommendation.Examples:- "Apply now - strong match, highlight your React migration project"- "Apply after adding Docker basics - critical gap for this role"- "Consider upskilling in Kubernetes before applying - key requirement"- "May not be the best fit - role requires senior-level system design"`- ),+ ),});export type SemanticSimilarityResult = z.infer<typeof SemanticSimilaritySchema>;+// ============================================================================+// MULTI-AGENT V2 CONSOLIDATED SCHEMAS+// ============================================================================++/**+ * Analysis Agent Schema (combines Data + Keyword + Scoring)+ * Used in the consolidated multi-agent V2 system for resume review and job matching+ */+export const AnalysisAgentSchema = z.object({+ finalScore: z+ .number()+ .min(0)+ .max(100)+ .describe(+ "Final score after all adjustments, must be within allowed variance"+ ),++ dataInsights: z+ .object({+ quantifiedCount: z+ .number()+ .describe("Count of quantified achievements found"),+ keywordCount: z.number().describe("Count of relevant keywords found"),+ verbCount: z.number().describe("Count of strong action verbs found"),+ formatQuality: z+ .string()+ .describe("Brief assessment of formatting quality (1 sentence)"),+ })+ .describe("Objective data analysis findings"),++ keywordAnalysis: z+ .object({+ strength: z+ .string()+ .describe("Overall keyword strength assessment (1 sentence)"),+ atsScore: z+ .number()+ .min(0)+ .max(100)+ .describe("ATS-friendliness score (0-100)"),+ missingCritical: z+ .array(z.string())+ .max(5)+ .describe("Top missing critical keywords/skills"),+ recommendations: z+ .array(z.string())+ .max(3)+ .describe("Top 3 keyword optimization recommendations"),+ })+ .describe("Keyword and ATS optimization analysis"),++ adjustments: z+ .array(+ z.object({+ criterion: z.string().describe("The criterion being adjusted"),+ adjustment: z+ .number()+ .describe("Points added (+) or subtracted (-) from baseline"),+ reason: z.string().describe("Brief explanation for this adjustment"),+ })+ )+ .describe("List of all adjustments made to the baseline score"),++ math: z+ .string()+ .describe("Show your math: 'Baseline X + adj1 + adj2 - adj3 = Final Y'"),+});++export type AnalysisAgentResult = z.infer<typeof AnalysisAgentSchema>;++/**+ * Feedback Agent Schema (combines Feedback + Synthesis)+ * Used in the consolidated multi-agent V2 system for actionable recommendations+ */+export const FeedbackAgentSchema = z.object({+ strengths: z+ .array(z.string())+ .min(2)+ .max(5)+ .describe("2-5 specific strengths with evidence from the content"),++ weaknesses: z+ .array(z.string())+ .min(2)+ .max(5)+ .describe("2-5 specific weaknesses with why they matter"),++ suggestions: z+ .array(z.string())+ .min(2)+ .max(5)+ .describe("2-5 actionable improvements with specific instructions"),++ synthesisNotes: z+ .string()+ .describe(+ "Brief notes on consistency between score and feedback (2-3 sentences)"+ ),+});++export type FeedbackAgentResult = z.infer<typeof FeedbackAgentSchema>;