agency-x
Version:
This project is a Claude-compatible, LLM-agnostic sub-agent framework that simulates a complete SaaS product team. It is delivered as a reusable, developer-ready NPM package.
40 lines (33 loc) • 1.3 kB
text/typescript
import { createLogger } from '../utils/logger';
import { getContext, updateContext } from '../utils/contextStore';
import { getLlmClient } from '../llm/llmRouter';
import { copywriterPrompt, jsonRepairPrompt } from '../utils/promptTemplates';
const logger = createLogger('copywriter');
export const runCopywriter = async () => {
logger.start();
const context = getContext();
const { spec, agents } = context;
const llmClient = getLlmClient();
const prompt = copywriterPrompt
.replace('{{spec}}', JSON.stringify(spec, null, 2))
.replace('{{frontendCode}}', agents.frontendDeveloper.output);
let response = await llmClient.generate(prompt);
let copy;
try {
copy = JSON.parse(response);
} catch (error) {
logger.error('Invalid JSON response from LLM. Attempting to repair...');
const repairPrompt = jsonRepairPrompt.replace('{{invalidJson}}', response);
response = await llmClient.generate(repairPrompt);
try {
copy = JSON.parse(response);
} catch (error) {
logger.error('Failed to repair JSON response. Skipping copy generation.');
return;
}
}
updateContext({ agents: { ...context.agents, copywriter: { output: copy, completed: true } } });
logger.stop();
logger.success('Generated microcopy.');
return copy;
};