@iqai/adk 0.1.3 → 0.1.5

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/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Part, Content as Content$1, Blob, SpeechConfig, AudioTranscriptionConfig, RealtimeInputConfig, ProactivityConfig, GenerateContentConfig, LiveConnectConfig, GroundingMetadata, GenerateContentResponseUsageMetadata, GoogleGenAI, FunctionCall } from '@google/genai';
2
2
  export { Blob, Content } from '@google/genai';
3
+ import { LanguageModel } from 'ai';
3
4
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
4
5
  import { CreateMessageRequestSchema, CreateMessageResultSchema, Tool } from '@modelcontextprotocol/sdk/types.js';
5
6
  import { z } from 'zod';
@@ -7,6 +8,29 @@ import { Kysely, Generated } from 'kysely';
7
8
  import { StorageOptions } from '@google-cloud/storage';
8
9
  import { Tracer } from '@opentelemetry/api';
9
10
 
11
+ interface LoggerOpts {
12
+ name: string;
13
+ }
14
+ declare class Logger {
15
+ name: string;
16
+ isDebugEnabled: boolean;
17
+ constructor({ name }: LoggerOpts);
18
+ private colorize;
19
+ debug(message: string, ...args: any[]): void;
20
+ info(message: string, ...args: any[]): void;
21
+ warn(message: string, ...args: any[]): void;
22
+ error(message: string, ...args: any[]): void;
23
+ /**
24
+ * Logs structured data in a visually appealing table format.
25
+ * Uses vertical layout for better readability and respects debug settings.
26
+ */
27
+ debugStructured(title: string, data: Record<string, any>): void;
28
+ /**
29
+ * Logs array data in a compact, readable format.
30
+ */
31
+ debugArray(title: string, items: Array<Record<string, any>>): void;
32
+ }
33
+
10
34
  /**
11
35
  * JSON Schema type for function parameters
12
36
  */
