adk-llm-bridge 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -67,10 +67,10 @@ model: OpenRouter('anthropic/claude-sonnet-4')
67
67
  model: OpenAI('gpt-4.1')
68
68
 
69
69
  // Anthropic - Direct API
70
- model: Anthropic('claude-sonnet-4-5')
70
+ model: Anthropic('claude-sonnet-4-6')
71
71
 
72
72
  // xAI - Direct API
73
- model: XAI('grok-3-beta')
73
+ model: XAI('grok-4.3')
74
74
 
75
75
  // Local models (LM Studio, Ollama, etc.)
76
76
  model: Custom('your-model', { baseURL: 'http://localhost:1234/v1' })
@@ -90,7 +90,7 @@ LLMRegistry.register(AnthropicLlm);
90
90
 
91
91
  const agent = new LlmAgent({
92
92
  name: 'assistant',
93
- model: 'claude-sonnet-4-5', // String-based model name
93
+ model: 'claude-sonnet-4-6', // String-based model name
94
94
  instruction: 'You are a helpful assistant.',
95
95
  });
96
96
  ```
@@ -140,7 +140,7 @@ model: OpenRouter('anthropic/claude-sonnet-4', {
140
140
  })
141
141
 
142
142
  // Anthropic with custom max tokens
143
- model: Anthropic('claude-sonnet-4-5', {
143
+ model: Anthropic('claude-sonnet-4-6', {
144
144
  apiKey: process.env.ANTHROPIC_API_KEY,
145
145
  maxTokens: 8192,
146
146
  })
@@ -205,7 +205,7 @@ const getWeather = new FunctionTool({
205
205
 
206
206
  const agent = new LlmAgent({
207
207
  name: 'weather-assistant',
208
- model: Anthropic('claude-sonnet-4-5'),
208
+ model: Anthropic('claude-sonnet-4-6'),
209
209
  instruction: 'You help users check the weather.',
210
210
  tools: [getWeather],
211
211
  });
@@ -298,12 +298,13 @@ See the [examples](./examples) directory:
298
298
  - **[basic-agent-anthropic](./examples/basic-agent-anthropic)** - Multi-agent HelpDesk with Anthropic
299
299
  - **[basic-agent-xai](./examples/basic-agent-xai)** - Multi-agent HelpDesk with xAI
300
300
  - **[basic-agent-lmstudio](./examples/basic-agent-lmstudio)** - Multi-agent HelpDesk with LM Studio
301
+ - **[native-features](./examples/native-features)** - Showcase of native model capabilities (sampling, reasoning, structured output, multimodal, tool_choice, streaming) across all 5 providers
301
302
  - **[express-server](./examples/express-server)** - Production HTTP API with sessions, streaming, tools
302
303
 
303
304
  ## Requirements
304
305
 
305
306
  - Node.js >= 18.0.0
306
- - `@google/adk` >= 0.2.2
307
+ - `@google/adk` >= 0.5.0 (peer range `>=0.5.0 <2`; tested against 1.2.0)
307
308
 
308
309
  ## Contributing
309
310
 
package/dist/index.d.ts CHANGED
@@ -470,6 +470,22 @@ interface AnthropicProviderConfig extends BaseProviderConfig {
470
470
  * @defaultValue 4096
471
471
  */
472
472
  maxTokens?: number;
473
+ /**
474
+ * Opt-in Anthropic prompt caching.
475
+ *
476
+ * When `true`, attaches `cache_control: { type: "ephemeral" }` to the
477
+ * system prompt block and the last tool definition, marking the largely
478
+ * static prefix of the request (system instruction + tool schemas) as
479
+ * cacheable. This can substantially reduce cost and latency for prompts
480
+ * that reuse the same system instruction and tools across turns.
481
+ *
482
+ * This is a bridge-level instance setting, NOT derived from ADK's
483
+ * `config.cachedContent` (which is a non-portable Gemini resource name).
484
+ *
485
+ * @defaultValue false
486
+ * @see {@link https://platform.claude.com/docs/en/docs/build-with-claude/prompt-caching|Anthropic Prompt Caching}
487
+ */
488
+ promptCaching?: boolean;
473
489
  }
474
490
  /**
475
491
  * Options for registering Anthropic with ADK's LLMRegistry.
@@ -497,6 +513,17 @@ interface AnthropicRegisterOptions {
497
513
  * @defaultValue 4096
498
514
  */
499
515
  maxTokens?: number;
516
+ /**
517
+ * Opt-in Anthropic prompt caching for all models created through the
518
+ * registry.
519
+ *
520
+ * When `true`, attaches `cache_control: { type: "ephemeral" }` to the
521
+ * system prompt block and the last tool definition.
522
+ *
523
+ * @defaultValue false
524
+ * @see {@link AnthropicProviderConfig.promptCaching}
525
+ */
526
+ promptCaching?: boolean;
500
527
  }
501
528
  /**
502
529
  * Accumulator for tool call data during streaming.
@@ -538,8 +565,23 @@ interface ToolCallAccumulator {
538
565
  interface StreamAccumulator {
539
566
  /** Accumulated text content from all chunks */
540
567
  text: string;
568
+ /**
569
+ * Accumulated reasoning/thinking text from all chunks.
570
+ *
571
+ * Populated from provider `delta.reasoning` / `delta.reasoning_content`
572
+ * fields. Emitted as a `{ thought: true }` part.
573
+ */
574
+ reasoning: string;
541
575
  /** Map of tool call index to accumulated tool call data */
542
576
  toolCalls: Map<number, ToolCallAccumulator>;
577
+ /**
578
+ * Token usage captured from the final OpenAI streaming chunk.
579
+ *
580
+ * Populated when `stream_options.include_usage` is enabled; emitted as
581
+ * `usageMetadata` on the final response. Includes `thoughtsTokenCount` when
582
+ * the provider reports `completion_tokens_details.reasoning_tokens`.
583
+ */
584
+ usage?: LlmResponse["usageMetadata"];
543
585
  }
544
586
  /**
545
587
  * Result from processing a stream chunk.
@@ -858,6 +900,12 @@ declare class AnthropicLlm extends BaseProviderLlm {
858
900
  */
859
901
  private readonly maxTokens;
860
902
  /**
903
+ * Whether opt-in prompt caching is enabled for this instance.
904
+ *
905
+ * @private
906
+ */
907
+ private readonly promptCaching;
908
+ /**
861
909
  * Creates a new Anthropic LLM instance.
862
910
  *
863
911
  * @param config - Configuration options for the Anthropic provider
@@ -886,6 +934,9 @@ declare class AnthropicLlm extends BaseProviderLlm {
886
934
  /**
887
935
  * Builds the shared request parameters for the Anthropic API.
888
936
  *
937
+ * Per-request `config.maxOutputTokens` (params.max_tokens) overrides the
938
+ * instance default. Anthropic requires `max_tokens` to always be present.
939
+ *
889
940
  * @private
890
941
  */
891
942
  private buildRequestParams;
@@ -1373,6 +1424,19 @@ interface ConvertedRequest {
1373
1424
  * Converted from ADK function declarations with schema normalization.
1374
1425
  */
1375
1426
  tools?: OpenAI3.ChatCompletionTool[];
1427
+ /**
1428
+ * Generation + structured-output parameters mapped from `config`.
1429
+ *
1430
+ * Built from a strict allowlist (temperature, top_p, max_tokens, etc. plus
1431
+ * response_format). Spread directly into the chat completion request body.
1432
+ */
1433
+ params?: Record<string, unknown>;
1434
+ /**
1435
+ * OpenAI `tool_choice` mapped from `config.toolConfig.functionCallingConfig`.
1436
+ *
1437
+ * Only meaningful when tools are present.
1438
+ */
1439
+ toolChoice?: OpenAI3.ChatCompletionToolChoiceOption;
1376
1440
  }
1377
1441
  /**
1378
1442
  * Converts an ADK LlmRequest to OpenAI chat completion format.
@@ -1423,7 +1487,48 @@ interface ConvertedRequest {
1423
1487
  * // tools[0].function.parameters.type = "object" (normalized from "OBJECT")
1424
1488
  * ```
