01import Anthropic from '@anthropic-ai/sdk';
02import { FacebookAdsClient } from '../../shared/clients/facebook-ads';
03import { ClientRecord } from '../../shared/clients/supabase';
04import { getBenchmark, getCplStatus } from './benchmarks';
05import { evaluateAdRules, evaluateAdSetRules } from './rules';
06import { identifyScalingCandidates, detectCreativeFatigue } from './strategies';
07
08export class MetaAdsAnalyzer {
09 private anthropic: Anthropic | null = null;
10
11 async analyzeClient(client: ClientRecord): Promise {
12 logger.info({ clientId: client.id }, 'Starting Meta ads analysis');
13
14 // Layer 2: Read intel from OTHER agents about this client
15 const otherIntel = await readClientIntel(client.id, "meta-ads-engineer");
16 const crossAgentContext = otherIntel.map(
17 i => `[${i.agent_name}] ${i.intel_type}: ${i.summary}`
18 ).join("\n");
19
20 // Fetch campaign data from Meta Ads API
21 const campaigns = await this.facebookClient.getCampaigns(client.ad_account_id);
22 const adSets = await this.facebookClient.getAdSets(client.ad_account_id);
23
24 // Claude Opus 4.6 deep analysis with cross-agent context
25 const analysis = await this.anthropic.messages.create({
26 model: 'claude-opus-4-6-20260301',