@iqai/adk 0.4.0 → 0.5.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @iqai/adk
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9c8441c: Enhanced CoinGecko MCP server support with remote endpoints
8
+
9
+ - **Enhanced createMcpConfig function**: Now automatically detects URLs and uses `mcp-remote` for remote MCP endpoints while maintaining backward compatibility with npm packages
10
+ - **Updated McpCoinGecko**: Now uses the remote CoinGecko MCP API endpoint (`https://mcp.api.coingecko.com/mcp`) instead of the npm package
11
+ - **Added McpCoinGeckoPro**: New function for accessing the professional CoinGecko MCP API endpoint (`https://mcp.pro-api.coingecko.com/mcp`) with enhanced features and higher rate limits
12
+ - **Improved code maintainability**: Refactored both CoinGecko functions to use the enhanced `createMcpConfig`, eliminating code duplication
13
+ - **Added documentation**: Updated module documentation with examples showing how to use both CoinGecko functions
14
+
15
+ This change enables seamless integration with CoinGecko's remote MCP endpoints while providing a cleaner, more maintainable codebase for future remote endpoint integrations.
16
+
17
+ ## 0.4.1
18
+
19
+ ### Patch Changes
20
+
21
+ - 1b00e47: Add export to VertexAiRagMemoryService
22
+
3
23
  ## 0.4.0
4
24
 
5
25
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -674,6 +674,18 @@ declare class ReadonlyContext {
674
674
  * The name of the agent that is currently running.
675
675
  */
676
676
  get agentName(): string;
677
+ /**
678
+ * The application name for this invocation. READONLY field.
679
+ */
680
+ get appName(): string;
681
+ /**
682
+ * The user ID for this invocation. READONLY field.
683
+ */
684
+ get userId(): string;
685
+ /**
686
+ * The session ID for this invocation. READONLY field.
687
+ */
688
+ get sessionId(): string;
677
689
  /**
678
690
  * The state of the current session. READONLY field.
679
691
  */
@@ -1255,7 +1267,7 @@ type ToolUnion = BaseTool | ((...args: any[]) => any);
1255
1267
  type SingleBeforeModelCallback = (args: {
1256
1268
  callbackContext: CallbackContext;
1257
1269
  llmRequest: LlmRequest;
1258
- }) => LlmResponse | null | Promise<LlmResponse | null>;
1270
+ }) => LlmResponse | null | undefined | Promise<LlmResponse | null | undefined>;
1259
1271
  /**
1260
1272
  * Before model callback type (single or array)
1261
1273
  */
@@ -1266,7 +1278,7 @@ type BeforeModelCallback = SingleBeforeModelCallback | SingleBeforeModelCallback
1266
1278
  type SingleAfterModelCallback = (args: {
1267
1279
  callbackContext: CallbackContext;
1268
1280
  llmResponse: LlmResponse;
1269
- }) => LlmResponse | null | Promise<LlmResponse | null>;
1281
+ }) => LlmResponse | null | undefined | Promise<LlmResponse | null | undefined>;
1270
1282
  /**
1271
1283
  * After model callback type (single or array)
1272
1284
  */
@@ -1274,7 +1286,7 @@ type AfterModelCallback = SingleAfterModelCallback | SingleAfterModelCallback[];
1274
1286
  /**
1275
1287
  * Single before tool callback type
1276
1288
  */
1277
- type SingleBeforeToolCallback = (tool: BaseTool, args: Record<string, any>, toolContext: ToolContext) => Record<string, any> | null | Promise<Record<string, any> | null>;
1289
+ type SingleBeforeToolCallback = (tool: BaseTool, args: Record<string, any>, toolContext: ToolContext) => Record<string, any> | null | undefined | Promise<Record<string, any> | null | undefined>;
1278
1290
  /**
1279
1291
  * Before tool callback type (single or array)
1280
1292
  */
@@ -1282,7 +1294,7 @@ type BeforeToolCallback = SingleBeforeToolCallback | SingleBeforeToolCallback[];
1282
1294
  /**
1283
1295
  * Single after tool callback type
1284
1296
  */
1285
- type SingleAfterToolCallback = (tool: BaseTool, args: Record<string, any>, toolContext: ToolContext, toolResponse: Record<string, any>) => Record<string, any> | null | Promise<Record<string, any> | null>;
1297
+ type SingleAfterToolCallback = (tool: BaseTool, args: Record<string, any>, toolContext: ToolContext, toolResponse: Record<string, any>) => Record<string, any> | null | undefined | Promise<Record<string, any> | null | undefined>;
1286
1298
  /**
1287
1299
  * After tool callback type (single or array)
1288
1300
  */
@@ -2275,6 +2287,24 @@ declare function createSamplingHandler(handler: SamplingHandler): SamplingHandle
2275
2287
  *
2276
2288
  * @example
2277
2289
  * ```typescript
2290
+ * // Using remote MCP endpoints (CoinGecko):
2291
+ * const coinGeckoTools = await McpCoinGecko().getTools();
2292
+ *
2293
+ * const coinGeckoProTools = await McpCoinGeckoPro({
2294
+ * env: {
2295
+ * COINGECKO_PRO_API_KEY: env.COINGECKO_PRO_API_KEY
2296
+ * }
2297
+ * }).getTools();
2298
+ *
2299
+ * const cryptoAgent = new LlmAgent({
2300
+ * name: "crypto_assistant",
2301
+ * model: "gemini-2.5-flash",
2302
+ * tools: [...coinGeckoTools, ...coinGeckoProTools],
2303
+ * });
2304
+ * ```
2305
+ *
2306
+ * @example
2307
+ * ```typescript
2278
2308
  * // Using MCP servers with sampling handlers:
2279
2309
  * import { createSamplingHandler, LlmResponse } from "@iqai/adk";
2280
2310
  *
@@ -2388,11 +2418,18 @@ declare function McpTelegram(config?: McpServerConfig): McpToolset;
2388
2418
  */
2389
2419
  declare function McpDiscord(config?: McpServerConfig): McpToolset;
2390
2420
  /**
2391
- * MCP CoinGecko - Access cryptocurrency market data and analytics
2421
+ * MCP CoinGecko - Access cryptocurrency market data and analytics via remote endpoint
2392
2422
  *
2393
- * Optional env vars: COINGECKO_PRO_API_KEY, COINGECKO_DEMO_API_KEY, COINGECKO_ENVIRONMENT
2423
+ * Uses the public CoinGecko MCP API endpoint. No API key required for basic functionality.
2394
2424
  */
2395
2425
  declare function McpCoinGecko(config?: McpServerConfig): McpToolset;
2426
+ /**
2427
+ * MCP CoinGecko Pro - Access premium cryptocurrency market data and analytics via remote endpoint
2428
+ *
2429
+ * Uses the professional CoinGecko MCP API endpoint with enhanced features and higher rate limits.
2430
+ * Requires a CoinGecko Pro API subscription.
2431
+ */
2432
+ declare function McpCoinGeckoPro(config?: McpServerConfig): McpToolset;
2396
2433
  /**
2397
2434
  * MCP Upbit - Interact with the Upbit cryptocurrency exchange
2398
2435
  *
@@ -2528,6 +2565,7 @@ declare const index$7_McpAbi: typeof McpAbi;
2528
2565
  declare const index$7_McpAtp: typeof McpAtp;
2529
2566
  declare const index$7_McpBamm: typeof McpBamm;
2530
2567
  declare const index$7_McpCoinGecko: typeof McpCoinGecko;
2568
+ declare const index$7_McpCoinGeckoPro: typeof McpCoinGeckoPro;
2531
2569
  type index$7_McpConfig = McpConfig;
2532
2570
  declare const index$7_McpDiscord: typeof McpDiscord;
2533
2571
  type index$7_McpError = McpError;
@@ -2571,7 +2609,7 @@ declare const index$7_jsonSchemaToDeclaration: typeof jsonSchemaToDeclaration;
2571
2609
  declare const index$7_mcpSchemaToParameters: typeof mcpSchemaToParameters;
2572
2610
  declare const index$7_normalizeJsonSchema: typeof normalizeJsonSchema;
2573
2611
  declare namespace index$7 {
2574
- export { index$7_AgentTool as AgentTool, type index$7_AgentToolConfig as AgentToolConfig, type index$7_BaseAgentType as BaseAgentType, index$7_BaseTool as BaseTool, type index$7_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, type index$7_CreateToolConfig as CreateToolConfig, type index$7_CreateToolConfigWithSchema as CreateToolConfigWithSchema, type index$7_CreateToolConfigWithoutSchema as CreateToolConfigWithoutSchema, index$7_ExitLoopTool as ExitLoopTool, index$7_FileOperationsTool as FileOperationsTool, index$7_FunctionTool as FunctionTool, index$7_GetUserChoiceTool as GetUserChoiceTool, index$7_GoogleSearch as GoogleSearch, index$7_HttpRequestTool as HttpRequestTool, index$7_LoadArtifactsTool as LoadArtifactsTool, index$7_LoadMemoryTool as LoadMemoryTool, index$7_McpAbi as McpAbi, index$7_McpAtp as McpAtp, index$7_McpBamm as McpBamm, index$7_McpCoinGecko as McpCoinGecko, type index$7_McpConfig as McpConfig, index$7_McpDiscord as McpDiscord, index$7_McpError as McpError, index$7_McpErrorType as McpErrorType, index$7_McpFilesystem as McpFilesystem, index$7_McpFraxlend as McpFraxlend, index$7_McpGeneric as McpGeneric, index$7_McpIqWiki as McpIqWiki, index$7_McpMemory as McpMemory, index$7_McpNearAgent as McpNearAgent, index$7_McpNearIntents as McpNearIntents, index$7_McpOdos as McpOdos, index$7_McpSamplingHandler as McpSamplingHandler, type index$7_McpSamplingRequest as McpSamplingRequest, type index$7_McpSamplingResponse as McpSamplingResponse, type index$7_McpServerConfig as McpServerConfig, index$7_McpTelegram as McpTelegram, index$7_McpToolset as McpToolset, type index$7_McpTransportType as McpTransportType, index$7_McpUpbit as McpUpbit, type index$7_SamplingHandler as SamplingHandler, type index$7_ToolConfig as ToolConfig, index$7_ToolContext as ToolContext, index$7_TransferToAgentTool as TransferToAgentTool, index$7_UserInteractionTool as UserInteractionTool, index$7_adkToMcpToolType as adkToMcpToolType, index$7_buildFunctionDeclaration as buildFunctionDeclaration, index$7_convertMcpToolToBaseTool as convertMcpToolToBaseTool, index$7_createFunctionTool as createFunctionTool, index$7_createSamplingHandler as createSamplingHandler, index$7_createTool as createTool, index$7_getMcpTools as getMcpTools, index$7_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$7_mcpSchemaToParameters as mcpSchemaToParameters, index$7_normalizeJsonSchema as normalizeJsonSchema };
2612
+ export { index$7_AgentTool as AgentTool, type index$7_AgentToolConfig as AgentToolConfig, type index$7_BaseAgentType as BaseAgentType, index$7_BaseTool as BaseTool, type index$7_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, type index$7_CreateToolConfig as CreateToolConfig, type index$7_CreateToolConfigWithSchema as CreateToolConfigWithSchema, type index$7_CreateToolConfigWithoutSchema as CreateToolConfigWithoutSchema, index$7_ExitLoopTool as ExitLoopTool, index$7_FileOperationsTool as FileOperationsTool, index$7_FunctionTool as FunctionTool, index$7_GetUserChoiceTool as GetUserChoiceTool, index$7_GoogleSearch as GoogleSearch, index$7_HttpRequestTool as HttpRequestTool, index$7_LoadArtifactsTool as LoadArtifactsTool, index$7_LoadMemoryTool as LoadMemoryTool, index$7_McpAbi as McpAbi, index$7_McpAtp as McpAtp, index$7_McpBamm as McpBamm, index$7_McpCoinGecko as McpCoinGecko, index$7_McpCoinGeckoPro as McpCoinGeckoPro, type index$7_McpConfig as McpConfig, index$7_McpDiscord as McpDiscord, index$7_McpError as McpError, index$7_McpErrorType as McpErrorType, index$7_McpFilesystem as McpFilesystem, index$7_McpFraxlend as McpFraxlend, index$7_McpGeneric as McpGeneric, index$7_McpIqWiki as McpIqWiki, index$7_McpMemory as McpMemory, index$7_McpNearAgent as McpNearAgent, index$7_McpNearIntents as McpNearIntents, index$7_McpOdos as McpOdos, index$7_McpSamplingHandler as McpSamplingHandler, type index$7_McpSamplingRequest as McpSamplingRequest, type index$7_McpSamplingResponse as McpSamplingResponse, type index$7_McpServerConfig as McpServerConfig, index$7_McpTelegram as McpTelegram, index$7_McpToolset as McpToolset, type index$7_McpTransportType as McpTransportType, index$7_McpUpbit as McpUpbit, type index$7_SamplingHandler as SamplingHandler, type index$7_ToolConfig as ToolConfig, index$7_ToolContext as ToolContext, index$7_TransferToAgentTool as TransferToAgentTool, index$7_UserInteractionTool as UserInteractionTool, index$7_adkToMcpToolType as adkToMcpToolType, index$7_buildFunctionDeclaration as buildFunctionDeclaration, index$7_convertMcpToolToBaseTool as convertMcpToolToBaseTool, index$7_createFunctionTool as createFunctionTool, index$7_createSamplingHandler as createSamplingHandler, index$7_createTool as createTool, index$7_getMcpTools as getMcpTools, index$7_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$7_mcpSchemaToParameters as mcpSchemaToParameters, index$7_normalizeJsonSchema as normalizeJsonSchema };
2575
2613
  }
2576
2614
 
2577
2615
  /**
@@ -3997,6 +4035,10 @@ interface AgentBuilderConfig {
3997
4035
  subAgents?: BaseAgent[];
3998
4036
  beforeAgentCallback?: BeforeAgentCallback;
3999
4037
  afterAgentCallback?: AfterAgentCallback;
4038
+ beforeModelCallback?: BeforeModelCallback;
4039
+ afterModelCallback?: AfterModelCallback;
4040
+ beforeToolCallback?: BeforeToolCallback;
4041
+ afterToolCallback?: AfterToolCallback;
4000
4042
  maxIterations?: number;
4001
4043
  nodes?: LangGraphNode[];
4002
4044
  rootNode?: string;
@@ -4207,6 +4249,30 @@ declare class AgentBuilder<TOut = string, TMulti extends boolean = false> {
4207
4249
  * @returns This builder instance for chaining
4208
4250
  */
4209
4251
  withAfterAgentCallback(callback: AfterAgentCallback): this;
4252
+ /**
4253
+ * Set the before model callback for LLM interaction
4254
+ * @param callback Callback to invoke before calling the LLM
4255
+ * @returns This builder instance for chaining
4256
+ */
4257
+ withBeforeModelCallback(callback: BeforeModelCallback): this;
4258
+ /**
4259
+ * Set the after model callback for LLM interaction
4260
+ * @param callback Callback to invoke after receiving LLM response
4261
+ * @returns This builder instance for chaining
4262
+ */
4263
+ withAfterModelCallback(callback: AfterModelCallback): this;
4264
+ /**
4265
+ * Set the before tool callback for tool execution
4266
+ * @param callback Callback to invoke before running a tool
4267
+ * @returns This builder instance for chaining
4268
+ */
4269
+ withBeforeToolCallback(callback: BeforeToolCallback): this;
4270
+ /**
4271
+ * Set the after tool callback for tool execution
4272
+ * @param callback Callback to invoke after running a tool
4273
+ * @returns This builder instance for chaining
4274
+ */
4275
+ withAfterToolCallback(callback: AfterToolCallback): this;
4210
4276
  /**
4211
4277
  * Provide an already constructed agent instance. Further definition-mutating calls
4212
4278
  * (model/tools/instruction/etc.) will be ignored with a dev warning.
@@ -4422,14 +4488,46 @@ declare class InMemoryMemoryService implements BaseMemoryService {
4422
4488
  clear(): void;
4423
4489
  }
4424
4490
 
4491
+ /**
4492
+ * A memory service that uses Vertex AI RAG for storage and retrieval.
4493
+ */
4494
+ declare class VertexAiRagMemoryService implements BaseMemoryService {
4495
+ private _vertexRagStore;
4496
+ /**
4497
+ * Initializes a VertexAiRagMemoryService.
4498
+ *
4499
+ * @param ragCorpus The name of the Vertex AI RAG corpus to use. Format:
4500
+ * `projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
4501
+ * or `{rag_corpus_id}`
4502
+ * @param similarityTopK The number of contexts to retrieve.
4503
+ * @param vectorDistanceThreshold Only returns contexts with vector distance
4504
+ * smaller than the threshold.
4505
+ */
4506
+ constructor(ragCorpus?: string, similarityTopK?: number, vectorDistanceThreshold?: number);
4507
+ /**
4508
+ * Adds a session to the memory service
4509
+ */
4510
+ addSessionToMemory(session: Session): Promise<void>;
4511
+ /**
4512
+ * Searches for sessions that match the query using rag.retrieval_query
4513
+ */
4514
+ searchMemory(options: {
4515
+ appName: string;
4516
+ userId: string;
4517
+ query: string;
4518
+ }): Promise<SearchMemoryResponse>;
4519
+ }
4520
+
4425
4521
  /**
4426
4522
  * Memory Services for the Agent Development Kit
4427
4523
  */