1425
1489
  */
1426
- declare function convertRequest(llmRequest: LlmRequest5): ConvertedRequest;
1490
+ declare function convertRequest(llmRequest: LlmRequest5, model?: string): ConvertedRequest;
1491
+ /**
1492
+ * Maps ADK generation config to OpenAI chat completion params.
1493
+ *
1494
+ * Uses a STRICT allowlist — the ADK `config` is never blind-spread, so
1495
+ * Gemini-only knobs (safetySettings, responseModalities, etc.) cannot leak
1496
+ * into the OpenAI request body. `topK` is intentionally dropped (no OpenAI
1497
+ * Chat Completions equivalent).
1498
+ *
1499
+ * @param req - The LLM request
1500
+ * @returns An OpenAI params object, or `{}` when no fields are set
1501
+ */
1502
+ declare function convertGenerationConfig(req: LlmRequest5, model?: string): Record<string, unknown>;
1503
+ /**
1504
+ * Maps ADK `functionCallingConfig` to an OpenAI `tool_choice`.
1505
+ *
1506
+ * - AUTO -> "auto"
1507
+ * - NONE -> "none"
1508
+ * - ANY / VALIDATED -> "required" (or a specific function when exactly one
1509
+ * allowedFunctionName is given)
1510
+ *
1511
+ * @param req - The LLM request
1512
+ * @returns The OpenAI tool_choice, or undefined when no toolConfig is present
1513
+ */
1514
+ declare function convertToolChoice(req: LlmRequest5): OpenAI3.ChatCompletionToolChoiceOption | undefined;
1515
+ /**
1516
+ * Maps ADK structured-output config to an OpenAI `response_format`.
1517
+ *
1518
+ * - `responseJsonSchema` -> json_schema (passthrough, already JSON Schema)
1519
+ * - `responseSchema` -> json_schema (normalized from Gemini types)
1520
+ * - `responseMimeType === "application/json"` only -> json_object
1521
+ *
1522
+ * `strict` is intentionally `false`. OpenAI strict mode imposes hard structural
1523
+ * requirements (every object must set `additionalProperties: false` and list
1524
+ * ALL properties in `required`) that Gemini-derived / arbitrary caller schemas
1525
+ * routinely violate, producing a 400. Lenient (`strict: false`) accepts partial
1526
+ * schemas, which is the lower-risk default for caller-supplied schemas.
1527
+ *
1528
+ * @param req - The LLM request
1529
+ * @returns A params object with `response_format`, or `{}` when not applicable
1530
+ */
1531
+ declare function convertStructuredOutput(req: LlmRequest5): Record<string, unknown>;
1427
1532
  import { LlmResponse as LlmResponse6 } from "@google/adk";
1428
1533
  import OpenAI4 from "openai";
1429
1534
  /**
@@ -1512,4 +1617,35 @@ declare function convertStreamChunk(chunk: OpenAI4.ChatCompletionChunk, acc: Str
1512
1617
  * ```
1513
1618
  */
1514
1619
  declare function createStreamAccumulator(): StreamAccumulator;
1515
- export { setProviderConfig, setConfig, resetProviderConfig, resetConfig, resetAllConfigs, registerXAI, registerOpenRouter, registerOpenAI, registerAnthropic, registerAIGateway, isXAIRegistered, isOpenRouterRegistered, isOpenAIRegistered, isAnthropicRegistered, isAIGatewayRegistered, getProviderConfig, getConfig, createStreamAccumulator, createCustomLlm, convertStreamChunk, convertResponse, convertRequest, XAIRegisterOptions, XAIProviderConfig, XAILlm, XAI, ToolCallAccumulator, StreamChunkResult, StreamAccumulator, RegisterOptions, PROVIDER_IDS, OpenRouterRegisterOptions, OpenRouterProviderPreferences, OpenRouterLlm, OpenRouterConfig, OpenRouter, OpenAIRegisterOptions, OpenAIProviderConfig, OpenAILlm, OpenAICompatibleLlm, OpenAIClientConfig, OpenAI2 as OpenAI, OPENROUTER_MODEL_PATTERNS, OPENROUTER_BASE_URL, MODEL_PATTERNS, DEFAULT_BASE_URL, CustomLlmProviderConfig, CustomLlmConfig, CustomLlm, Custom, BaseProviderLlm, BaseProviderConfig, BaseLlm2 as BaseLlm, AnthropicRegisterOptions, AnthropicProviderConfig, AnthropicLlm, Anthropic3 as Anthropic, AIGatewayLlm, AIGatewayConfig, AIGateway };
1620
+ /**
1621
+ * @license
1622
+ * Copyright 2025 PAI
1623
+ * SPDX-License-Identifier: MIT
1624
+ */
1625
+ /**
1626
+ * Shared schema normalization.
1627
+ *
1628
+ * Converts Gemini-style schemas (UPPERCASE type names) to the lowercase
1629
+ * JSON-Schema-style types expected by OpenAI and Anthropic. Used by tool
1630
+ * conversion and structured-output mapping across providers.
1631
+ *
1632
+ * @module converters/schema
1633
+ */
1634
+ /**
1635
+ * Normalizes a Gemini-style schema to a JSON-Schema-style schema.
1636
+ *
1637
+ * Converts UPPERCASE type names (Gemini format) to lowercase, recursing into
1638
+ * nested objects and preserving arrays. Already-lowercase types are left
1639
+ * unchanged, making the function idempotent.
1640
+ *
1641
+ * @param schema - The schema object to normalize
1642
+ * @returns The normalized schema, or undefined if the input is not an object
1643
+ *
1644
+ * @example
1645
+ * ```typescript
1646
+ * normalizeSchema({ type: "OBJECT", properties: { name: { type: "STRING" } } });
1647
+ * // Returns: { type: "object", properties: { name: { type: "string" } } }
1648
+ * ```
1649
+ */
1650
+ declare function normalizeSchema(schema: unknown): Record<string, unknown> | undefined;
1651
+ export { setProviderConfig, setConfig, resetProviderConfig, resetConfig, resetAllConfigs, registerXAI, registerOpenRouter, registerOpenAI, registerAnthropic, registerAIGateway, normalizeSchema, isXAIRegistered, isOpenRouterRegistered, isOpenAIRegistered, isAnthropicRegistered, isAIGatewayRegistered, getProviderConfig, getConfig, createStreamAccumulator, createCustomLlm, convertToolChoice, convertStructuredOutput, convertStreamChunk, convertResponse, convertRequest, convertGenerationConfig, XAIRegisterOptions, XAIProviderConfig, XAILlm, XAI, ToolCallAccumulator, StreamChunkResult, StreamAccumulator, RegisterOptions, PROVIDER_IDS, OpenRouterRegisterOptions, OpenRouterProviderPreferences, OpenRouterLlm, OpenRouterConfig, OpenRouter, OpenAIRegisterOptions, OpenAIProviderConfig, OpenAILlm, OpenAICompatibleLlm, OpenAIClientConfig, OpenAI2 as OpenAI, OPENROUTER_MODEL_PATTERNS, OPENROUTER_BASE_URL, MODEL_PATTERNS, DEFAULT_BASE_URL, CustomLlmProviderConfig, CustomLlmConfig, CustomLlm, Custom, BaseProviderLlm, BaseProviderConfig, BaseLlm2 as BaseLlm, AnthropicRegisterOptions, AnthropicProviderConfig, AnthropicLlm, Anthropic3 as Anthropic, AIGatewayLlm, AIGatewayConfig, AIGateway };