Lines 15-55javascript
16 return 4096; // safe fallback for claude-3 and any unrecognised model
19 * Anthropic LLM provider for realm agent.
20 * Uses the Messages API and extracts JSON from the first text content block.
21 * Retries once if the model returns non-JSON content.
23export class AnthropicProvider extends ToolCapableLlmProvider {
29 async callStep(prompt, inputSchema, agentProfileInstructions) {
30 // Dynamically import @anthropic-ai/sdk to keep it an optional peer dependency.
31 // See openai-provider.ts for an explanation of the 'string' cast technique.
32 // eslint-disable-next-line @typescript-eslint/no-explicit-any
35 const moduleId = '@anthropic-ai/sdk';
36 mod = await import(moduleId);
37 }
MediumDynamic Require
Package source references dynamic require/import behavior.
dist/agent/providers/anthropic-provider.jsView on unpkg · L35 39 console.error('realm agent requires the @anthropic-ai/sdk package. Run: npm install @anthropic-ai/sdk');
42 // eslint-disable-next-line @typescript-eslint/no-explicit-any
43 const client = new mod.default({
44 apiKey: process.env['ANTHROPIC_API_KEY'],
46 const systemPrompt = buildSystemPrompt(inputSchema, agentProfileInstructions);
47 const makeRequest = async (userContent) => {
48 const response = await // eslint-disable-next-line @typescript-eslint/no-explicit-any
49 client.messages.create({
51 max_tokens: resolveMaxTokens(this.model),
53 messages: [{ role: 'user', content: userContent }],
55 const block = response.content.find(