4428
4524
 
4429
4525
  type index$4_InMemoryMemoryService = InMemoryMemoryService;
4430
4526
  declare const index$4_InMemoryMemoryService: typeof InMemoryMemoryService;
4527
+ type index$4_VertexAiRagMemoryService = VertexAiRagMemoryService;
4528
+ declare const index$4_VertexAiRagMemoryService: typeof VertexAiRagMemoryService;
4431
4529
  declare namespace index$4 {
4432
- export { index$4_InMemoryMemoryService as InMemoryMemoryService };
4530
+ export { index$4_InMemoryMemoryService as InMemoryMemoryService, index$4_VertexAiRagMemoryService as VertexAiRagMemoryService };
4433
4531
  }
4434
4532
 
4435
4533
  /**
@@ -5575,4 +5673,4 @@ declare const traceLlmCall: (invocationContext: InvocationContext, eventId: stri
5575
5673
 
5576
5674
  declare const VERSION = "0.1.0";
5577
5675
 
5578
- export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, type AfterModelCallback, type AfterToolCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentBuilderWithSchema, AgentEvaluator, AgentTool, type AgentToolConfig, type AgentType, index$5 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, type BaseAgentType, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BeforeModelCallback, type BeforeToolCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, type CreateToolConfig, type CreateToolConfigWithSchema, type CreateToolConfigWithoutSchema, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, type EvalCase, type EvalCaseResult, type EvalMetric, type EvalMetricResult, type EvalMetricResultPerInvocation, EvalResult, type EvalSet, type EvalSetResult, EvalStatus, type EvaluateConfig, index as Evaluation, type EvaluationResult, Evaluator, Event, EventActions, index$2 as Events, ExitLoopTool, type File, FileOperationsTool, FinalResponseMatchV2Evaluator, index$1 as Flows, type FullMessage, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, type IntermediateData, type Interval, type Invocation, InvocationContext, type JudgeModelOptions, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntents, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, McpUpbit, index$4 as Memory, type MessagePart, type MetricInfo, type MetricValueInfo, index$6 as Models, type MultiAgentResponse, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, type PerInvocationResult, PlanReActPlanner, PrebuiltMetrics, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RougeEvaluator, RunConfig, Runner, type RunnerAskReturn, SafetyEvaluatorV1, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionInput, type SessionOptions, index$3 as Sessions, type SingleAfterModelCallback, type SingleAfterToolCallback, type SingleAgentCallback, type SingleBeforeModelCallback, type SingleBeforeToolCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$7 as Tools, TrajectoryEvaluator, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, convertMcpToolToBaseTool, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, createTool, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
5676
+ export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, type AfterModelCallback, type AfterToolCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentBuilderWithSchema, AgentEvaluator, AgentTool, type AgentToolConfig, type AgentType, index$5 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, type BaseAgentType, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BeforeModelCallback, type BeforeToolCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, type CreateToolConfig, type CreateToolConfigWithSchema, type CreateToolConfigWithoutSchema, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, type EvalCase, type EvalCaseResult, type EvalMetric, type EvalMetricResult, type EvalMetricResultPerInvocation, EvalResult, type EvalSet, type EvalSetResult, EvalStatus, type EvaluateConfig, index as Evaluation, type EvaluationResult, Evaluator, Event, EventActions, index$2 as Events, ExitLoopTool, type File, FileOperationsTool, FinalResponseMatchV2Evaluator, index$1 as Flows, type FullMessage, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, type IntermediateData, type Interval, type Invocation, InvocationContext, type JudgeModelOptions, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, McpCoinGeckoPro, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntents, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, McpUpbit, index$4 as Memory, type MessagePart, type MetricInfo, type MetricValueInfo, index$6 as Models, type MultiAgentResponse, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, type PerInvocationResult, PlanReActPlanner, PrebuiltMetrics, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RougeEvaluator, RunConfig, Runner, type RunnerAskReturn, SafetyEvaluatorV1, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionInput, type SessionOptions, index$3 as Sessions, type SingleAfterModelCallback, type SingleAfterToolCallback, type SingleAgentCallback, type SingleBeforeModelCallback, type SingleBeforeToolCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$7 as Tools, TrajectoryEvaluator, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiRagMemoryService, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, convertMcpToolToBaseTool, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, createTool, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
package/dist/index.d.ts CHANGED
@@ -674,6 +674,18 @@ declare class ReadonlyContext {
674
674
  * The name of the agent that is currently running.
675
675
  */
676
676
  get agentName(): string;
677
+ /**
678
+ * The application name for this invocation. READONLY field.
679
+ */
680
+ get appName(): string;
681
+ /**
682
+ * The user ID for this invocation. READONLY field.
683
+ */
684
+ get userId(): string;
685
+ /**
686
+ * The session ID for this invocation. READONLY field.
687
+ */
688
+ get sessionId(): string;
677
689
  /**
678
690
  * The state of the current session. READONLY field.
679
691
  */
