From c8ca68f13bec93d2ae5103509cd45db511b9b6f1 Mon Sep 17 00:00:00 2001 From: Alex Curley Date: Mon, 11 May 2026 23:07:30 -0400 Subject: [PATCH] Invoke file ID --- netlify/functions/agent-proxy.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/netlify/functions/agent-proxy.js b/netlify/functions/agent-proxy.js index 43a0a4a..1566392 100644 --- a/netlify/functions/agent-proxy.js +++ b/netlify/functions/agent-proxy.js @@ -72,7 +72,17 @@ export default async (req /*, context */) => { return new Response('Server is missing ANTHROPIC_API_KEY', { status: 500 }) } - const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY }) + const client = new Anthropic({ + apiKey: process.env.ANTHROPIC_API_KEY, + // Required while the Files API is in beta. + defaultHeaders: { 'anthropic-beta': 'files-api-2025-04-14' }, + }) + + // File uploaded to the Anthropic Console / Files API that the agent + // should consult on every call. + const KNOWLEDGE_FILE_ID = + process.env.ANTHROPIC_KNOWLEDGE_FILE_ID || + 'file_011Cawv1SPNaknuMmyDtM1S7' const userMessage = `Here is a new public media station intake: @@ -93,7 +103,20 @@ Please draft the funding outlook brief described in your instructions.` model: MODEL, max_tokens: 10000, system: SYSTEM_PROMPT, - messages: [{ role: 'user', content: userMessage }], + messages: [ + { + role: 'user', + content: [ + { + type: 'document', + source: { type: 'file', file_id: KNOWLEDGE_FILE_ID }, + // Lets the model cite the doc in answers. + citations: { enabled: true }, + }, + { type: 'text', text: userMessage }, + ], + }, + ], } if (AGENT_ID && AGENT_ID !== 'YOUR_AGENT_ID_HERE') { streamArgs.agent_id = AGENT_ID