import { identify, startExecution, log } from '@runflow-ai/sdk/observability';
export async function analyzeDocument(docId: string) {
// 1. Identify context
identify({ type: 'document', value: docId });
// 2. Start custom execution
const exec = startExecution({
name: 'document-analysis',
input: { documentId: docId }
});
try {
// 3. Process with LLM calls
const llm = LLM.openai('gpt-4o');
const text = await llm.chat("Extract text from document...");
exec.log('text_extracted', { length: text.length });
const category = await llm.chat(`Classify this: ${text}`);
exec.log('document_classified', { category });
const summary = await llm.chat(`Summarize: ${text}`);
// 4. Finish with custom output
await exec.end({
output: {
summary,
category,
documentId: docId
}
});
return { summary, category };
} catch (error) {
exec.setError(error);
await exec.end();
throw error;
}
}