@@ -1255,7 +1267,7 @@ type ToolUnion = BaseTool | ((...args: any[]) => any);
1255
1267
  type SingleBeforeModelCallback = (args: {
1256
1268
  callbackContext: CallbackContext;
1257
1269
  llmRequest: LlmRequest;
1258
- }) => LlmResponse | null | Promise<LlmResponse | null>;
1270
+ }) => LlmResponse | null | undefined | Promise<LlmResponse | null | undefined>;
1259
1271
  /**
1260
1272
  * Before model callback type (single or array)
1261
1273
  */
@@ -1266,7 +1278,7 @@ type BeforeModelCallback = SingleBeforeModelCallback | SingleBeforeModelCallback
1266
1278
  type SingleAfterModelCallback = (args: {
1267
1279
  callbackContext: CallbackContext;
1268
1280
  llmResponse: LlmResponse;
1269
- }) => LlmResponse | null | Promise<LlmResponse | null>;
1281
+ }) => LlmResponse | null | undefined | Promise<LlmResponse | null | undefined>;
1270
1282
  /**
1271
1283
  * After model callback type (single or array)
1272
1284
  */
@@ -1274,7 +1286,7 @@ type AfterModelCallback = SingleAfterModelCallback | SingleAfterModelCallback[];
1274
1286
  /**
1275
1287
  * Single before tool callback type
1276
1288
  */
1277
- type SingleBeforeToolCallback = (tool: BaseTool, args: Record<string, any>, toolContext: ToolContext) => Record<string, any> | null | Promise<Record<string, any> | null>;
1289
+ type SingleBeforeToolCallback = (tool: BaseTool, args: Record<string, any>, toolContext: ToolContext) => Record<string, any> | null | undefined | Promise<Record<string, any> | null | undefined>;
1278
1290
  /**
1279
1291
  * Before tool callback type (single or array)
1280
1292
  */
@@ -1282,7 +1294,7 @@ type BeforeToolCallback = SingleBeforeToolCallback | SingleBeforeToolCallback[];
1282
1294
  /**
1283
1295
  * Single after tool callback type
1284
1296
  */
1285
- type SingleAfterToolCallback = (tool: BaseTool, args: Record<string, any>, toolContext: ToolContext, toolResponse: Record<string, any>) => Record<string, any> | null | Promise<Record<string, any> | null>;
1297
+ type SingleAfterToolCallback = (tool: BaseTool, args: Record<string, any>, toolContext: ToolContext, toolResponse: Record<string, any>) => Record<string, any> | null | undefined | Promise<Record<string, any> | null | undefined>;
1286
1298
  /**
1287
1299
  * After tool callback type (single or array)
1288
1300
  */
@@ -2275,6 +2287,24 @@ declare function createSamplingHandler(handler: SamplingHandler): SamplingHandle
2275
2287
  *
2276
2288
  * @example
2277
2289
  * ```typescript
2290
+ * // Using remote MCP endpoints (CoinGecko):
2291
+ * const coinGeckoTools = await McpCoinGecko().getTools();
2292
+ *
2293
+ * const coinGeckoProTools = await McpCoinGeckoPro({
2294
+ * env: {
2295
+ * COINGECKO_PRO_API_KEY: env.COINGECKO_PRO_API_KEY
2296
+ * }
2297
+ * }).getTools();
2298
+ *
2299
+ * const cryptoAgent = new LlmAgent({
2300
+ * name: "crypto_assistant",
2301
+ * model: "gemini-2.5-flash",
2302
+ * tools: [...coinGeckoTools, ...coinGeckoProTools],
2303
+ * });
2304
+ * ```
2305
+ *
2306
+ * @example
2307
+ * ```typescript
2278
2308
  * // Using MCP servers with sampling handlers:
2279
2309
  * import { createSamplingHandler, LlmResponse } from "@iqai/adk";
2280
2310
  *
@@ -2388,11 +2418,18 @@ declare function McpTelegram(config?: McpServerConfig): McpToolset;
2388
2418
  */
2389
2419
  declare function McpDiscord(config?: McpServerConfig): McpToolset;
2390
2420
  /**
2391
- * MCP CoinGecko - Access cryptocurrency market data and analytics
2421
+ * MCP CoinGecko - Access cryptocurrency market data and analytics via remote endpoint
2392
2422
  *
2393
- * Optional env vars: COINGECKO_PRO_API_KEY, COINGECKO_DEMO_API_KEY, COINGECKO_ENVIRONMENT
2423
+ * Uses the public CoinGecko MCP API endpoint. No API key required for basic functionality.
2394
2424
  */
2395
2425
  declare function McpCoinGecko(config?: McpServerConfig): McpToolset;
2426
+ /**
2427
+ * MCP CoinGecko Pro - Access premium cryptocurrency market data and analytics via remote endpoint
2428
+ *
2429
+ * Uses the professional CoinGecko MCP API endpoint with enhanced features and higher rate limits.
2430
+ * Requires a CoinGecko Pro API subscription.
2431
+ */
2432
+ declare function McpCoinGeckoPro(config?: McpServerConfig): McpToolset;
2396
2433
  /**
2397
2434
  * MCP Upbit - Interact with the Upbit cryptocurrency exchange
2398
2435
  *
@@ -2528,6 +2565,7 @@ declare const index$7_McpAbi: typeof McpAbi;
2528
2565
  declare const index$7_McpAtp: typeof McpAtp;
2529
2566
  declare const index$7_McpBamm: typeof McpBamm;
2530
2567
  declare const index$7_McpCoinGecko: typeof McpCoinGecko;
2568
+ declare const index$7_McpCoinGeckoPro: typeof McpCoinGeckoPro;
2531
2569
  type index$7_McpConfig = McpConfig;
2532
2570
  declare const index$7_McpDiscord: typeof McpDiscord;
2533
2571
  type index$7_McpError = McpError;
@@ -2571,7 +2609,7 @@ declare const index$7_jsonSchemaToDeclaration: typeof jsonSchemaToDeclaration;
2571
2609
  declare const index$7_mcpSchemaToParameters: typeof mcpSchemaToParameters;
2572
2610
  declare const index$7_normalizeJsonSchema: typeof normalizeJsonSchema;
2573
2611
  declare namespace index$7 {
2574
- export { index$7_AgentTool as AgentTool, type index$7_AgentToolConfig as AgentToolConfig, type index$7_BaseAgentType as BaseAgentType, index$7_BaseTool as BaseTool, type index$7_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, type index$7_CreateToolConfig as CreateToolConfig, type index$7_CreateToolConfigWithSchema as CreateToolConfigWithSchema, type index$7_CreateToolConfigWithoutSchema as CreateToolConfigWithoutSchema, index$7_ExitLoopTool as ExitLoopTool, index$7_FileOperationsTool as FileOperationsTool, index$7_FunctionTool as FunctionTool, index$7_GetUserChoiceTool as GetUserChoiceTool, index$7_GoogleSearch as GoogleSearch, index$7_HttpRequestTool as HttpRequestTool, index$7_LoadArtifactsTool as LoadArtifactsTool, index$7_LoadMemoryTool as LoadMemoryTool, index$7_McpAbi as McpAbi, index$7_McpAtp as McpAtp, index$7_McpBamm as McpBamm, index$7_McpCoinGecko as McpCoinGecko, type index$7_McpConfig as McpConfig, index$7_McpDiscord as McpDiscord, index$7_McpError as McpError, index$7_McpErrorType as McpErrorType, index$7_McpFilesystem as McpFilesystem, index$7_McpFraxlend as McpFraxlend, index$7_McpGeneric as McpGeneric, index$7_McpIqWiki as McpIqWiki, index$7_McpMemory as McpMemory, index$7_McpNearAgent as McpNearAgent, index$7_McpNearIntents as McpNearIntents, index$7_McpOdos as McpOdos, index$7_McpSamplingHandler as McpSamplingHandler, type index$7_McpSamplingRequest as McpSamplingRequest, type index$7_McpSamplingResponse as McpSamplingResponse, type index$7_McpServerConfig as McpServerConfig, index$7_McpTelegram as McpTelegram, index$7_McpToolset as McpToolset, type index$7_McpTransportType as McpTransportType, index$7_McpUpbit as McpUpbit, type index$7_SamplingHandler as SamplingHandler, type index$7_ToolConfig as ToolConfig, index$7_ToolContext as ToolContext, index$7_TransferToAgentTool as TransferToAgentTool, index$7_UserInteractionTool as UserInteractionTool, index$7_adkToMcpToolType as adkToMcpToolType, index$7_buildFunctionDeclaration as buildFunctionDeclaration, index$7_convertMcpToolToBaseTool as convertMcpToolToBaseTool, index$7_createFunctionTool as createFunctionTool, index$7_createSamplingHandler as createSamplingHandler, index$7_createTool as createTool, index$7_getMcpTools as getMcpTools, index$7_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$7_mcpSchemaToParameters as mcpSchemaToParameters, index$7_normalizeJsonSchema as normalizeJsonSchema };
2612
+ export { index$7_AgentTool as AgentTool, type index$7_AgentToolConfig as AgentToolConfig, type index$7_BaseAgentType as BaseAgentType, index$7_BaseTool as BaseTool, type index$7_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, type index$7_CreateToolConfig as CreateToolConfig, type index$7_CreateToolConfigWithSchema as CreateToolConfigWithSchema, type index$7_CreateToolConfigWithoutSchema as CreateToolConfigWithoutSchema, index$7_ExitLoopTool as ExitLoopTool, index$7_FileOperationsTool as FileOperationsTool, index$7_FunctionTool as FunctionTool, index$7_GetUserChoiceTool as GetUserChoiceTool, index$7_GoogleSearch as GoogleSearch, index$7_HttpRequestTool as HttpRequestTool, index$7_LoadArtifactsTool as LoadArtifactsTool, index$7_LoadMemoryTool as LoadMemoryTool, index$7_McpAbi as McpAbi, index$7_McpAtp as McpAtp, index$7_McpBamm as McpBamm, index$7_McpCoinGecko as McpCoinGecko, index$7_McpCoinGeckoPro as McpCoinGeckoPro, type index$7_McpConfig as McpConfig, index$7_McpDiscord as McpDiscord, index$7_McpError as McpError, index$7_McpErrorType as McpErrorType, index$7_McpFilesystem as McpFilesystem, index$7_McpFraxlend as McpFraxlend, index$7_McpGeneric as McpGeneric, index$7_McpIqWiki as McpIqWiki, index$7_McpMemory as McpMemory, index$7_McpNearAgent as McpNearAgent, index$7_McpNearIntents as McpNearIntents, index$7_McpOdos as McpOdos, index$7_McpSamplingHandler as McpSamplingHandler, type index$7_McpSamplingRequest as McpSamplingRequest, type index$7_McpSamplingResponse as McpSamplingResponse, type index$7_McpServerConfig as McpServerConfig, index$7_McpTelegram as McpTelegram, index$7_McpToolset as McpToolset, type index$7_McpTransportType as McpTransportType, index$7_McpUpbit as McpUpbit, type index$7_SamplingHandler as SamplingHandler, type index$7_ToolConfig as ToolConfig, index$7_ToolContext as ToolContext, index$7_TransferToAgentTool as TransferToAgentTool, index$7_UserInteractionTool as UserInteractionTool, index$7_adkToMcpToolType as adkToMcpToolType, index$7_buildFunctionDeclaration as buildFunctionDeclaration, index$7_convertMcpToolToBaseTool as convertMcpToolToBaseTool, index$7_createFunctionTool as createFunctionTool, index$7_createSamplingHandler as createSamplingHandler, index$7_createTool as createTool, index$7_getMcpTools as getMcpTools, index$7_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$7_mcpSchemaToParameters as mcpSchemaToParameters, index$7_normalizeJsonSchema as normalizeJsonSchema };
2575
2613
  }
2576
2614
 
2577
2615
  /**
@@ -3997,6 +4035,10 @@ interface AgentBuilderConfig {
3997
4035
  subAgents?: BaseAgent[];
3998
4036
  beforeAgentCallback?: BeforeAgentCallback;
3999
4037
  afterAgentCallback?: AfterAgentCallback;
4038
+ beforeModelCallback?: BeforeModelCallback;
4039
+ afterModelCallback?: AfterModelCallback;
4040
+ beforeToolCallback?: BeforeToolCallback;
4041
+ afterToolCallback?: AfterToolCallback;
4000
4042
  maxIterations?: number;
4001
4043
  nodes?: LangGraphNode[];
4002
4044
  rootNode?: string;
@@ -4207,6 +4249,30 @@ declare class AgentBuilder<TOut = string, TMulti extends boolean = false> {
4207
4249
  * @returns This builder instance for chaining
4208
4250
  */
4209
4251
  withAfterAgentCallback(callback: AfterAgentCallback): this;
4252
+ /**
4253
+ * Set the before model callback for LLM interaction
4254
+ * @param callback Callback to invoke before calling the LLM
4255
+ * @returns This builder instance for chaining
4256
+ */
4257
+ withBeforeModelCallback(callback: BeforeModelCallback): this;
4258
+ /**
4259
+ * Set the after model callback for LLM interaction
4260
+ * @param callback Callback to invoke after receiving LLM response
4261
+ * @returns This builder instance for chaining
4262
+ */
4263
+ withAfterModelCallback(callback: AfterModelCallback): this;
4264
+ /**
4265
+ * Set the before tool callback for tool execution
4266
+ * @param callback Callback to invoke before running a tool
4267
+ * @returns This builder instance for chaining
4268
+ */
4269
+ withBeforeToolCallback(callback: BeforeToolCallback): this;
4270
+ /**
4271
+ * Set the after tool callback for tool execution
4272
+ * @param callback Callback to invoke after running a tool
4273
+ * @returns This builder instance for chaining
4274
+ */
4275
+ withAfterToolCallback(callback: AfterToolCallback): this;
4210
4276
  /**
4211
4277
  * Provide an already constructed agent instance. Further definition-mutating calls
4212
4278
  * (model/tools/instruction/etc.) will be ignored with a dev warning.
@@ -4422,14 +4488,46 @@ declare class InMemoryMemoryService implements BaseMemoryService {
4422
4488
  clear(): void;
4423
4489
  }
4424
4490
 
4491
+ /**
4492
+ * A memory service that uses Vertex AI RAG for storage and retrieval.
4493
+ */
4494
+ declare class VertexAiRagMemoryService implements BaseMemoryService {
4495
+ private _vertexRagStore;
4496
+ /**
4497
+ * Initializes a VertexAiRagMemoryService.
4498
+ *
4499
+ * @param ragCorpus The name of the Vertex AI RAG corpus to use. Format:
4500
+ * `projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
4501
+ * or `{rag_corpus_id}`
4502
+ * @param similarityTopK The number of contexts to retrieve.
4503
+ * @param vectorDistanceThreshold Only returns contexts with vector distance
4504
+ * smaller than the threshold.
4505
+ */
4506
+ constructor(ragCorpus?: string, similarityTopK?: number, vectorDistanceThreshold?: number);
4507
+ /**
4508
+ * Adds a session to the memory service
4509
+ */
4510
+ addSessionToMemory(session: Session): Promise<void>;
4511
+ /**
4512
+ * Searches for sessions that match the query using rag.retrieval_query
4513
+ */
4514
+ searchMemory(options: {
4515
+ appName: string;
4516
+ userId: string;
4517
+ query: string;
4518
+ }): Promise<SearchMemoryResponse>;
4519
+ }
4520
+
4425
4521
  /**
4426
4522
  * Memory Services for the Agent Development Kit
4427
4523
  */
4428
4524
 
4429
4525
  type index$4_InMemoryMemoryService = InMemoryMemoryService;
4430
4526
  declare const index$4_InMemoryMemoryService: typeof InMemoryMemoryService;
4527
+ type index$4_VertexAiRagMemoryService = VertexAiRagMemoryService;
4528
+ declare const index$4_VertexAiRagMemoryService: typeof VertexAiRagMemoryService;
4431
4529
  declare namespace index$4 {
4432
- export { index$4_InMemoryMemoryService as InMemoryMemoryService };
4530
+ export { index$4_InMemoryMemoryService as InMemoryMemoryService, index$4_VertexAiRagMemoryService as VertexAiRagMemoryService };
4433
4531
  }
4434
4532
 
4435
4533
  /**
@@ -5575,4 +5673,4 @@ declare const traceLlmCall: (invocationContext: InvocationContext, eventId: stri
5575
5673
 
5576
5674
  declare const VERSION = "0.1.0";
5577
5675
 
5578
- export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, type AfterModelCallback, type AfterToolCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentBuilderWithSchema, AgentEvaluator, AgentTool, type AgentToolConfig, type AgentType, index$5 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, type BaseAgentType, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BeforeModelCallback, type BeforeToolCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, type CreateToolConfig, type CreateToolConfigWithSchema, type CreateToolConfigWithoutSchema, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, type EvalCase, type EvalCaseResult, type EvalMetric, type EvalMetricResult, type EvalMetricResultPerInvocation, EvalResult, type EvalSet, type EvalSetResult, EvalStatus, type EvaluateConfig, index as Evaluation, type EvaluationResult, Evaluator, Event, EventActions, index$2 as Events, ExitLoopTool, type File, FileOperationsTool, FinalResponseMatchV2Evaluator, index$1 as Flows, type FullMessage, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, type IntermediateData, type Interval, type Invocation, InvocationContext, type JudgeModelOptions, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntents, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, McpUpbit, index$4 as Memory, type MessagePart, type MetricInfo, type MetricValueInfo, index$6 as Models, type MultiAgentResponse, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, type PerInvocationResult, PlanReActPlanner, PrebuiltMetrics, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RougeEvaluator, RunConfig, Runner, type RunnerAskReturn, SafetyEvaluatorV1, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionInput, type SessionOptions, index$3 as Sessions, type SingleAfterModelCallback, type SingleAfterToolCallback, type SingleAgentCallback, type SingleBeforeModelCallback, type SingleBeforeToolCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$7 as Tools, TrajectoryEvaluator, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, convertMcpToolToBaseTool, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, createTool, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
5676
+ export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, type AfterModelCallback, type AfterToolCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentBuilderWithSchema, AgentEvaluator, AgentTool, type AgentToolConfig, type AgentType, index$5 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, type BaseAgentType, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BeforeModelCallback, type BeforeToolCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, type CreateToolConfig, type CreateToolConfigWithSchema, type CreateToolConfigWithoutSchema, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, type EvalCase, type EvalCaseResult, type EvalMetric, type EvalMetricResult, type EvalMetricResultPerInvocation, EvalResult, type EvalSet, type EvalSetResult, EvalStatus, type EvaluateConfig, index as Evaluation, type EvaluationResult, Evaluator, Event, EventActions, index$2 as Events, ExitLoopTool, type File, FileOperationsTool, FinalResponseMatchV2Evaluator, index$1 as Flows, type FullMessage, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, type IntermediateData, type Interval, type Invocation, InvocationContext, type JudgeModelOptions, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, McpCoinGeckoPro, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntents, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, McpUpbit, index$4 as Memory, type MessagePart, type MetricInfo, type MetricValueInfo, index$6 as Models, type MultiAgentResponse, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, type PerInvocationResult, PlanReActPlanner, PrebuiltMetrics, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RougeEvaluator, RunConfig, Runner, type RunnerAskReturn, SafetyEvaluatorV1, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionInput, type SessionOptions, index$3 as Sessions, type SingleAfterModelCallback, type SingleAfterToolCallback, type SingleAgentCallback, type SingleBeforeModelCallback, type SingleBeforeToolCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$7 as Tools, TrajectoryEvaluator, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiRagMemoryService, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, convertMcpToolToBaseTool, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, createTool, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
package/dist/index.js CHANGED
@@ -3521,6 +3521,24 @@ var ReadonlyContext = class {
3521
3521
  get agentName() {
3522
3522
  return this._invocationContext.agent.name;
3523
3523
  }
3524
+ /**
3525
+ * The application name for this invocation. READONLY field.
3526
+ */
3527
+ get appName() {
3528
+ return this._invocationContext.appName;
3529
+ }
3530
+ /**
3531
+ * The user ID for this invocation. READONLY field.
3532
+ */
3533
+ get userId() {
3534
+ return this._invocationContext.userId;
3535
+ }
3536
+ /**
3537
+ * The session ID for this invocation. READONLY field.
3538
+ */
3539
+ get sessionId() {
3540
+ return this._invocationContext.session.id;
3541
+ }
3524
3542
  /**
3525
3543
  * The state of the current session. READONLY field.
3526
3544
  */