@@ -816,6 +840,7 @@ declare abstract class BaseTool {
816
840
  * Maximum delay for retry in ms
817
841
  */
818
842
  maxRetryDelay: number;
843
+ protected logger: Logger;
819
844
  /**
820
845
  * Constructor for BaseTool
821
846
  */
@@ -983,7 +1008,7 @@ declare function createFunctionTool(func: (...args: any[]) => any, options?: {
983
1008
  * Simple GoogleSearch tool implementation
984
1009
  */
985
1010
  declare class GoogleSearch extends BaseTool {
986
- private logger;
1011
+ protected logger: Logger;
987
1012
  /**
988
1013
  * Constructor for GoogleSearch
989
1014
  */
@@ -1126,7 +1151,7 @@ declare class UserInteractionTool extends BaseTool {
1126
1151
  * Tool that allows an agent to exit the current execution loop
1127
1152
  */
1128
1153
  declare class ExitLoopTool extends BaseTool {
1129
- private logger;
1154
+ protected logger: Logger;
1130
1155
  /**
1131
1156
  * Constructor for ExitLoopTool
1132
1157
  */
@@ -1141,7 +1166,7 @@ declare class ExitLoopTool extends BaseTool {
1141
1166
  * Tool that allows an agent to get a choice from the user
1142
1167
  */
1143
1168
  declare class GetUserChoiceTool extends BaseTool {
1144
- private logger;
1169
+ protected logger: Logger;
1145
1170
  /**
1146
1171
  * Constructor for GetUserChoiceTool
1147
1172
  */
@@ -1165,7 +1190,7 @@ declare class GetUserChoiceTool extends BaseTool {
1165
1190
  * Tool that allows an agent to transfer control to another agent
1166
1191
  */
1167
1192
  declare class TransferToAgentTool extends BaseTool {
1168
- private logger;
1193
+ protected logger: Logger;
1169
1194
  /**
1170
1195
  * Constructor for TransferToAgentTool
1171
1196
  */
@@ -1182,7 +1207,7 @@ declare class TransferToAgentTool extends BaseTool {
1182
1207
  * Tool that allows an agent to load memories relevant to a query
1183
1208
  */
1184
1209
  declare class LoadMemoryTool extends BaseTool {
1185
- private logger;
1210
+ protected logger: Logger;
1186
1211
  /**
1187
1212
  * Constructor for LoadMemoryTool
1188
1213
  */
@@ -1307,7 +1332,7 @@ declare class McpClientService {
1307
1332
  private transport;
1308
1333
  private isClosing;
1309
1334
  private mcpSamplingHandler;
1310
- private logger;
1335
+ protected logger: Logger;
1311
1336
  constructor(config: McpConfig);
1312
1337
  /**
1313
1338
  * Initializes and returns an MCP client based on configuration.
@@ -1378,7 +1403,7 @@ declare function mcpSchemaToParameters(mcpTool: Tool): JSONSchema;
1378
1403
  * between MCP format and ADK format
1379
1404
  */
1380
1405
  declare class McpSamplingHandler {
1381
- private logger;
1406
+ protected logger: Logger;
1382
1407
  private samplingHandler;
1383
1408
  constructor(samplingHandler: SamplingHandler);
1384
1409
  /**
@@ -1442,8 +1467,8 @@ declare function createSamplingHandler(handler: SamplingHandler): SamplingHandle
1442
1467
  * ```typescript
1443
1468
  * // Old verbose way:
1444
1469
  * const toolset = new McpToolset({
1445
- * name: "Near Intent Swaps MCP Client",
1446
- * description: "Client for Near Intent Swaps",
1470
+ * name: "Near Intents Swaps MCP Client",
1471
+ * description: "Client for Near Intents Swaps",
1447
1472
  * debug: env.DEBUG,
1448
1473
  * retryOptions: { maxRetries: 2, initialDelay: 200 },
1449
1474
  * transport: {
@@ -1500,6 +1525,38 @@ declare function createSamplingHandler(handler: SamplingHandler): SamplingHandle
1500
1525
  * tools: [...atpTools, ...fraxlendTools],
1501
1526
  * });
1502
1527
  * ```
1528
+ *
1529
+ * @example
1530
+ * ```typescript
1531
+ * // Using MCP servers with sampling handlers:
1532
+ * import { createSamplingHandler, LlmResponse } from "@iqai/adk";
1533
+ *
1534
+ * const samplingHandler = createSamplingHandler(async (request) => {
1535
+ * // Handle MCP sampling requests
1536
+ * return new LlmResponse({
1537
+ * content: {
1538
+ * role: "model",
1539
+ * parts: [{ text: "Response from sampling handler" }],
1540
+ * },
1541
+ * });
1542
+ * });
1543
+ *
1544
+ * const nearTools = await McpNearAgent({
1545
+ * env: {
1546
+ * ACCOUNT_ID: env.ACCOUNT_ID,
1547
+ * ACCOUNT_KEY: env.ACCOUNT_KEY,
1548
+ * NEAR_NETWORK_ID: "testnet",
1549
+ * PATH: env.PATH
1550
+ * },
1551
+ * samplingHandler
1552
+ * }).getTools();
1553
+ *
1554
+ * const agent = new LlmAgent({
1555
+ * name: "near_assistant",
1556
+ * model: "gemini-2.5-flash",
1557
+ * tools: nearTools,
1558
+ * });
1559
+ * ```
1503
1560
  */
1504
1561
  /**
1505
1562
  * Base configuration interface for MCP servers
@@ -1516,6 +1573,8 @@ interface McpServerConfig {
1516
1573
  maxRetries?: number;
1517
1574
  initialDelay?: number;
1518
1575
  };
1576
+ /** Sampling handler for processing MCP sampling requests */
1577
+ samplingHandler?: SamplingHandler;
1519
1578
  }
1520
1579
  /**
1521
1580
  * MCP ABI - Smart contract ABI interactions for Ethereum-compatible blockchains
@@ -1556,7 +1615,7 @@ declare function McpIqWiki(config?: McpServerConfig): McpToolset;
1556
1615
  */
1557
1616
  declare function McpNearAgent(config?: McpServerConfig): McpToolset;
1558
1617
  /**
1559
- * MCP NEAR Intent Swaps - NEAR Protocol intent swaps functionality
1618
+ * MCP Near Intents Swaps - NEAR Protocol intent swaps functionality
1560
1619
  *
1561
1620
  * Required env vars: ACCOUNT_ID, ACCOUNT_KEY
1562
1621
  * Optional env vars: NEAR_NETWORK_ID, NEAR_NODE_URL, NEAR_GAS_LIMIT
@@ -1594,7 +1653,7 @@ declare function McpMemory(config?: McpServerConfig): McpToolset;
1594
1653
  * Generic MCP server function for any package
1595
1654
  *
1596
1655
  * @param packageName The npm package name of the MCP server
1597
- * @param config Configuration object with environment variables
1656
+ * @param config Configuration object with environment variables and optional sampling handler
1598
1657
  * @param name Optional custom name for the client
1599
1658
  */
1600
1659
  declare function McpGeneric(packageName: string, config?: McpServerConfig, name?: string): McpToolset;
@@ -1878,6 +1937,10 @@ declare class LlmResponse {
1878
1937
  * Reason why the model finished generating.
1879
1938
  */
1880
1939
  finishReason?: string;
1940
+ /**
1941
+ * Error object if the response is an error.
1942
+ */
1943
+ error?: Error;
1881
1944
  /**
1882
1945
  * Creates a new LlmResponse.
1883
1946
  */
@@ -1889,6 +1952,19 @@ declare class LlmResponse {
1889
1952
  * @returns The LlmResponse.
1890
1953
  */
1891
1954
  static create(generateContentResponse: GenerateContentResponse): LlmResponse;
1955
+ /**
1956
+ * Creates an LlmResponse from an error.
1957
+ *
1958
+ * @param error The error object or message.
1959
+ * @param options Additional options for the error response.
1960
+ * @param options.errorCode A specific error code for the response.
1961
+ * @param options.model The model that was being used when the error occurred.
1962
+ * @returns The LlmResponse.
1963
+ */
1964
+ static fromError(error: unknown, options?: {
1965
+ errorCode?: string;
1966
+ model?: string;
1967
+ }): LlmResponse;
1892
1968
  }
1893
1969
 
1894
1970
  /**
@@ -1944,6 +2020,7 @@ declare abstract class BaseLlm {
1944
2020
  * The name of the LLM, e.g. gemini-1.5-flash or gemini-1.5-flash-001.
1945
2021
  */
1946
2022
  model: string;
2023
+ protected logger: Logger;
1947
2024
  /**
1948
2025
  * Constructor for BaseLlm
1949
2026
  */
@@ -2001,7 +2078,6 @@ declare class GoogleLlm extends BaseLlm {
2001
2078
  private _liveApiClient?;
2002
2079
  private _apiBackend?;
2003
2080
  private _trackingHeaders?;
2004
- private logger;
2005
2081
  /**
2006
2082
  * Constructor for Gemini
2007
2083
  */
@@ -2042,14 +2118,6 @@ declare class GoogleLlm extends BaseLlm {
2042
2118
  * Builds function declaration log string.
2043
2119
  */
2044
2120
  private buildFunctionDeclarationLog;
2045
- /**
2046
- * Builds request log string.
2047
- */
2048
- private buildRequestLog;
2049
- /**
2050
- * Builds response log string.
2051
- */
2052
- private buildResponseLog;
2053
2121
  /**
2054
2122
  * Provides the api client.
2055
2123
  */
@@ -2077,6 +2145,7 @@ declare class GoogleLlm extends BaseLlm {
2077
2145
  */
2078
2146
  declare class AnthropicLlm extends BaseLlm {
2079
2147
  private _client?;
2148
+ protected logger: Logger;
2080
2149
  /**
2081
2150
  * Constructor for Anthropic LLM
2082
2151
  */
@@ -2199,17 +2268,48 @@ declare class OpenAiLlm extends BaseLlm {
2199
2268
  */
2200
2269
  private hasInlineData;
2201
2270
  /**
2202
- * Build request log string for debugging (similar to Google LLM)
2271
+ * Gets the OpenAI client
2203
2272
  */
2204
- private buildRequestLog;
2273
+ private get client();
2274
+ }
2275
+
2276
+ /**
2277
+ * AI SDK integration that accepts a pre-configured LanguageModel.
2278
+ * Enables ADK to work with any provider supported by Vercel's AI SDK.
2279
+ */
2280
+ declare class AiSdkLlm extends BaseLlm {
2281
+ private modelInstance;
2282
+ protected logger: Logger;
2205
2283
  /**
2206
- * Build response log string for debugging (similar to Google LLM)
2284
+ * Constructor accepts a pre-configured LanguageModel instance
2285
+ * @param model - Pre-configured LanguageModel from provider(modelName)
2207
2286
  */
2208
- private buildResponseLog;
2287
+ constructor(modelInstance: LanguageModel);
2209
2288
  /**
2210
- * Gets the OpenAI client
2289
+ * Returns empty array - following Python ADK pattern
2211
2290
  */
2212
- private get client();
2291
+ static supportedModels(): string[];
2292
+ protected generateContentAsyncImpl(request: LlmRequest, stream?: boolean): AsyncGenerator<LlmResponse, void, unknown>;
2293
+ /**
2294
+ * Convert ADK LlmRequest to AI SDK CoreMessage format
2295
+ */
2296
+ private convertToAiSdkMessages;
2297
+ /**
2298
+ * Convert ADK tools to AI SDK tools format
2299
+ */
2300
+ private convertToAiSdkTools;
2301
+ /**
2302
+ * Convert ADK Content to AI SDK CoreMessage
2303
+ */
2304
+ private contentToAiSdkMessage;
2305
+ /**
2306
+ * Map ADK role to AI SDK role
2307
+ */
2308
+ private mapRole;
2309
+ /**
2310
+ * Map AI SDK finish reason to ADK finish reason
2311
+ */
2312
+ private mapFinishReason;
2213
2313
  }
2214
2314
 
2215
2315
  /**
@@ -2227,6 +2327,7 @@ declare class LLMRegistry {
2227
2327
  * Map of model name regex to LLM class
2228
2328
  */
2229
2329
  private static llmRegistry;
2330
+ private static logger;
2230
2331
  /**
2231
2332
  * Creates a new LLM instance
2232
2333
  *
@@ -2759,6 +2860,8 @@ declare class OAuth2Credential extends AuthCredential {
2759
2860
  * Models module exports - consolidated to match Python structure
2760
2861
  */
2761
2862
 
2863
+ type index$5_AiSdkLlm = AiSdkLlm;
2864
+ declare const index$5_AiSdkLlm: typeof AiSdkLlm;
2762
2865
  type index$5_AnthropicLlm = AnthropicLlm;
2763
2866
  declare const index$5_AnthropicLlm: typeof AnthropicLlm;
2764
2867
  type index$5_ApiKeyCredential = ApiKeyCredential;
@@ -2816,7 +2919,7 @@ declare const index$5_State: typeof State;
2816
2919
  type index$5_ThinkingConfig = ThinkingConfig;
2817
2920
  declare const index$5_registerProviders: typeof registerProviders;
2818
2921
  declare namespace index$5 {
2819
- export { index$5_AnthropicLlm as AnthropicLlm, index$5_ApiKeyCredential as ApiKeyCredential, index$5_ApiKeyScheme as ApiKeyScheme, index$5_AuthConfig as AuthConfig, index$5_AuthCredential as AuthCredential, index$5_AuthCredentialType as AuthCredentialType, index$5_AuthHandler as AuthHandler, index$5_AuthScheme as AuthScheme, index$5_AuthSchemeType as AuthSchemeType, index$5_BaseLLMConnection as BaseLLMConnection, index$5_BaseLlm as BaseLlm, type index$5_BaseMemoryService as BaseMemoryService, index$5_BasicAuthCredential as BasicAuthCredential, index$5_BearerTokenCredential as BearerTokenCredential, index$5_Blob as Blob, Content$1 as Content, type index$5_FunctionDeclaration as FunctionDeclaration, index$5_GoogleLlm as GoogleLlm, index$5_HttpScheme as HttpScheme, type index$5_JSONSchema as JSONSchema, index$5_LLMRegistry as LLMRegistry, index$5_LlmRequest as LlmRequest, index$5_LlmResponse as LlmResponse, index$5_OAuth2Credential as OAuth2Credential, index$5_OAuth2Scheme as OAuth2Scheme, type index$5_OAuthFlow as OAuthFlow, type index$5_OAuthFlows as OAuthFlows, index$5_OpenAiLlm as OpenAiLlm, index$5_OpenIdConnectScheme as OpenIdConnectScheme, type index$5_SearchMemoryResponse as SearchMemoryResponse, type index$5_Session as Session, index$5_State as State, type index$5_ThinkingConfig as ThinkingConfig, index$5_registerProviders as registerProviders };
2922
+ export { index$5_AiSdkLlm as AiSdkLlm, index$5_AnthropicLlm as AnthropicLlm, index$5_ApiKeyCredential as ApiKeyCredential, index$5_ApiKeyScheme as ApiKeyScheme, index$5_AuthConfig as AuthConfig, index$5_AuthCredential as AuthCredential, index$5_AuthCredentialType as AuthCredentialType, index$5_AuthHandler as AuthHandler, index$5_AuthScheme as AuthScheme, index$5_AuthSchemeType as AuthSchemeType, index$5_BaseLLMConnection as BaseLLMConnection, index$5_BaseLlm as BaseLlm, type index$5_BaseMemoryService as BaseMemoryService, index$5_BasicAuthCredential as BasicAuthCredential, index$5_BearerTokenCredential as BearerTokenCredential, index$5_Blob as Blob, Content$1 as Content, type index$5_FunctionDeclaration as FunctionDeclaration, index$5_GoogleLlm as GoogleLlm, index$5_HttpScheme as HttpScheme, type index$5_JSONSchema as JSONSchema, index$5_LLMRegistry as LLMRegistry, index$5_LlmRequest as LlmRequest, index$5_LlmResponse as LlmResponse, index$5_OAuth2Credential as OAuth2Credential, index$5_OAuth2Scheme as OAuth2Scheme, type index$5_OAuthFlow as OAuthFlow, type index$5_OAuthFlows as OAuthFlows, index$5_OpenAiLlm as OpenAiLlm, index$5_OpenIdConnectScheme as OpenIdConnectScheme, type index$5_SearchMemoryResponse as SearchMemoryResponse, type index$5_Session as Session, index$5_State as State, type index$5_ThinkingConfig as ThinkingConfig, index$5_registerProviders as registerProviders };
2820
2923
  }
2821
2924
 
2822
2925
  /**
@@ -3050,6 +3153,101 @@ declare abstract class BaseAgent {
3050
3153
  private setParentAgentForSubAgents;
3051
3154
  }
3052
3155
 
3156
+ interface File {
3157
+ /** The name of the file with file extension (e.g., "file.csv") */
3158
+ name: string;
3159
+ /** The base64-encoded bytes of the file content */
3160
+ content: string;
3161
+ /** The mime type of the file (e.g., "image/png") */
3162
+ mimeType: string;
3163
+ }
3164
+ interface CodeExecutionInput {
3165
+ /** The code to execute */
3166
+ code: string;
3167
+ /** The input files available to the code */
3168
+ inputFiles: File[];
3169
+ /** The execution ID for the stateful code execution */
3170
+ executionId?: string;
3171
+ }
3172
+ interface CodeExecutionResult {
3173
+ /** The standard output of the code execution */
3174
+ stdout: string;
3175
+ /** The standard error of the code execution */
3176
+ stderr: string;
3177
+ /** The output files from the code execution */
3178
+ outputFiles: File[];
3179
+ }
3180
+ declare class CodeExecutionUtils {
3181
+ /**
3182
+ * Gets the file content as a base64-encoded string
3183
+ */
3184
+ static getEncodedFileContent(data: string | ArrayBuffer): string;
3185
+ private static isBase64Encoded;
3186
+ /**
3187
+ * Extracts the first code block from the content and truncates everything after it
3188
+ */
3189
+ static extractCodeAndTruncateContent(content: Content$1, codeBlockDelimiters: Array<[string, string]>): string | null;
3190
+ private static escapeRegex;
3191
+ /**
3192
+ * Builds an executable code part with code string
3193
+ */
3194
+ static buildExecutableCodePart(code: string): Part;
3195
+ /**
3196
+ * Builds the code execution result part from the code execution result
3197
+ */
3198
+ static buildCodeExecutionResultPart(codeExecutionResult: CodeExecutionResult): Part;
3199
+ /**
3200
+ * Converts the code execution parts to text parts in a Content
3201
+ */
3202
+ static convertCodeExecutionParts(content: Content$1, codeBlockDelimiter: [string, string], executionResultDelimiters: [string, string]): void;
3203
+ }
3204
+
3205
+ interface BaseCodeExecutorConfig {
3206
+ /**
3207
+ * If true, extract and process data files from the model request
3208
+ * and attach them to the code executor.
3209
+ * Supported data file MimeTypes are [text/csv].
3210
+ * Default to false.
3211
+ */
3212
+ optimizeDataFile?: boolean;
3213
+ /**
3214
+ * Whether the code executor is stateful. Default to false.
3215
+ */
3216
+ stateful?: boolean;
3217
+ /**
3218
+ * The number of attempts to retry on consecutive code execution errors.
3219
+ * Default to 2.
3220
+ */
3221
+ errorRetryAttempts?: number;
3222
+ /**
3223
+ * The list of the enclosing delimiters to identify the code blocks.
3224
+ * For example, the delimiter ['```python\n', '\n```'] can be
3225
+ * used to identify code blocks with the following format:
3226
+ *
3227
+ * ```python
3228
+ * print("hello")
3229
+ * ```
3230
+ */
3231
+ codeBlockDelimiters?: Array<[string, string]>;
3232
+ /**
3233
+ * The delimiters to format the code execution result.
3234
+ */
3235
+ executionResultDelimiters?: [string, string];
3236
+ }
3237
+ declare abstract class BaseCodeExecutor {
3238
+ protected readonly config: Required<BaseCodeExecutorConfig>;
3239
+ constructor(config?: BaseCodeExecutorConfig);
3240
+ /**
3241
+ * Executes code and returns the code execution result.
3242
+ */
3243
+ abstract executeCode(invocationContext: InvocationContext, codeExecutionInput: CodeExecutionInput): Promise<CodeExecutionResult>;
3244
+ get optimizeDataFile(): boolean;
3245
+ get stateful(): boolean;
3246
+ get errorRetryAttempts(): number;
3247
+ get codeBlockDelimiters(): Array<[string, string]>;
3248
+ get executionResultDelimiters(): [string, string];
3249
+ }
3250
+
3053
3251
  /**
3054
3252
  * Abstract base class for all planners.
3055
3253
  *
@@ -3085,7 +3283,7 @@ type ToolUnion = BaseTool | ((...args: any[]) => any);
3085
3283
  /**
3086
3284
  * Configuration for LlmAgent
3087
3285
  */
3088
- interface LlmAgentConfig {
3286
+ interface LlmAgentConfig<T extends BaseLlm = BaseLlm> {
3089
3287
  /**
3090
3288
  * Name of the agent
3091
3289
  */
@@ -3098,7 +3296,7 @@ interface LlmAgentConfig {
3098
3296
  * The LLM model to use
3099
3297
  * When not set, the agent will inherit the model from its ancestor
3100
3298
  */
3101
- model?: string | BaseLlm;
3299
+ model?: string | T | LanguageModel;
3102
3300
  /**
3103
3301
  * Instructions for the LLM model, guiding the agent's behavior
3104
3302
  */
@@ -3112,6 +3310,10 @@ interface LlmAgentConfig {
3112
3310
  * Tools available to this agent
3113
3311
  */
3114
3312
  tools?: ToolUnion[];
3313
+ /**
3314
+ * Code executor for this agent
3315
+ */
3316
+ codeExecutor?: BaseCodeExecutor;
3115
3317
  /**
3116
3318
  * Disallows LLM-controlled transferring to the parent agent
3117
3319
  */
@@ -3171,12 +3373,12 @@ interface LlmAgentConfig {
3171
3373
  /**
3172
3374
  * LLM-based Agent
3173
3375
  */
3174
- declare class LlmAgent extends BaseAgent {
3376
+ declare class LlmAgent<T extends BaseLlm = BaseLlm> extends BaseAgent {
3175
3377
  /**
3176
3378
  * The model to use for the agent
3177
3379
  * When not set, the agent will inherit the model from its ancestor
3178
3380
  */
3179
- model: string | BaseLlm;
3381
+ model: string | T | LanguageModel;
3180
3382
  /**
3181
3383
  * Instructions for the LLM model, guiding the agent's behavior
3182
3384
  */
@@ -3190,6 +3392,10 @@ declare class LlmAgent extends BaseAgent {
3190
3392
  * Tools available to this agent
3191
3393
  */
3192
3394
  tools: ToolUnion[];
3395
+ /**
3396
+ * Code executor for this agent
3397
+ */
3398
+ codeExecutor?: BaseCodeExecutor;
3193
3399
  /**
3194
3400
  * Disallows LLM-controlled transferring to the parent agent
3195
3401
  */
@@ -3242,11 +3448,11 @@ declare class LlmAgent extends BaseAgent {
3242
3448
  * The output schema when agent replies
3243
3449
  */
3244
3450
  outputSchema?: any;
3245
- private logger;
3451
+ protected logger: Logger;
3246
3452
  /**
3247
3453
  * Constructor for LlmAgent
3248
3454
  */
3249
- constructor(config: LlmAgentConfig);
3455
+ constructor(config: LlmAgentConfig<T>);
3250
3456
  /**
3251
3457
  * The resolved model field as BaseLLM
3252
3458
  * This method is only for use by Agent Development Kit
@@ -3481,7 +3687,7 @@ declare class LangGraphAgent extends BaseAgent {
3481
3687
  * Results from node executions
3482
3688
  */
3483
3689
  private results;
3484
- private logger;
3690
+ protected logger: Logger;
3485
3691
  /**
3486
3692
  * Constructor for LangGraphAgent
3487
3693
  */
@@ -3542,7 +3748,7 @@ declare class LangGraphAgent extends BaseAgent {
3542
3748
  * processing, event generation, and interaction with various services like
3543
3749
  * artifact storage, session management, and memory.
3544
3750
  */
3545
- declare class Runner {
3751
+ declare class Runner<T extends BaseAgent = BaseAgent> {
3546
3752
  /**
3547
3753
  * The app name of the runner.
3548
3754
  */
@@ -3550,7 +3756,7 @@ declare class Runner {
3550
3756
  /**
3551
3757
  * The root agent to run.
3552
3758
  */
3553
- agent: BaseAgent;
3759
+ agent: T;
3554
3760
  /**
3555
3761
  * The artifact service for the runner.
3556
3762
  */
@@ -3563,12 +3769,13 @@ declare class Runner {
3563
3769
  * The memory service for the runner.
3564
3770
  */
3565
3771
  memoryService?: BaseMemoryService;
3772
+ protected logger: Logger;
3566
3773
  /**
3567
3774
  * Initializes the Runner.
3568
3775
  */
3569
3776
  constructor({ appName, agent, artifactService, sessionService, memoryService, }: {
3570
3777
  appName: string;
3571
- agent: BaseAgent;
3778
+ agent: T;
3572
3779
  artifactService?: BaseArtifactService;
3573
3780
  sessionService: BaseSessionService;
3574
3781
  memoryService?: BaseMemoryService;
@@ -3613,7 +3820,7 @@ declare class Runner {
3613
3820
  /**
3614
3821
  * An in-memory Runner for testing and development.
3615
3822
  */
3616
- declare class InMemoryRunner extends Runner {
3823
+ declare class InMemoryRunner<T extends BaseAgent = BaseAgent> extends Runner<T> {
3617
3824
  /**
3618
3825
  * Deprecated. Please don't use. The in-memory session service for the runner.
3619
3826
  */
@@ -3621,7 +3828,7 @@ declare class InMemoryRunner extends Runner {
3621
3828
  /**
3622
3829
  * Initializes the InMemoryRunner.
3623
3830
  */
3624
- constructor(agent: BaseAgent, { appName }?: {
3831
+ constructor(agent: T, { appName }?: {
3625
3832
  appName?: string;
3626
3833
  });
3627
3834
  }
@@ -3631,7 +3838,7 @@ declare class InMemoryRunner extends Runner {
3631
3838
  */
3632
3839
  interface AgentBuilderConfig {
3633
3840
  name: string;
3634
- model?: string;
3841
+ model?: string | BaseLlm | LanguageModel;
3635
3842
  description?: string;
3636
3843
  instruction?: string;
3637
3844
  tools?: BaseTool[];
@@ -3690,6 +3897,10 @@ type AgentType = "llm" | "sequential" | "parallel" | "loop" | "langgraph";
3690
3897
  * .withModel("gemini-2.5-flash")
3691
3898
  * .withSession(sessionService, "user123", "myApp")
3692
3899
  * .build();
3900
+ *
3901
+ * // Using an AI SDK provider directly
3902
+ * import { google } from "@ai-sdk/google";
3903
+ * const response = await AgentBuilder.withModel(google()).ask("Hi");
3693
3904
  * ```
3694
3905
  */
3695
3906
  declare class AgentBuilder {
@@ -3711,13 +3922,13 @@ declare class AgentBuilder {
3711
3922
  * @param model The model identifier (e.g., "gemini-2.5-flash")
3712
3923
  * @returns New AgentBuilder instance with model set
3713
3924
  */
3714
- static withModel(model: string): AgentBuilder;
3925
+ static withModel(model: string | BaseLlm | LanguageModel): AgentBuilder;
3715
3926
  /**
3716
3927
  * Set the model for the agent
3717
3928
  * @param model The model identifier (e.g., "gemini-2.5-flash")
3718
3929
  * @returns This builder instance for chaining
3719
3930
  */
3720
- withModel(model: string): this;
3931
+ withModel(model: string | BaseLlm | LanguageModel): this;
3721
3932
  /**
3722
3933
  * Set the description for the agent
3723
3934
  * @param description Agent description
@@ -3821,9 +4032,9 @@ type index$4_LangGraphAgent = LangGraphAgent;
3821
4032
  declare const index$4_LangGraphAgent: typeof LangGraphAgent;
3822
4033
  type index$4_LangGraphAgentConfig = LangGraphAgentConfig;
3823
4034
  type index$4_LangGraphNode = LangGraphNode;
3824
- type index$4_LlmAgent = LlmAgent;
4035
+ type index$4_LlmAgent<T extends BaseLlm = BaseLlm> = LlmAgent<T>;
3825
4036
  declare const index$4_LlmAgent: typeof LlmAgent;
3826
- type index$4_LlmAgentConfig = LlmAgentConfig;
4037
+ type index$4_LlmAgentConfig<T extends BaseLlm = BaseLlm> = LlmAgentConfig<T>;
3827
4038
  type index$4_LlmCallsLimitExceededError = LlmCallsLimitExceededError;
3828
4039
  declare const index$4_LlmCallsLimitExceededError: typeof LlmCallsLimitExceededError;
3829
4040
  type index$4_LoopAgent = LoopAgent;
@@ -4219,7 +4430,7 @@ declare namespace index$1 {
4219
4430
  declare abstract class BaseLlmFlow {
4220
4431
  requestProcessors: Array<any>;
4221
4432
  responseProcessors: Array<any>;
4222
- private logger;
4433
+ protected logger: Logger;
4223
4434
  runAsync(invocationContext: InvocationContext): AsyncGenerator<Event>;
4224
4435
  runLive(invocationContext: InvocationContext): AsyncGenerator<Event>;
4225
4436
  _runOneStepAsync(invocationContext: InvocationContext): AsyncGenerator<Event>;
@@ -4233,6 +4444,15 @@ declare abstract class BaseLlmFlow {
4233
4444
  _handleBeforeModelCallback(invocationContext: InvocationContext, llmRequest: LlmRequest, modelResponseEvent: Event): Promise<LlmResponse | undefined>;
4234
4445
  _handleAfterModelCallback(invocationContext: InvocationContext, llmResponse: LlmResponse, modelResponseEvent: Event): Promise<LlmResponse | undefined>;
4235
4446
  _finalizeModelResponseEvent(llmRequest: LlmRequest, llmResponse: LlmResponse, modelResponseEvent: Event): Event;
4447
+ /**
4448
+ * Logs data in a visually appealing format that works well in any terminal size.
4449
+ * Uses vertical layout for better readability and respects debug settings.
4450
+ */
4451
+ _formatContentPreview(content: any): string;
4452
+ /**
4453
+ * Formats response content preview for debug logging
4454
+ */
4455
+ _formatResponsePreview(llmResponse: LlmResponse): string;
4236
4456
  __getLlm(invocationContext: InvocationContext): BaseLlm;
4237
4457
  }
4238
4458
 
@@ -4371,39 +4591,83 @@ declare const requestProcessor$1: NlPlanningRequestProcessor;
4371
4591
  */
4372
4592
  declare const responseProcessor$1: NlPlanningResponseProcessor;
4373
4593
 
4594
+ /**
4595
+ * The persistent context used to configure the code executor.
4596
+ */
4597
+ declare class CodeExecutorContext {
4598
+ private readonly context;
4599
+ private readonly sessionState;
4600
+ constructor(sessionState: State);
4601
+ /**
4602
+ * Gets the state delta to update in the persistent session state.
4603
+ */
4604
+ getStateDelta(): Record<string, any>;
4605
+ /**
4606
+ * Gets the session ID for the code executor.
4607
+ */
4608
+ getExecutionId(): string | null;
4609
+ /**
4610
+ * Sets the session ID for the code executor.
4611
+ */
4612
+ setExecutionId(sessionId: string): void;
4613
+ /**
4614
+ * Gets the processed file names from the session state.
4615
+ */
4616
+ getProcessedFileNames(): string[];
4617
+ /**
4618
+ * Adds the processed file names to the session state.
4619
+ */
4620
+ addProcessedFileNames(fileNames: string[]): void;
4621
+ /**
4622
+ * Gets the code executor input files from the session state.
4623
+ */
4624
+ getInputFiles(): File[];
4625
+ /**
4626
+ * Adds the input files to the code executor context.
4627
+ */
4628
+ addInputFiles(inputFiles: File[]): void;
4629
+ /**
4630
+ * Removes the input files and processed file names from the code executor context.
4631
+ */
4632
+ clearInputFiles(): void;
4633
+ /**
4634
+ * Gets the error count from the session state.
4635
+ */
4636
+ getErrorCount(invocationId: string): number;
4637
+ /**
4638
+ * Increments the error count for the given invocation ID.
4639
+ */
4640
+ incrementErrorCount(invocationId: string): void;
4641
+ /**
4642
+ * Resets the error count for the given invocation ID.
4643
+ */
4644
+ resetErrorCount(invocationId: string): void;
4645
+ /**
4646
+ * Updates the code execution result.
4647
+ */
4648
+ updateCodeExecutionResult(invocationId: string, code: string, resultStdout: string, resultStderr: string): void;
4649
+ /**
4650
+ * Gets the code executor context from the session state.
4651
+ */
4652
+ private getCodeExecutorContext;
4653
+ }
4654
+
4374
4655
  /**
4375
4656
  * Request processor for code execution
4376
- * This is a placeholder implementation that will be enhanced when code-executors are ready
4377
4657
  */
4378
4658
  declare class CodeExecutionRequestProcessor extends BaseLlmRequestProcessor {
4379
4659
  runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event>;
4380
- /**
4381
- * Placeholder for pre-processor logic
4382
- * TODO: Implement when code-executors are ready
4383
- */
4384
- private runPreProcessor;
4385
4660
  }
4386
4661
  /**
4387
4662
  * Response processor for code execution
4388
- * This is a placeholder implementation that will be enhanced when code-executors are ready
4389
4663
  */
4390
4664
  declare class CodeExecutionResponseProcessor extends BaseLlmResponseProcessor {
4391
4665
  runAsync(invocationContext: InvocationContext, llmResponse: LlmResponse): AsyncGenerator<Event>;
4392
- /**
4393
- * Placeholder for post-processor logic
4394
- * TODO: Implement when code-executors are ready
4395
- */
4396
- private runPostProcessor;
4397
4666
  }
4398
4667
  /**
4399
- * Exported request processor instance for use in flow configurations
4400
- * Ready to be connected when code-executors module is implemented
4668
+ * Exported processor instances
4401
4669
  */
4402
4670
  declare const requestProcessor: CodeExecutionRequestProcessor;
4403
- /**
4404
- * Exported response processor instance for use in flow configurations
4405
- * Ready to be connected when code-executors module is implemented
4406
- */
4407
4671
  declare const responseProcessor: CodeExecutionResponseProcessor;
4408
4672
 
4409
4673
  declare const AF_FUNCTION_CALL_ID_PREFIX = "adk-";
@@ -4496,6 +4760,21 @@ declare namespace index {
4496
4760
  */
4497
4761
  declare function injectSessionState(template: string, readonlyContext: ReadonlyContext): Promise<string>;
4498
4762
 
4763
+ /**
4764
+ * A code executor that uses the Model's built-in code executor.
4765
+ *
4766
+ * Currently only supports Gemini 2.0+ models, but will be expanded to
4767
+ * other models.
4768
+ */
4769
+ declare class BuiltInCodeExecutor extends BaseCodeExecutor {
4770
+ constructor(config?: BaseCodeExecutorConfig);
4771
+ executeCode(invocationContext: InvocationContext, codeExecutionInput: CodeExecutionInput): Promise<CodeExecutionResult>;
4772
+ /**
4773
+ * Pre-process the LLM request for Gemini 2.0+ models to use the code execution tool
4774
+ */
4775
+ processLlmRequest(llmRequest: LlmRequest): void;
4776
+ }
4777
+
4499
4778
  /**
4500
4779
  * The built-in planner that uses model's built-in thinking features.
4501
4780
  */
@@ -4634,4 +4913,4 @@ declare const traceLlmCall: (invocationContext: InvocationContext, eventId: stri
4634
4913
 
4635
4914
  declare const VERSION = "0.1.0";
4636
4915
 
4637
- export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentType, index$4 as Agents, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInPlanner, CallbackContext, DatabaseSessionService, EnhancedAuthConfig, Event, EventActions, index$1 as Events, ExitLoopTool, FileOperationsTool, index as Flows, type FunctionDeclaration, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, InvocationContext, type JSONSchema, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, type McpConfig, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntentSwaps, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, index$3 as Memory, index$5 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PlanReActPlanner, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RunConfig, Runner, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionConfig, index$2 as Sessions, type SingleAgentCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$6 as Tools, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiSessionService, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, createAuthToolArguments, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
4916
+ export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentType, index$4 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, DatabaseSessionService, EnhancedAuthConfig, Event, EventActions, index$1 as Events, ExitLoopTool, type File, FileOperationsTool, index as Flows, type FunctionDeclaration, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, InvocationContext, type JSONSchema, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, type McpConfig, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntentSwaps, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, index$3 as Memory, index$5 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PlanReActPlanner, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RunConfig, Runner, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionConfig, index$2 as Sessions, type SingleAgentCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$6 as Tools, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiSessionService, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, createAuthToolArguments, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };