Agent fix
This commit is contained in:
@@ -12,11 +12,9 @@ import Anthropic from '@anthropic-ai/sdk'
|
||||
// ---------------------------------------------------------------------------
|
||||
// Managed Agent configuration
|
||||
// ---------------------------------------------------------------------------
|
||||
// If you have provisioned a Managed Agent in the Anthropic console, set its
|
||||
// ID here (or via the AGENT_ID env var). When AGENT_ID is present the call
|
||||
// is routed to that agent. Otherwise we fall back to a system-prompt-driven
|
||||
// "virtual agent" that defines the persona inline.
|
||||
const AGENT_ID = process.env.ANTHROPIC_AGENT_ID || 'YOUR_AGENT_ID_HERE'
|
||||
// The Managed Agent ID is supplied via the ANTHROPIC_AGENT_ID env var. When
|
||||
// present the call is routed to that agent. Otherwise we fall back to a
|
||||
// system-prompt-driven "virtual agent" that defines the persona inline.
|
||||
|
||||
const SYSTEM_PROMPT = `You are the "PMC Funder Discovery Agent", an expert
|
||||
fundraising consultant for U.S. public media stations (NPR/PBS member
|
||||
@@ -38,11 +36,6 @@ specific dollar amounts.`
|
||||
|
||||
const MODEL = process.env.ANTHROPIC_MODEL || 'claude-sonnet-4-5'
|
||||
|
||||
// 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_011CawyAEnxwp1oXg79g2Fjx'
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Anthropic client (reused across warm Lambda invocations)
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -54,8 +47,6 @@ function getClient() {
|
||||
}
|
||||
_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' },
|
||||
})
|
||||
return _client
|
||||
}
|
||||
@@ -122,23 +113,12 @@ Please draft the funding outlook brief described in your instructions.`
|
||||
messages: [
|
||||
{
|
||||
role: 'user',
|
||||
content: [
|
||||
{
|
||||
type: 'document',
|
||||
source: { type: 'file', file_id: KNOWLEDGE_FILE_ID },
|
||||
title: 'Funder knowledge base (CSV)',
|
||||
citations: { enabled: true },
|
||||
// Cache the tokenized CSV on Anthropic's side for ~5 minutes
|
||||
// so repeat requests pay ~10% of input-token cost for it.
|
||||
cache_control: { type: 'ephemeral' },
|
||||
},
|
||||
{ type: 'text', text: userMessage },
|
||||
],
|
||||
content: [{ type: 'text', text: userMessage }],
|
||||
},
|
||||
],
|
||||
}
|
||||
if (AGENT_ID && AGENT_ID !== 'YOUR_AGENT_ID_HERE') {
|
||||
streamArgs.agent_id = AGENT_ID
|
||||
if (process.env.ANTHROPIC_AGENT_ID) {
|
||||
streamArgs.agent_id = process.env.ANTHROPIC_AGENT_ID
|
||||
}
|
||||
|
||||
const upstream = client.messages.stream(streamArgs)
|
||||
|
||||
Reference in New Issue
Block a user