@@ -4079,6 +4097,7 @@ __export(tools_exports, {
4079
4097
  McpAtp: () => McpAtp,
4080
4098
  McpBamm: () => McpBamm,
4081
4099
  McpCoinGecko: () => McpCoinGecko,
4100
+ McpCoinGeckoPro: () => McpCoinGeckoPro,
4082
4101
  McpDiscord: () => McpDiscord,
4083
4102
  McpError: () => McpError,
4084
4103
  McpErrorType: () => McpErrorType,
@@ -6123,7 +6142,7 @@ var McpToolAdapter = (_class23 = class extends BaseTool {
6123
6142
  }, _class23);
6124
6143
 
6125
6144
  // src/tools/mcp/servers.ts
6126
- function createMcpConfig(name, packageName, config = {}) {
6145
+ function createMcpConfig(name, packageNameOrUrl, config = {}) {
6127
6146
  const {
6128
6147
  debug,
6129
6148
  description,
@@ -6140,17 +6159,25 @@ function createMcpConfig(name, packageName, config = {}) {
6140
6159
  if (!env.PATH) {
6141
6160
  env.PATH = process.env.PATH || "";
6142
6161
  }
6162
+ let isUrl;
6163
+ try {
6164
+ const url = new URL(packageNameOrUrl);
6165
+ isUrl = url.protocol === "http:" || url.protocol === "https:";
6166
+ } catch (e5) {
6167
+ isUrl = false;
6168
+ }
6169
+ const transport = {
6170
+ mode: "stdio",
6171
+ command: "npx",
6172
+ args: isUrl ? ["-y", "mcp-remote@latest", packageNameOrUrl] : ["-y", packageNameOrUrl],
6173
+ env
6174
+ };
6143
6175
  return {
6144
6176
  name,
6145
6177
  description: description || `Client for ${name}`,
6146
6178
  debug: debug || false,
6147
6179
  retryOptions: retryOptions || { maxRetries: 2, initialDelay: 200 },
6148
- transport: {
6149
- mode: "stdio",
6150
- command: "npx",
6151
- args: ["-y", packageName],
6152
- env
6153
- },
6180
+ transport,
6154
6181
  samplingHandler
6155
6182
  };
6156
6183
  }
@@ -6229,7 +6256,15 @@ function McpDiscord(config = {}) {
6229
6256
  function McpCoinGecko(config = {}) {
6230
6257
  const mcpConfig = createMcpConfig(
6231
6258
  "CoinGecko MCP Client",
6232
- "@coingecko/coingecko-mcp",
6259
+ "https://mcp.api.coingecko.com/mcp",
6260
+ config
6261
+ );
6262
+ return new McpToolset(mcpConfig);
6263
+ }
6264
+ function McpCoinGeckoPro(config = {}) {
6265
+ const mcpConfig = createMcpConfig(
6266
+ "CoinGecko Pro MCP Client",
6267
+ "https://mcp.pro-api.coingecko.com/mcp",
6233
6268
  config
6234
6269
  );
6235
6270
  return new McpToolset(mcpConfig);
@@ -7480,7 +7515,7 @@ var CodeExecutionUtils = class _CodeExecutionUtils {
7480
7515
  static isBase64Encoded(str) {
7481
7516
  try {
7482
7517
  return btoa(atob(str)) === str;
7483
- } catch (e5) {
7518
+ } catch (e6) {
7484
7519
  return false;
7485
7520
  }
7486
7521
  }
@@ -8520,7 +8555,7 @@ var InstructionsLlmRequestProcessor = class extends BaseLlmRequestProcessor {
8520
8555
  llmRequest.appendInstructions([
8521
8556
  'IMPORTANT: After any tool calls, function calls, or agent transfers have completed, produce ONE final assistant message whose entire content is ONLY the JSON object that conforms to the schema provided above. Do NOT include any explanatory text, markdown, or additional messages. Do NOT wrap the JSON in code fences (for example, do NOT use ```json or ```). If you cannot produce valid JSON that matches the schema, return a JSON object with an "error" field describing the problem.'
8522
8557
  ]);
8523
- } catch (e6) {
8558
+ } catch (e7) {
8524
8559
  }
8525
8560
  }
8526
8561
  for await (const _ of []) {
@@ -10860,6 +10895,46 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
10860
10895
  this.config.afterAgentCallback = callback;
10861
10896
  return this;
10862
10897
  }
10898
+ /**
10899
+ * Set the before model callback for LLM interaction
10900
+ * @param callback Callback to invoke before calling the LLM
10901
+ * @returns This builder instance for chaining
10902
+ */
10903
+ withBeforeModelCallback(callback) {
10904
+ this.warnIfLocked("withBeforeModelCallback");
10905
+ this.config.beforeModelCallback = callback;
10906
+ return this;
10907
+ }
10908
+ /**
10909
+ * Set the after model callback for LLM interaction
10910
+ * @param callback Callback to invoke after receiving LLM response
10911
+ * @returns This builder instance for chaining
10912
+ */
10913
+ withAfterModelCallback(callback) {
10914
+ this.warnIfLocked("withAfterModelCallback");
10915
+ this.config.afterModelCallback = callback;
10916
+ return this;
10917
+ }
10918
+ /**
10919
+ * Set the before tool callback for tool execution
10920
+ * @param callback Callback to invoke before running a tool
10921
+ * @returns This builder instance for chaining
10922
+ */
10923
+ withBeforeToolCallback(callback) {
10924
+ this.warnIfLocked("withBeforeToolCallback");
10925
+ this.config.beforeToolCallback = callback;
10926
+ return this;
10927
+ }
10928
+ /**
10929
+ * Set the after tool callback for tool execution
10930
+ * @param callback Callback to invoke after running a tool
10931
+ * @returns This builder instance for chaining
10932
+ */
10933
+ withAfterToolCallback(callback) {
10934
+ this.warnIfLocked("withAfterToolCallback");
10935
+ this.config.afterToolCallback = callback;
10936
+ return this;
10937
+ }
10863
10938
  /**
10864
10939
  * Provide an already constructed agent instance. Further definition-mutating calls
10865
10940
  * (model/tools/instruction/etc.) will be ignored with a dev warning.
@@ -11133,6 +11208,10 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
11133
11208
  subAgents: this.config.subAgents,
11134
11209
  beforeAgentCallback: this.config.beforeAgentCallback,
11135
11210
  afterAgentCallback: this.config.afterAgentCallback,
11211
+ beforeModelCallback: this.config.beforeModelCallback,
11212
+ afterModelCallback: this.config.afterModelCallback,
11213
+ beforeToolCallback: this.config.beforeToolCallback,
11214
+ afterToolCallback: this.config.afterToolCallback,
11136
11215
  memoryService: this.memoryService,
11137
11216
  artifactService: this.artifactService,
11138
11217
  outputKey: this.config.outputKey,
@@ -11295,9 +11374,183 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
11295
11374
  // src/memory/index.ts
11296
11375
  var memory_exports = {};
11297
11376
  __export(memory_exports, {
11298
- InMemoryMemoryService: () => InMemoryMemoryService
11377
+ InMemoryMemoryService: () => InMemoryMemoryService,
11378
+ VertexAiRagMemoryService: () => VertexAiRagMemoryService
11299
11379
  });
11300
11380
 
11381
+ // src/memory/vertex-ai-rag-memory-service.ts
11382
+
11383
+ var _fs = require('fs');
11384
+ var _os = require('os');
11385
+
11386
+ var rag = {
11387
+ async upload_file(options) {
11388
+ console.log("Mock upload_file:", options);
11389
+ },
11390
+ async retrieval_query(options) {
11391
+ console.log("Mock retrieval_query:", options);
11392
+ return { contexts: { contexts: [] } };
11393
+ }
11394
+ };
11395
+ function _mergeEventLists(eventLists) {
11396
+ const merged = [];
11397
+ while (eventLists.length > 0) {
11398
+ const current = eventLists.shift();
11399
+ const currentTs = new Set(current.map((event) => event.timestamp));
11400
+ let mergeFound = true;
11401
+ while (mergeFound) {
11402
+ mergeFound = false;
11403
+ const remaining = [];
11404
+ for (const other of eventLists) {
11405
+ const otherTs = new Set(other.map((event) => event.timestamp));
11406
+ const hasOverlap = Array.from(currentTs).some((ts) => otherTs.has(ts));
11407
+ if (hasOverlap) {
11408
+ const newEvents = other.filter((e) => !currentTs.has(e.timestamp));
11409
+ current.push(...newEvents);
11410
+ newEvents.forEach((e) => currentTs.add(e.timestamp));
11411
+ mergeFound = true;
11412
+ } else {
11413
+ remaining.push(other);
11414
+ }
11415
+ }
11416
+ eventLists.splice(0, eventLists.length, ...remaining);
11417
+ }
11418
+ merged.push(current);
11419
+ }
11420
+ return merged;
11421
+ }
11422
+ var VertexAiRagMemoryService = class {
11423
+
11424
+ /**
11425
+ * Initializes a VertexAiRagMemoryService.
11426
+ *
11427
+ * @param ragCorpus The name of the Vertex AI RAG corpus to use. Format:
11428
+ * `projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
11429
+ * or `{rag_corpus_id}`
11430
+ * @param similarityTopK The number of contexts to retrieve.
11431
+ * @param vectorDistanceThreshold Only returns contexts with vector distance
11432
+ * smaller than the threshold.
11433
+ */
11434
+ constructor(ragCorpus, similarityTopK, vectorDistanceThreshold = 10) {
11435
+ this._vertexRagStore = {
11436
+ rag_resources: ragCorpus ? [{ rag_corpus: ragCorpus }] : [],
11437
+ similarity_top_k: similarityTopK,
11438
+ vector_distance_threshold: vectorDistanceThreshold
11439
+ };
11440
+ }
11441
+ /**
11442
+ * Adds a session to the memory service
11443
+ */
11444
+ async addSessionToMemory(session) {
11445
+ const tempFileName = `temp_${_crypto.randomUUID.call(void 0, )}.txt`;
11446
+ const tempFilePath = _path.join.call(void 0, _os.tmpdir.call(void 0, ), tempFileName);
11447
+ try {
11448
+ const outputLines = [];
11449
+ for (const event of session.events) {
11450
+ if (!event.content || !event.content.parts) {
11451
+ continue;
11452
+ }
11453
+ const textParts = event.content.parts.filter((part) => part.text).map((part) => part.text.replace(/\n/g, " "));
11454
+ if (textParts.length > 0) {
11455
+ outputLines.push(
11456
+ JSON.stringify({
11457
+ author: event.author,
11458
+ timestamp: event.timestamp,
11459
+ text: textParts.join(".")
11460
+ })
11461
+ );
11462
+ }
11463
+ }
11464
+ const outputString = outputLines.join("\n");
11465
+ _fs.writeFileSync.call(void 0, tempFilePath, outputString, "utf8");
11466
+ if (!this._vertexRagStore.rag_resources || this._vertexRagStore.rag_resources.length === 0) {
11467
+ throw new Error("Rag resources must be set.");
11468
+ }
11469
+ for (const ragResource of this._vertexRagStore.rag_resources) {
11470
+ await rag.upload_file({
11471
+ corpus_name: ragResource.rag_corpus,
11472
+ path: tempFilePath,
11473
+ // This is the temp workaround as upload file does not support
11474
+ // adding metadata, thus use display_name to store the session info.
11475
+ display_name: `${session.appName}.${session.userId}.${session.id}`
11476
+ });
11477
+ }
11478
+ } finally {
11479
+ try {
11480
+ _fs.unlinkSync.call(void 0, tempFilePath);
11481
+ } catch (error) {
11482
+ console.warn("Failed to delete temporary file:", tempFilePath, error);
11483
+ }
11484
+ }
11485
+ }
11486
+ /**
11487
+ * Searches for sessions that match the query using rag.retrieval_query
11488
+ */
11489
+ async searchMemory(options) {
11490
+ const { appName, userId, query } = options;
11491
+ const response = await rag.retrieval_query({
11492
+ text: query,
11493
+ rag_resources: this._vertexRagStore.rag_resources,
11494
+ rag_corpora: this._vertexRagStore.rag_corpora,
11495
+ similarity_top_k: this._vertexRagStore.similarity_top_k,
11496
+ vector_distance_threshold: this._vertexRagStore.vector_distance_threshold
11497
+ });
11498
+ const memoryResults = [];
11499
+ const sessionEventsMap = /* @__PURE__ */ new Map();
11500
+ for (const context4 of response.contexts.contexts) {
11501
+ if (!context4.source_display_name.startsWith(`${appName}.${userId}.`)) {
11502
+ continue;
11503
+ }
11504
+ const sessionId = context4.source_display_name.split(".").pop();
11505
+ const events = [];
11506
+ if (context4.text) {
11507
+ const lines = context4.text.split("\n");
11508
+ for (const line of lines) {
11509
+ const trimmedLine = line.trim();
11510
+ if (!trimmedLine) {
11511
+ continue;
11512
+ }
11513
+ try {
11514
+ const eventData = JSON.parse(trimmedLine);
11515
+ const author = eventData.author || "";
11516
+ const timestamp = Number.parseFloat(eventData.timestamp || "0");
11517
+ const text = eventData.text || "";
11518
+ const content = {
11519
+ parts: [{ text }]
11520
+ };
11521
+ const event = {
11522
+ author,
11523
+ timestamp,
11524
+ content
11525
+ };
11526
+ events.push(event);
11527
+ } catch (e8) {
11528
+ }
11529
+ }
11530
+ }
11531
+ if (sessionEventsMap.has(sessionId)) {
11532
+ sessionEventsMap.get(sessionId).push(events);
11533
+ } else {
11534
+ sessionEventsMap.set(sessionId, [events]);
11535
+ }
11536
+ }
11537
+ for (const [sessionId, eventLists] of sessionEventsMap.entries()) {
11538
+ const mergedEventLists = _mergeEventLists(eventLists);
11539
+ for (const events of mergedEventLists) {
11540
+ const sortedEvents = events.sort((a, b) => a.timestamp - b.timestamp).filter((event) => event.content);
11541
+ memoryResults.push(
11542
+ ...sortedEvents.map((event) => ({
11543
+ author: event.author,
11544
+ content: event.content,
11545
+ timestamp: formatTimestamp(event.timestamp)
11546
+ }))
11547
+ );
11548
+ }
11549
+ }
11550
+ return { memories: memoryResults };
11551
+ }
11552
+ };
11553
+
11301
11554
  // src/sessions/index.ts
11302
11555
  var sessions_exports = {};
11303
11556
  __export(sessions_exports, {
@@ -11703,7 +11956,7 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
11703
11956
  if (!jsonString) return defaultValue;
11704
11957
  try {
11705
11958
  return JSON.parse(jsonString);
11706
- } catch (e7) {
11959
+ } catch (e9) {
11707
11960
  return defaultValue;
11708
11961
  }
11709
11962
  }
@@ -13729,4 +13982,6 @@ var VERSION = "0.1.0";
13729
13982
 
13730
13983
 
13731
13984
 
13732
- exports.AF_FUNCTION_CALL_ID_PREFIX = AF_FUNCTION_CALL_ID_PREFIX; exports.Agent = LlmAgent; exports.AgentBuilder = AgentBuilder; exports.AgentEvaluator = AgentEvaluator; exports.AgentTool = AgentTool; exports.Agents = agents_exports; exports.AiSdkLlm = AiSdkLlm; exports.AnthropicLlm = AnthropicLlm; exports.ApiKeyCredential = ApiKeyCredential; exports.ApiKeyScheme = ApiKeyScheme; exports.AuthConfig = AuthConfig; exports.AuthCredential = AuthCredential; exports.AuthCredentialType = AuthCredentialType; exports.AuthHandler = AuthHandler; exports.AuthScheme = AuthScheme; exports.AuthSchemeType = AuthSchemeType; exports.AuthTool = AuthTool; exports.AutoFlow = AutoFlow; exports.BaseAgent = BaseAgent; exports.BaseCodeExecutor = BaseCodeExecutor; exports.BaseLLMConnection = BaseLLMConnection; exports.BaseLlm = BaseLlm; exports.BaseLlmFlow = BaseLlmFlow; exports.BaseLlmRequestProcessor = BaseLlmRequestProcessor; exports.BaseLlmResponseProcessor = BaseLlmResponseProcessor; exports.BasePlanner = BasePlanner; exports.BaseSessionService = BaseSessionService; exports.BaseTool = BaseTool; exports.BasicAuthCredential = BasicAuthCredential; exports.BearerTokenCredential = BearerTokenCredential; exports.BuiltInCodeExecutor = BuiltInCodeExecutor; exports.BuiltInPlanner = BuiltInPlanner; exports.CallbackContext = CallbackContext; exports.CodeExecutionUtils = CodeExecutionUtils; exports.CodeExecutorContext = CodeExecutorContext; exports.DatabaseSessionService = DatabaseSessionService; exports.EnhancedAuthConfig = EnhancedAuthConfig; exports.EvalResult = EvalResult; exports.EvalStatus = EvalStatus; exports.Evaluation = evaluation_exports; exports.Evaluator = Evaluator; exports.Event = Event; exports.EventActions = EventActions; exports.Events = events_exports; exports.ExitLoopTool = ExitLoopTool; exports.FileOperationsTool = FileOperationsTool; exports.FinalResponseMatchV2Evaluator = FinalResponseMatchV2Evaluator; exports.Flows = flows_exports; exports.FunctionTool = FunctionTool; exports.GcsArtifactService = GcsArtifactService; exports.GetUserChoiceTool = GetUserChoiceTool; exports.GoogleLlm = GoogleLlm; exports.GoogleSearch = GoogleSearch; exports.HttpRequestTool = HttpRequestTool; exports.HttpScheme = HttpScheme; exports.InMemoryArtifactService = InMemoryArtifactService; exports.InMemoryMemoryService = InMemoryMemoryService; exports.InMemoryRunner = InMemoryRunner; exports.InMemorySessionService = InMemorySessionService; exports.InvocationContext = InvocationContext; exports.LLMRegistry = LLMRegistry; exports.LangGraphAgent = LangGraphAgent; exports.LlmAgent = LlmAgent; exports.LlmCallsLimitExceededError = LlmCallsLimitExceededError; exports.LlmRequest = LlmRequest; exports.LlmResponse = LlmResponse; exports.LoadArtifactsTool = LoadArtifactsTool; exports.LoadMemoryTool = LoadMemoryTool; exports.LocalEvalService = LocalEvalService; exports.LoopAgent = LoopAgent; exports.McpAbi = McpAbi; exports.McpAtp = McpAtp; exports.McpBamm = McpBamm; exports.McpCoinGecko = McpCoinGecko; exports.McpDiscord = McpDiscord; exports.McpError = McpError; exports.McpErrorType = McpErrorType; exports.McpFilesystem = McpFilesystem; exports.McpFraxlend = McpFraxlend; exports.McpGeneric = McpGeneric; exports.McpIqWiki = McpIqWiki; exports.McpMemory = McpMemory; exports.McpNearAgent = McpNearAgent; exports.McpNearIntents = McpNearIntents; exports.McpOdos = McpOdos; exports.McpSamplingHandler = McpSamplingHandler; exports.McpTelegram = McpTelegram; exports.McpToolset = McpToolset; exports.McpUpbit = McpUpbit; exports.Memory = memory_exports; exports.Models = models_exports; exports.OAuth2Credential = OAuth2Credential; exports.OAuth2Scheme = OAuth2Scheme; exports.OpenAiLlm = OpenAiLlm; exports.OpenIdConnectScheme = OpenIdConnectScheme; exports.ParallelAgent = ParallelAgent; exports.PlanReActPlanner = PlanReActPlanner; exports.PrebuiltMetrics = PrebuiltMetrics; exports.REQUEST_EUC_FUNCTION_CALL_NAME = REQUEST_EUC_FUNCTION_CALL_NAME; exports.ReadonlyContext = ReadonlyContext; exports.RougeEvaluator = RougeEvaluator; exports.RunConfig = RunConfig; exports.Runner = Runner; exports.SafetyEvaluatorV1 = SafetyEvaluatorV1; exports.SequentialAgent = SequentialAgent; exports.Sessions = sessions_exports; exports.SingleFlow = SingleFlow; exports.State = State; exports.StreamingMode = StreamingMode; exports.TelemetryService = TelemetryService; exports.ToolContext = ToolContext; exports.Tools = tools_exports; exports.TrajectoryEvaluator = TrajectoryEvaluator; exports.TransferToAgentTool = TransferToAgentTool; exports.UserInteractionTool = UserInteractionTool; exports.VERSION = VERSION; exports.VertexAiSessionService = VertexAiSessionService; exports._findFunctionCallEventIfLastEventIsFunctionResponse = _findFunctionCallEventIfLastEventIsFunctionResponse; exports.adkToMcpToolType = adkToMcpToolType; exports.agentTransferRequestProcessor = requestProcessor8; exports.basicRequestProcessor = requestProcessor2; exports.buildFunctionDeclaration = buildFunctionDeclaration; exports.codeExecutionRequestProcessor = requestProcessor3; exports.codeExecutionResponseProcessor = responseProcessor; exports.contentRequestProcessor = requestProcessor4; exports.convertMcpToolToBaseTool = convertMcpToolToBaseTool; exports.createAuthToolArguments = createAuthToolArguments; exports.createBranchContextForSubAgent = createBranchContextForSubAgent; exports.createDatabaseSessionService = createDatabaseSessionService; exports.createFunctionTool = createFunctionTool; exports.createMysqlSessionService = createMysqlSessionService; exports.createPostgresSessionService = createPostgresSessionService; exports.createSamplingHandler = createSamplingHandler; exports.createSqliteSessionService = createSqliteSessionService; exports.createTool = createTool; exports.generateAuthEvent = generateAuthEvent; exports.generateClientFunctionCallId = generateClientFunctionCallId; exports.getLongRunningFunctionCalls = getLongRunningFunctionCalls; exports.getMcpTools = getMcpTools; exports.handleFunctionCallsAsync = handleFunctionCallsAsync; exports.handleFunctionCallsLive = handleFunctionCallsLive; exports.identityRequestProcessor = requestProcessor5; exports.initializeTelemetry = initializeTelemetry; exports.injectSessionState = injectSessionState; exports.instructionsRequestProcessor = requestProcessor6; exports.isEnhancedAuthConfig = isEnhancedAuthConfig; exports.jsonSchemaToDeclaration = jsonSchemaToDeclaration; exports.mcpSchemaToParameters = mcpSchemaToParameters; exports.mergeAgentRun = mergeAgentRun; exports.mergeParallelFunctionResponseEvents = mergeParallelFunctionResponseEvents; exports.newInvocationContextId = newInvocationContextId; exports.nlPlanningRequestProcessor = requestProcessor7; exports.nlPlanningResponseProcessor = responseProcessor2; exports.normalizeJsonSchema = normalizeJsonSchema; exports.populateClientFunctionCallId = populateClientFunctionCallId; exports.registerProviders = registerProviders; exports.removeClientFunctionCallId = removeClientFunctionCallId; exports.requestProcessor = requestProcessor; exports.shutdownTelemetry = shutdownTelemetry; exports.telemetryService = telemetryService; exports.traceLlmCall = traceLlmCall; exports.traceToolCall = traceToolCall; exports.tracer = tracer;
13985
+
13986
+
13987
+ exports.AF_FUNCTION_CALL_ID_PREFIX = AF_FUNCTION_CALL_ID_PREFIX; exports.Agent = LlmAgent; exports.AgentBuilder = AgentBuilder; exports.AgentEvaluator = AgentEvaluator; exports.AgentTool = AgentTool; exports.Agents = agents_exports; exports.AiSdkLlm = AiSdkLlm; exports.AnthropicLlm = AnthropicLlm; exports.ApiKeyCredential = ApiKeyCredential; exports.ApiKeyScheme = ApiKeyScheme; exports.AuthConfig = AuthConfig; exports.AuthCredential = AuthCredential; exports.AuthCredentialType = AuthCredentialType; exports.AuthHandler = AuthHandler; exports.AuthScheme = AuthScheme; exports.AuthSchemeType = AuthSchemeType; exports.AuthTool = AuthTool; exports.AutoFlow = AutoFlow; exports.BaseAgent = BaseAgent; exports.BaseCodeExecutor = BaseCodeExecutor; exports.BaseLLMConnection = BaseLLMConnection; exports.BaseLlm = BaseLlm; exports.BaseLlmFlow = BaseLlmFlow; exports.BaseLlmRequestProcessor = BaseLlmRequestProcessor; exports.BaseLlmResponseProcessor = BaseLlmResponseProcessor; exports.BasePlanner = BasePlanner; exports.BaseSessionService = BaseSessionService; exports.BaseTool = BaseTool; exports.BasicAuthCredential = BasicAuthCredential; exports.BearerTokenCredential = BearerTokenCredential; exports.BuiltInCodeExecutor = BuiltInCodeExecutor; exports.BuiltInPlanner = BuiltInPlanner; exports.CallbackContext = CallbackContext; exports.CodeExecutionUtils = CodeExecutionUtils; exports.CodeExecutorContext = CodeExecutorContext; exports.DatabaseSessionService = DatabaseSessionService; exports.EnhancedAuthConfig = EnhancedAuthConfig; exports.EvalResult = EvalResult; exports.EvalStatus = EvalStatus; exports.Evaluation = evaluation_exports; exports.Evaluator = Evaluator; exports.Event = Event; exports.EventActions = EventActions; exports.Events = events_exports; exports.ExitLoopTool = ExitLoopTool; exports.FileOperationsTool = FileOperationsTool; exports.FinalResponseMatchV2Evaluator = FinalResponseMatchV2Evaluator; exports.Flows = flows_exports; exports.FunctionTool = FunctionTool; exports.GcsArtifactService = GcsArtifactService; exports.GetUserChoiceTool = GetUserChoiceTool; exports.GoogleLlm = GoogleLlm; exports.GoogleSearch = GoogleSearch; exports.HttpRequestTool = HttpRequestTool; exports.HttpScheme = HttpScheme; exports.InMemoryArtifactService = InMemoryArtifactService; exports.InMemoryMemoryService = InMemoryMemoryService; exports.InMemoryRunner = InMemoryRunner; exports.InMemorySessionService = InMemorySessionService; exports.InvocationContext = InvocationContext; exports.LLMRegistry = LLMRegistry; exports.LangGraphAgent = LangGraphAgent; exports.LlmAgent = LlmAgent; exports.LlmCallsLimitExceededError = LlmCallsLimitExceededError; exports.LlmRequest = LlmRequest; exports.LlmResponse = LlmResponse; exports.LoadArtifactsTool = LoadArtifactsTool; exports.LoadMemoryTool = LoadMemoryTool; exports.LocalEvalService = LocalEvalService; exports.LoopAgent = LoopAgent; exports.McpAbi = McpAbi; exports.McpAtp = McpAtp; exports.McpBamm = McpBamm; exports.McpCoinGecko = McpCoinGecko; exports.McpCoinGeckoPro = McpCoinGeckoPro; exports.McpDiscord = McpDiscord; exports.McpError = McpError; exports.McpErrorType = McpErrorType; exports.McpFilesystem = McpFilesystem; exports.McpFraxlend = McpFraxlend; exports.McpGeneric = McpGeneric; exports.McpIqWiki = McpIqWiki; exports.McpMemory = McpMemory; exports.McpNearAgent = McpNearAgent; exports.McpNearIntents = McpNearIntents; exports.McpOdos = McpOdos; exports.McpSamplingHandler = McpSamplingHandler; exports.McpTelegram = McpTelegram; exports.McpToolset = McpToolset; exports.McpUpbit = McpUpbit; exports.Memory = memory_exports; exports.Models = models_exports; exports.OAuth2Credential = OAuth2Credential; exports.OAuth2Scheme = OAuth2Scheme; exports.OpenAiLlm = OpenAiLlm; exports.OpenIdConnectScheme = OpenIdConnectScheme; exports.ParallelAgent = ParallelAgent; exports.PlanReActPlanner = PlanReActPlanner; exports.PrebuiltMetrics = PrebuiltMetrics; exports.REQUEST_EUC_FUNCTION_CALL_NAME = REQUEST_EUC_FUNCTION_CALL_NAME; exports.ReadonlyContext = ReadonlyContext; exports.RougeEvaluator = RougeEvaluator; exports.RunConfig = RunConfig; exports.Runner = Runner; exports.SafetyEvaluatorV1 = SafetyEvaluatorV1; exports.SequentialAgent = SequentialAgent; exports.Sessions = sessions_exports; exports.SingleFlow = SingleFlow; exports.State = State; exports.StreamingMode = StreamingMode; exports.TelemetryService = TelemetryService; exports.ToolContext = ToolContext; exports.Tools = tools_exports; exports.TrajectoryEvaluator = TrajectoryEvaluator; exports.TransferToAgentTool = TransferToAgentTool; exports.UserInteractionTool = UserInteractionTool; exports.VERSION = VERSION; exports.VertexAiRagMemoryService = VertexAiRagMemoryService; exports.VertexAiSessionService = VertexAiSessionService; exports._findFunctionCallEventIfLastEventIsFunctionResponse = _findFunctionCallEventIfLastEventIsFunctionResponse; exports.adkToMcpToolType = adkToMcpToolType; exports.agentTransferRequestProcessor = requestProcessor8; exports.basicRequestProcessor = requestProcessor2; exports.buildFunctionDeclaration = buildFunctionDeclaration; exports.codeExecutionRequestProcessor = requestProcessor3; exports.codeExecutionResponseProcessor = responseProcessor; exports.contentRequestProcessor = requestProcessor4; exports.convertMcpToolToBaseTool = convertMcpToolToBaseTool; exports.createAuthToolArguments = createAuthToolArguments; exports.createBranchContextForSubAgent = createBranchContextForSubAgent; exports.createDatabaseSessionService = createDatabaseSessionService; exports.createFunctionTool = createFunctionTool; exports.createMysqlSessionService = createMysqlSessionService; exports.createPostgresSessionService = createPostgresSessionService; exports.createSamplingHandler = createSamplingHandler; exports.createSqliteSessionService = createSqliteSessionService; exports.createTool = createTool; exports.generateAuthEvent = generateAuthEvent; exports.generateClientFunctionCallId = generateClientFunctionCallId; exports.getLongRunningFunctionCalls = getLongRunningFunctionCalls; exports.getMcpTools = getMcpTools; exports.handleFunctionCallsAsync = handleFunctionCallsAsync; exports.handleFunctionCallsLive = handleFunctionCallsLive; exports.identityRequestProcessor = requestProcessor5; exports.initializeTelemetry = initializeTelemetry; exports.injectSessionState = injectSessionState; exports.instructionsRequestProcessor = requestProcessor6; exports.isEnhancedAuthConfig = isEnhancedAuthConfig; exports.jsonSchemaToDeclaration = jsonSchemaToDeclaration; exports.mcpSchemaToParameters = mcpSchemaToParameters; exports.mergeAgentRun = mergeAgentRun; exports.mergeParallelFunctionResponseEvents = mergeParallelFunctionResponseEvents; exports.newInvocationContextId = newInvocationContextId; exports.nlPlanningRequestProcessor = requestProcessor7; exports.nlPlanningResponseProcessor = responseProcessor2; exports.normalizeJsonSchema = normalizeJsonSchema; exports.populateClientFunctionCallId = populateClientFunctionCallId; exports.registerProviders = registerProviders; exports.removeClientFunctionCallId = removeClientFunctionCallId; exports.requestProcessor = requestProcessor; exports.shutdownTelemetry = shutdownTelemetry; exports.telemetryService = telemetryService; exports.traceLlmCall = traceLlmCall; exports.traceToolCall = traceToolCall; exports.tracer = tracer;
package/dist/index.mjs CHANGED
@@ -3521,6 +3521,24 @@ var ReadonlyContext = class {
3521
3521
  get agentName() {
3522
3522
  return this._invocationContext.agent.name;
3523
3523
  }
3524
+ /**
3525
+ * The application name for this invocation. READONLY field.
3526
+ */
3527
+ get appName() {
3528
+ return this._invocationContext.appName;
3529
+ }
3530
+ /**
3531
+ * The user ID for this invocation. READONLY field.
3532
+ */
3533
+ get userId() {
3534
+ return this._invocationContext.userId;
3535
+ }
3536
+ /**
3537
+ * The session ID for this invocation. READONLY field.
3538
+ */
3539
+ get sessionId() {
3540
+ return this._invocationContext.session.id;
3541
+ }
3524
3542
  /**
3525
3543
  * The state of the current session. READONLY field.
3526
3544
  */
@@ -4079,6 +4097,7 @@ __export(tools_exports, {
4079
4097
  McpAtp: () => McpAtp,
4080
4098
  McpBamm: () => McpBamm,
4081
4099
  McpCoinGecko: () => McpCoinGecko,
4100
+ McpCoinGeckoPro: () => McpCoinGeckoPro,
4082
4101
  McpDiscord: () => McpDiscord,
4083
4102
  McpError: () => McpError,
4084
4103
  McpErrorType: () => McpErrorType,
@@ -6123,7 +6142,7 @@ var McpToolAdapter = class extends BaseTool {
6123
6142
  };
6124
6143
 
6125
6144
  // src/tools/mcp/servers.ts
6126
- function createMcpConfig(name, packageName, config = {}) {
6145
+ function createMcpConfig(name, packageNameOrUrl, config = {}) {
6127
6146
  const {
6128
6147
  debug,
6129
6148
  description,
@@ -6140,17 +6159,25 @@ function createMcpConfig(name, packageName, config = {}) {
6140
6159
  if (!env.PATH) {
6141
6160
  env.PATH = process.env.PATH || "";
6142
6161
  }
6162
+ let isUrl;
6163
+ try {
6164
+ const url = new URL(packageNameOrUrl);
6165
+ isUrl = url.protocol === "http:" || url.protocol === "https:";
6166
+ } catch {
6167
+ isUrl = false;
6168
+ }
6169
+ const transport = {
6170
+ mode: "stdio",
6171
+ command: "npx",
6172
+ args: isUrl ? ["-y", "mcp-remote@latest", packageNameOrUrl] : ["-y", packageNameOrUrl],
6173
+ env
6174
+ };
6143
6175
  return {
6144
6176
  name,
6145
6177
  description: description || `Client for ${name}`,
6146
6178
  debug: debug || false,
6147
6179
  retryOptions: retryOptions || { maxRetries: 2, initialDelay: 200 },
6148
- transport: {
6149
- mode: "stdio",
6150
- command: "npx",
6151
- args: ["-y", packageName],
6152
- env
6153
- },
6180
+ transport,
6154
6181
  samplingHandler
6155
6182
  };
6156
6183
  }
@@ -6229,7 +6256,15 @@ function McpDiscord(config = {}) {
6229
6256
  function McpCoinGecko(config = {}) {
6230
6257
  const mcpConfig = createMcpConfig(
6231
6258
  "CoinGecko MCP Client",
6232
- "@coingecko/coingecko-mcp",
6259
+ "https://mcp.api.coingecko.com/mcp",
6260
+ config
6261
+ );
6262
+ return new McpToolset(mcpConfig);
6263
+ }
6264
+ function McpCoinGeckoPro(config = {}) {
6265
+ const mcpConfig = createMcpConfig(
6266
+ "CoinGecko Pro MCP Client",
6267
+ "https://mcp.pro-api.coingecko.com/mcp",
6233
6268
  config
6234
6269
  );
6235
6270
  return new McpToolset(mcpConfig);
@@ -10860,6 +10895,46 @@ var AgentBuilder = class _AgentBuilder {
10860
10895
  this.config.afterAgentCallback = callback;
10861
10896
  return this;
10862
10897
  }
10898
+ /**
10899
+ * Set the before model callback for LLM interaction
10900
+ * @param callback Callback to invoke before calling the LLM
10901
+ * @returns This builder instance for chaining
10902
+ */
10903
+ withBeforeModelCallback(callback) {
10904
+ this.warnIfLocked("withBeforeModelCallback");
10905
+ this.config.beforeModelCallback = callback;
10906
+ return this;
10907
+ }
10908
+ /**
10909
+ * Set the after model callback for LLM interaction
10910
+ * @param callback Callback to invoke after receiving LLM response
10911
+ * @returns This builder instance for chaining
10912
+ */
10913
+ withAfterModelCallback(callback) {
10914
+ this.warnIfLocked("withAfterModelCallback");
10915
+ this.config.afterModelCallback = callback;
10916
+ return this;
10917
+ }
10918
+ /**
10919
+ * Set the before tool callback for tool execution
10920
+ * @param callback Callback to invoke before running a tool
10921
+ * @returns This builder instance for chaining
10922
+ */
10923
+ withBeforeToolCallback(callback) {
10924
+ this.warnIfLocked("withBeforeToolCallback");
10925
+ this.config.beforeToolCallback = callback;
10926
+ return this;
10927
+ }
10928
+ /**
10929
+ * Set the after tool callback for tool execution
10930
+ * @param callback Callback to invoke after running a tool
10931
+ * @returns This builder instance for chaining
10932
+ */
10933
+ withAfterToolCallback(callback) {
10934
+ this.warnIfLocked("withAfterToolCallback");
10935
+ this.config.afterToolCallback = callback;
10936
+ return this;
10937
+ }
10863
10938
  /**
10864
10939
  * Provide an already constructed agent instance. Further definition-mutating calls
10865
10940
  * (model/tools/instruction/etc.) will be ignored with a dev warning.
@@ -11133,6 +11208,10 @@ var AgentBuilder = class _AgentBuilder {
11133
11208
  subAgents: this.config.subAgents,
11134
11209
  beforeAgentCallback: this.config.beforeAgentCallback,
11135
11210
  afterAgentCallback: this.config.afterAgentCallback,
11211
+ beforeModelCallback: this.config.beforeModelCallback,
11212
+ afterModelCallback: this.config.afterModelCallback,
11213
+ beforeToolCallback: this.config.beforeToolCallback,
11214
+ afterToolCallback: this.config.afterToolCallback,
11136
11215
  memoryService: this.memoryService,
11137
11216
  artifactService: this.artifactService,
11138
11217
  outputKey: this.config.outputKey,
@@ -11295,9 +11374,183 @@ var AgentBuilder = class _AgentBuilder {
11295
11374
  // src/memory/index.ts
11296
11375
  var memory_exports = {};
11297
11376
  __export(memory_exports, {
11298
- InMemoryMemoryService: () => InMemoryMemoryService
11377
+ InMemoryMemoryService: () => InMemoryMemoryService,
11378
+ VertexAiRagMemoryService: () => VertexAiRagMemoryService
11299
11379
  });
11300
11380
 
11381
+ // src/memory/vertex-ai-rag-memory-service.ts
11382
+ import { randomUUID as randomUUID2 } from "crypto";
11383
+ import { unlinkSync, writeFileSync } from "fs";
11384
+ import { tmpdir } from "os";
11385
+ import { join } from "path";
11386
+ var rag = {
11387
+ async upload_file(options) {
11388
+ console.log("Mock upload_file:", options);
11389
+ },
11390
+ async retrieval_query(options) {
11391
+ console.log("Mock retrieval_query:", options);
11392
+ return { contexts: { contexts: [] } };
11393
+ }
11394
+ };
11395
+ function _mergeEventLists(eventLists) {
11396
+ const merged = [];
11397
+ while (eventLists.length > 0) {
11398
+ const current = eventLists.shift();
11399
+ const currentTs = new Set(current.map((event) => event.timestamp));
11400
+ let mergeFound = true;
11401
+ while (mergeFound) {
11402
+ mergeFound = false;
11403
+ const remaining = [];
11404
+ for (const other of eventLists) {
11405
+ const otherTs = new Set(other.map((event) => event.timestamp));
11406
+ const hasOverlap = Array.from(currentTs).some((ts) => otherTs.has(ts));
11407
+ if (hasOverlap) {
11408
+ const newEvents = other.filter((e) => !currentTs.has(e.timestamp));
11409
+ current.push(...newEvents);
11410
+ newEvents.forEach((e) => currentTs.add(e.timestamp));
11411
+ mergeFound = true;
11412
+ } else {
11413
+ remaining.push(other);
11414
+ }
11415
+ }
11416
+ eventLists.splice(0, eventLists.length, ...remaining);
11417
+ }
11418
+ merged.push(current);
11419
+ }
11420
+ return merged;
11421
+ }
11422
+ var VertexAiRagMemoryService = class {
11423
+ _vertexRagStore;
11424
+ /**
11425
+ * Initializes a VertexAiRagMemoryService.
11426
+ *
11427
+ * @param ragCorpus The name of the Vertex AI RAG corpus to use. Format:
11428
+ * `projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
11429
+ * or `{rag_corpus_id}`
11430
+ * @param similarityTopK The number of contexts to retrieve.
11431
+ * @param vectorDistanceThreshold Only returns contexts with vector distance
11432
+ * smaller than the threshold.
11433
+ */
11434
+ constructor(ragCorpus, similarityTopK, vectorDistanceThreshold = 10) {
11435
+ this._vertexRagStore = {
11436
+ rag_resources: ragCorpus ? [{ rag_corpus: ragCorpus }] : [],
11437
+ similarity_top_k: similarityTopK,
11438
+ vector_distance_threshold: vectorDistanceThreshold
11439
+ };
11440
+ }
11441
+ /**
11442
+ * Adds a session to the memory service
11443
+ */
11444
+ async addSessionToMemory(session) {
11445
+ const tempFileName = `temp_${randomUUID2()}.txt`;
11446
+ const tempFilePath = join(tmpdir(), tempFileName);
11447
+ try {
11448
+ const outputLines = [];
11449
+ for (const event of session.events) {
11450
+ if (!event.content || !event.content.parts) {
11451
+ continue;
11452
+ }
11453
+ const textParts = event.content.parts.filter((part) => part.text).map((part) => part.text.replace(/\n/g, " "));
11454
+ if (textParts.length > 0) {
11455
+ outputLines.push(
11456
+ JSON.stringify({
11457
+ author: event.author,
11458
+ timestamp: event.timestamp,
11459
+ text: textParts.join(".")
11460
+ })
11461
+ );
11462
+ }
11463
+ }
11464
+ const outputString = outputLines.join("\n");
11465
+ writeFileSync(tempFilePath, outputString, "utf8");
11466
+ if (!this._vertexRagStore.rag_resources || this._vertexRagStore.rag_resources.length === 0) {
11467
+ throw new Error("Rag resources must be set.");
11468
+ }
11469
+ for (const ragResource of this._vertexRagStore.rag_resources) {
11470
+ await rag.upload_file({
11471
+ corpus_name: ragResource.rag_corpus,
11472
+ path: tempFilePath,
11473
+ // This is the temp workaround as upload file does not support
11474
+ // adding metadata, thus use display_name to store the session info.
11475
+ display_name: `${session.appName}.${session.userId}.${session.id}`
11476
+ });
11477
+ }
11478
+ } finally {
11479
+ try {
11480
+ unlinkSync(tempFilePath);
11481
+ } catch (error) {
11482
+ console.warn("Failed to delete temporary file:", tempFilePath, error);
11483
+ }
11484
+ }
11485
+ }
11486
+ /**
11487
+ * Searches for sessions that match the query using rag.retrieval_query
11488
+ */
11489
+ async searchMemory(options) {
11490
+ const { appName, userId, query } = options;
11491
+ const response = await rag.retrieval_query({
11492
+ text: query,
11493
+ rag_resources: this._vertexRagStore.rag_resources,
11494
+ rag_corpora: this._vertexRagStore.rag_corpora,
11495
+ similarity_top_k: this._vertexRagStore.similarity_top_k,
11496
+ vector_distance_threshold: this._vertexRagStore.vector_distance_threshold
11497
+ });
11498
+ const memoryResults = [];
11499
+ const sessionEventsMap = /* @__PURE__ */ new Map();
11500
+ for (const context4 of response.contexts.contexts) {
11501
+ if (!context4.source_display_name.startsWith(`${appName}.${userId}.`)) {
11502
+ continue;
11503
+ }
11504
+ const sessionId = context4.source_display_name.split(".").pop();
11505
+ const events = [];
11506
+ if (context4.text) {
11507
+ const lines = context4.text.split("\n");
11508
+ for (const line of lines) {
11509
+ const trimmedLine = line.trim();
11510
+ if (!trimmedLine) {
11511
+ continue;
11512
+ }
11513
+ try {
11514
+ const eventData = JSON.parse(trimmedLine);
11515
+ const author = eventData.author || "";
11516
+ const timestamp = Number.parseFloat(eventData.timestamp || "0");
11517
+ const text = eventData.text || "";
11518
+ const content = {
11519
+ parts: [{ text }]
11520
+ };
11521
+ const event = {
11522
+ author,
11523
+ timestamp,
11524
+ content
11525
+ };
11526
+ events.push(event);
11527
+ } catch {
11528
+ }
11529
+ }
11530
+ }
11531
+ if (sessionEventsMap.has(sessionId)) {
11532
+ sessionEventsMap.get(sessionId).push(events);
11533
+ } else {
11534
+ sessionEventsMap.set(sessionId, [events]);
11535
+ }
11536
+ }
11537
+ for (const [sessionId, eventLists] of sessionEventsMap.entries()) {
11538
+ const mergedEventLists = _mergeEventLists(eventLists);
11539
+ for (const events of mergedEventLists) {
11540
+ const sortedEvents = events.sort((a, b) => a.timestamp - b.timestamp).filter((event) => event.content);
11541
+ memoryResults.push(
11542
+ ...sortedEvents.map((event) => ({
11543
+ author: event.author,
11544
+ content: event.content,
11545
+ timestamp: formatTimestamp(event.timestamp)
11546
+ }))
11547
+ );
11548
+ }
11549
+ }
11550
+ return { memories: memoryResults };
11551
+ }
11552
+ };
11553
+
11301
11554
  // src/sessions/index.ts
11302
11555
  var sessions_exports = {};
11303
11556
  __export(sessions_exports, {
@@ -13640,6 +13893,7 @@ export {
13640
13893
  McpAtp,
13641
13894
  McpBamm,
13642
13895
  McpCoinGecko,
13896
+ McpCoinGeckoPro,
13643
13897
  McpDiscord,
13644
13898
  McpError,
13645
13899
  McpErrorType,
@@ -13682,6 +13936,7 @@ export {
13682
13936
  TransferToAgentTool,
13683
13937
  UserInteractionTool,
13684
13938
  VERSION,
13939
+ VertexAiRagMemoryService,
13685
13940
  VertexAiSessionService,
13686
13941
  _findFunctionCallEventIfLastEventIsFunctionResponse,
13687
13942
  adkToMcpToolType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iqai/adk",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Agent Development Kit for TypeScript with multi-provider LLM support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",