@iqai/adk 0.3.7 → 0.4.1
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 +17 -0
- package/dist/index.d.mts +43 -5
- package/dist/index.d.ts +43 -5
- package/dist/index.js +216 -12
- package/dist/index.mjs +214 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @iqai/adk
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1b00e47: Add export to VertexAiRagMemoryService
|
|
8
|
+
|
|
9
|
+
## 0.4.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- c538a1a: feat(adk): align before/after model callback signatures with runtime (single object arg) and wire before/after tool callbacks into tool execution.
|
|
14
|
+
|
|
15
|
+
- beforeModelCallback/afterModelCallback now receive `{ callbackContext, llmRequest|llmResponse }` to match runtime invocation; removes need for casts in examples.
|
|
16
|
+
- beforeToolCallback/afterToolCallback are now invoked around tool execution; allow argument mutation and result override.
|
|
17
|
+
- tracing updated to include final args and the produced event.
|
|
18
|
+
- minor lint/style cleanups in flows.
|
|
19
|
+
|
|
3
20
|
## 0.3.7
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1252,7 +1252,10 @@ type ToolUnion = BaseTool | ((...args: any[]) => any);
|
|
|
1252
1252
|
/**
|
|
1253
1253
|
* Single before model callback type
|
|
1254
1254
|
*/
|
|
1255
|
-
type SingleBeforeModelCallback = (
|
|
1255
|
+
type SingleBeforeModelCallback = (args: {
|
|
1256
|
+
callbackContext: CallbackContext;
|
|
1257
|
+
llmRequest: LlmRequest;
|
|
1258
|
+
}) => LlmResponse | null | Promise<LlmResponse | null>;
|
|
1256
1259
|
/**
|
|
1257
1260
|
* Before model callback type (single or array)
|
|
1258
1261
|
*/
|
|
@@ -1260,7 +1263,10 @@ type BeforeModelCallback = SingleBeforeModelCallback | SingleBeforeModelCallback
|
|
|
1260
1263
|
/**
|
|
1261
1264
|
* Single after model callback type
|
|
1262
1265
|
*/
|
|
1263
|
-
type SingleAfterModelCallback = (
|
|
1266
|
+
type SingleAfterModelCallback = (args: {
|
|
1267
|
+
callbackContext: CallbackContext;
|
|
1268
|
+
llmResponse: LlmResponse;
|
|
1269
|
+
}) => LlmResponse | null | Promise<LlmResponse | null>;
|
|
1264
1270
|
/**
|
|
1265
1271
|
* After model callback type (single or array)
|
|
1266
1272
|
*/
|
|
@@ -1517,7 +1523,7 @@ declare class LlmAgent<T extends BaseLlm = BaseLlm> extends BaseAgent {
|
|
|
1517
1523
|
* The resolved tools field as a list of BaseTool based on the context
|
|
1518
1524
|
* This method is only for use by Agent Development Kit
|
|
1519
1525
|
*/
|
|
1520
|
-
canonicalTools(
|
|
1526
|
+
canonicalTools(_ctx?: ReadonlyContext): Promise<BaseTool[]>;
|
|
1521
1527
|
/**
|
|
1522
1528
|
* Gets the canonical before model callbacks as an array
|
|
1523
1529
|
*/
|
|
@@ -4416,14 +4422,46 @@ declare class InMemoryMemoryService implements BaseMemoryService {
|
|
|
4416
4422
|
clear(): void;
|
|
4417
4423
|
}
|
|
4418
4424
|
|
|
4425
|
+
/**
|
|
4426
|
+
* A memory service that uses Vertex AI RAG for storage and retrieval.
|
|
4427
|
+
*/
|
|
4428
|
+
declare class VertexAiRagMemoryService implements BaseMemoryService {
|
|
4429
|
+
private _vertexRagStore;
|
|
4430
|
+
/**
|
|
4431
|
+
* Initializes a VertexAiRagMemoryService.
|
|
4432
|
+
*
|
|
4433
|
+
* @param ragCorpus The name of the Vertex AI RAG corpus to use. Format:
|
|
4434
|
+
* `projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
|
|
4435
|
+
* or `{rag_corpus_id}`
|
|
4436
|
+
* @param similarityTopK The number of contexts to retrieve.
|
|
4437
|
+
* @param vectorDistanceThreshold Only returns contexts with vector distance
|
|
4438
|
+
* smaller than the threshold.
|
|
4439
|
+
*/
|
|
4440
|
+
constructor(ragCorpus?: string, similarityTopK?: number, vectorDistanceThreshold?: number);
|
|
4441
|
+
/**
|
|
4442
|
+
* Adds a session to the memory service
|
|
4443
|
+
*/
|
|
4444
|
+
addSessionToMemory(session: Session): Promise<void>;
|
|
4445
|
+
/**
|
|
4446
|
+
* Searches for sessions that match the query using rag.retrieval_query
|
|
4447
|
+
*/
|
|
4448
|
+
searchMemory(options: {
|
|
4449
|
+
appName: string;
|
|
4450
|
+
userId: string;
|
|
4451
|
+
query: string;
|
|
4452
|
+
}): Promise<SearchMemoryResponse>;
|
|
4453
|
+
}
|
|
4454
|
+
|
|
4419
4455
|
/**
|
|
4420
4456
|
* Memory Services for the Agent Development Kit
|
|
4421
4457
|
*/
|
|
4422
4458
|
|
|
4423
4459
|
type index$4_InMemoryMemoryService = InMemoryMemoryService;
|
|
4424
4460
|
declare const index$4_InMemoryMemoryService: typeof InMemoryMemoryService;
|
|
4461
|
+
type index$4_VertexAiRagMemoryService = VertexAiRagMemoryService;
|
|
4462
|
+
declare const index$4_VertexAiRagMemoryService: typeof VertexAiRagMemoryService;
|
|
4425
4463
|
declare namespace index$4 {
|
|
4426
|
-
export { index$4_InMemoryMemoryService as InMemoryMemoryService };
|
|
4464
|
+
export { index$4_InMemoryMemoryService as InMemoryMemoryService, index$4_VertexAiRagMemoryService as VertexAiRagMemoryService };
|
|
4427
4465
|
}
|
|
4428
4466
|
|
|
4429
4467
|
/**
|
|
@@ -5569,4 +5607,4 @@ declare const traceLlmCall: (invocationContext: InvocationContext, eventId: stri
|
|
|
5569
5607
|
|
|
5570
5608
|
declare const VERSION = "0.1.0";
|
|
5571
5609
|
|
|
5572
|
-
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 };
|
|
5610
|
+
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, 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
|
@@ -1252,7 +1252,10 @@ type ToolUnion = BaseTool | ((...args: any[]) => any);
|
|
|
1252
1252
|
/**
|
|
1253
1253
|
* Single before model callback type
|
|
1254
1254
|
*/
|
|
1255
|
-
type SingleBeforeModelCallback = (
|
|
1255
|
+
type SingleBeforeModelCallback = (args: {
|
|
1256
|
+
callbackContext: CallbackContext;
|
|
1257
|
+
llmRequest: LlmRequest;
|
|
1258
|
+
}) => LlmResponse | null | Promise<LlmResponse | null>;
|
|
1256
1259
|
/**
|
|
1257
1260
|
* Before model callback type (single or array)
|
|
1258
1261
|
*/
|
|
@@ -1260,7 +1263,10 @@ type BeforeModelCallback = SingleBeforeModelCallback | SingleBeforeModelCallback
|
|
|
1260
1263
|
/**
|
|
1261
1264
|
* Single after model callback type
|
|
1262
1265
|
*/
|
|
1263
|
-
type SingleAfterModelCallback = (
|
|
1266
|
+
type SingleAfterModelCallback = (args: {
|
|
1267
|
+
callbackContext: CallbackContext;
|
|
1268
|
+
llmResponse: LlmResponse;
|
|
1269
|
+
}) => LlmResponse | null | Promise<LlmResponse | null>;
|
|
1264
1270
|
/**
|
|
1265
1271
|
* After model callback type (single or array)
|
|
1266
1272
|
*/
|
|
@@ -1517,7 +1523,7 @@ declare class LlmAgent<T extends BaseLlm = BaseLlm> extends BaseAgent {
|
|
|
1517
1523
|
* The resolved tools field as a list of BaseTool based on the context
|
|
1518
1524
|
* This method is only for use by Agent Development Kit
|
|
1519
1525
|
*/
|
|
1520
|
-
canonicalTools(
|
|
1526
|
+
canonicalTools(_ctx?: ReadonlyContext): Promise<BaseTool[]>;
|
|
1521
1527
|
/**
|
|
1522
1528
|
* Gets the canonical before model callbacks as an array
|
|
1523
1529
|
*/
|
|
@@ -4416,14 +4422,46 @@ declare class InMemoryMemoryService implements BaseMemoryService {
|
|
|
4416
4422
|
clear(): void;
|
|
4417
4423
|
}
|
|
4418
4424
|
|
|
4425
|
+
/**
|
|
4426
|
+
* A memory service that uses Vertex AI RAG for storage and retrieval.
|
|
4427
|
+
*/
|
|
4428
|
+
declare class VertexAiRagMemoryService implements BaseMemoryService {
|
|
4429
|
+
private _vertexRagStore;
|
|
4430
|
+
/**
|
|
4431
|
+
* Initializes a VertexAiRagMemoryService.
|
|
4432
|
+
*
|
|
4433
|
+
* @param ragCorpus The name of the Vertex AI RAG corpus to use. Format:
|
|
4434
|
+
* `projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
|
|
4435
|
+
* or `{rag_corpus_id}`
|
|
4436
|
+
* @param similarityTopK The number of contexts to retrieve.
|
|
4437
|
+
* @param vectorDistanceThreshold Only returns contexts with vector distance
|
|
4438
|
+
* smaller than the threshold.
|
|
4439
|
+
*/
|
|
4440
|
+
constructor(ragCorpus?: string, similarityTopK?: number, vectorDistanceThreshold?: number);
|
|
4441
|
+
/**
|
|
4442
|
+
* Adds a session to the memory service
|
|
4443
|
+
*/
|
|
4444
|
+
addSessionToMemory(session: Session): Promise<void>;
|
|
4445
|
+
/**
|
|
4446
|
+
* Searches for sessions that match the query using rag.retrieval_query
|
|
4447
|
+
*/
|
|
4448
|
+
searchMemory(options: {
|
|
4449
|
+
appName: string;
|
|
4450
|
+
userId: string;
|
|
4451
|
+
query: string;
|
|
4452
|
+
}): Promise<SearchMemoryResponse>;
|
|
4453
|
+
}
|
|
4454
|
+
|
|
4419
4455
|
/**
|
|
4420
4456
|
* Memory Services for the Agent Development Kit
|
|
4421
4457
|
*/
|
|
4422
4458
|
|
|
4423
4459
|
type index$4_InMemoryMemoryService = InMemoryMemoryService;
|
|
4424
4460
|
declare const index$4_InMemoryMemoryService: typeof InMemoryMemoryService;
|
|
4461
|
+
type index$4_VertexAiRagMemoryService = VertexAiRagMemoryService;
|
|
4462
|
+
declare const index$4_VertexAiRagMemoryService: typeof VertexAiRagMemoryService;
|
|
4425
4463
|
declare namespace index$4 {
|
|
4426
|
-
export { index$4_InMemoryMemoryService as InMemoryMemoryService };
|
|
4464
|
+
export { index$4_InMemoryMemoryService as InMemoryMemoryService, index$4_VertexAiRagMemoryService as VertexAiRagMemoryService };
|
|
4427
4465
|
}
|
|
4428
4466
|
|
|
4429
4467
|
/**
|
|
@@ -5569,4 +5607,4 @@ declare const traceLlmCall: (invocationContext: InvocationContext, eventId: stri
|
|
|
5569
5607
|
|
|
5570
5608
|
declare const VERSION = "0.1.0";
|
|
5571
5609
|
|
|
5572
|
-
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 };
|
|
5610
|
+
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, 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
|
@@ -6531,7 +6531,6 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
6531
6531
|
}
|
|
6532
6532
|
const { tool, toolContext } = getToolAndContext(
|
|
6533
6533
|
invocationContext,
|
|
6534
|
-
functionCallEvent,
|
|
6535
6534
|
functionCall,
|
|
6536
6535
|
toolsDict
|
|
6537
6536
|
);
|
|
@@ -6541,10 +6540,44 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
6541
6540
|
const spanContext = _api.trace.setSpan(_api.context.active(), span);
|
|
6542
6541
|
try {
|
|
6543
6542
|
const functionResponse = await _api.context.with(spanContext, async () => {
|
|
6544
|
-
const
|
|
6543
|
+
const argsForTool = { ...functionArgs };
|
|
6544
|
+
if (isLlmAgent2(agent)) {
|
|
6545
|
+
for (const cb of agent.canonicalBeforeToolCallbacks) {
|
|
6546
|
+
const maybeOverride = await cb(tool, argsForTool, toolContext);
|
|
6547
|
+
if (maybeOverride !== null && maybeOverride !== void 0) {
|
|
6548
|
+
const overriddenEvent = buildResponseEvent(
|
|
6549
|
+
tool,
|
|
6550
|
+
maybeOverride,
|
|
6551
|
+
toolContext,
|
|
6552
|
+
invocationContext
|
|
6553
|
+
);
|
|
6554
|
+
telemetryService.traceToolCall(
|
|
6555
|
+
tool,
|
|
6556
|
+
argsForTool,
|
|
6557
|
+
overriddenEvent
|
|
6558
|
+
);
|
|
6559
|
+
return { result: maybeOverride, event: overriddenEvent };
|
|
6560
|
+
}
|
|
6561
|
+
}
|
|
6562
|
+
}
|
|
6563
|
+
let result = await callToolAsync(tool, argsForTool, toolContext);
|
|
6545
6564
|
if (tool.isLongRunning && !result) {
|
|
6546
6565
|
return null;
|
|
6547
6566
|
}
|
|
6567
|
+
if (isLlmAgent2(agent)) {
|
|
6568
|
+
for (const cb of agent.canonicalAfterToolCallbacks) {
|
|
6569
|
+
const maybeModified = await cb(
|
|
6570
|
+
tool,
|
|
6571
|
+
argsForTool,
|
|
6572
|
+
toolContext,
|
|
6573
|
+
result
|
|
6574
|
+
);
|
|
6575
|
+
if (maybeModified !== null && maybeModified !== void 0) {
|
|
6576
|
+
result = maybeModified;
|
|
6577
|
+
break;
|
|
6578
|
+
}
|
|
6579
|
+
}
|
|
6580
|
+
}
|
|
6548
6581
|
const functionResponseEvent = buildResponseEvent(
|
|
6549
6582
|
tool,
|
|
6550
6583
|
result,
|
|
@@ -6553,7 +6586,7 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
6553
6586
|
);
|
|
6554
6587
|
telemetryService.traceToolCall(
|
|
6555
6588
|
tool,
|
|
6556
|
-
|
|
6589
|
+
argsForTool,
|
|
6557
6590
|
functionResponseEvent
|
|
6558
6591
|
);
|
|
6559
6592
|
return { result, event: functionResponseEvent };
|
|
@@ -6583,7 +6616,7 @@ async function handleFunctionCallsLive(invocationContext, functionCallEvent, too
|
|
|
6583
6616
|
toolsDict
|
|
6584
6617
|
);
|
|
6585
6618
|
}
|
|
6586
|
-
function getToolAndContext(invocationContext,
|
|
6619
|
+
function getToolAndContext(invocationContext, functionCall, toolsDict) {
|
|
6587
6620
|
if (!(functionCall.name in toolsDict)) {
|
|
6588
6621
|
throw new Error(
|
|
6589
6622
|
`Function ${functionCall.name} is not found in the tools_dict.`
|
|
@@ -6700,12 +6733,10 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6700
6733
|
}
|
|
6701
6734
|
async *_runOneStepAsync(invocationContext) {
|
|
6702
6735
|
const llmRequest = new LlmRequest();
|
|
6703
|
-
let preprocessEventCount = 0;
|
|
6704
6736
|
for await (const event of this._preprocessAsync(
|
|
6705
6737
|
invocationContext,
|
|
6706
6738
|
llmRequest
|
|
6707
6739
|
)) {
|
|
6708
|
-
preprocessEventCount++;
|
|
6709
6740
|
yield event;
|
|
6710
6741
|
}
|
|
6711
6742
|
if (invocationContext.endInvocation) {
|
|
@@ -6718,13 +6749,11 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6718
6749
|
author: invocationContext.agent.name,
|
|
6719
6750
|
branch: invocationContext.branch
|
|
6720
6751
|
});
|
|
6721
|
-
let llmResponseCount = 0;
|
|
6722
6752
|
for await (const llmResponse of this._callLlmAsync(
|
|
6723
6753
|
invocationContext,
|
|
6724
6754
|
llmRequest,
|
|
6725
6755
|
modelResponseEvent
|
|
6726
6756
|
)) {
|
|
6727
|
-
llmResponseCount++;
|
|
6728
6757
|
for await (const event of this._postprocessAsync(
|
|
6729
6758
|
invocationContext,
|
|
6730
6759
|
llmRequest,
|
|
@@ -9241,7 +9270,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
|
|
|
9241
9270
|
* The resolved tools field as a list of BaseTool based on the context
|
|
9242
9271
|
* This method is only for use by Agent Development Kit
|
|
9243
9272
|
*/
|
|
9244
|
-
async canonicalTools(
|
|
9273
|
+
async canonicalTools(_ctx) {
|
|
9245
9274
|
const resolvedTools = [];
|
|
9246
9275
|
for (const toolUnion of this.tools) {
|
|
9247
9276
|
if (typeof toolUnion === "function") {
|
|
@@ -11266,9 +11295,183 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11266
11295
|
// src/memory/index.ts
|
|
11267
11296
|
var memory_exports = {};
|
|
11268
11297
|
__export(memory_exports, {
|
|
11269
|
-
InMemoryMemoryService: () => InMemoryMemoryService
|
|
11298
|
+
InMemoryMemoryService: () => InMemoryMemoryService,
|
|
11299
|
+
VertexAiRagMemoryService: () => VertexAiRagMemoryService
|
|
11270
11300
|
});
|
|
11271
11301
|
|
|
11302
|
+
// src/memory/vertex-ai-rag-memory-service.ts
|
|
11303
|
+
|
|
11304
|
+
var _fs = require('fs');
|
|
11305
|
+
var _os = require('os');
|
|
11306
|
+
|
|
11307
|
+
var rag = {
|
|
11308
|
+
async upload_file(options) {
|
|
11309
|
+
console.log("Mock upload_file:", options);
|
|
11310
|
+
},
|
|
11311
|
+
async retrieval_query(options) {
|
|
11312
|
+
console.log("Mock retrieval_query:", options);
|
|
11313
|
+
return { contexts: { contexts: [] } };
|
|
11314
|
+
}
|
|
11315
|
+
};
|
|
11316
|
+
function _mergeEventLists(eventLists) {
|
|
11317
|
+
const merged = [];
|
|
11318
|
+
while (eventLists.length > 0) {
|
|
11319
|
+
const current = eventLists.shift();
|
|
11320
|
+
const currentTs = new Set(current.map((event) => event.timestamp));
|
|
11321
|
+
let mergeFound = true;
|
|
11322
|
+
while (mergeFound) {
|
|
11323
|
+
mergeFound = false;
|
|
11324
|
+
const remaining = [];
|
|
11325
|
+
for (const other of eventLists) {
|
|
11326
|
+
const otherTs = new Set(other.map((event) => event.timestamp));
|
|
11327
|
+
const hasOverlap = Array.from(currentTs).some((ts) => otherTs.has(ts));
|
|
11328
|
+
if (hasOverlap) {
|
|
11329
|
+
const newEvents = other.filter((e) => !currentTs.has(e.timestamp));
|
|
11330
|
+
current.push(...newEvents);
|
|
11331
|
+
newEvents.forEach((e) => currentTs.add(e.timestamp));
|
|
11332
|
+
mergeFound = true;
|
|
11333
|
+
} else {
|
|
11334
|
+
remaining.push(other);
|
|
11335
|
+
}
|
|
11336
|
+
}
|
|
11337
|
+
eventLists.splice(0, eventLists.length, ...remaining);
|
|
11338
|
+
}
|
|
11339
|
+
merged.push(current);
|
|
11340
|
+
}
|
|
11341
|
+
return merged;
|
|
11342
|
+
}
|
|
11343
|
+
var VertexAiRagMemoryService = class {
|
|
11344
|
+
|
|
11345
|
+
/**
|
|
11346
|
+
* Initializes a VertexAiRagMemoryService.
|
|
11347
|
+
*
|
|
11348
|
+
* @param ragCorpus The name of the Vertex AI RAG corpus to use. Format:
|
|
11349
|
+
* `projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
|
|
11350
|
+
* or `{rag_corpus_id}`
|
|
11351
|
+
* @param similarityTopK The number of contexts to retrieve.
|
|
11352
|
+
* @param vectorDistanceThreshold Only returns contexts with vector distance
|
|
11353
|
+
* smaller than the threshold.
|
|
11354
|
+
*/
|
|
11355
|
+
constructor(ragCorpus, similarityTopK, vectorDistanceThreshold = 10) {
|
|
11356
|
+
this._vertexRagStore = {
|
|
11357
|
+
rag_resources: ragCorpus ? [{ rag_corpus: ragCorpus }] : [],
|
|
11358
|
+
similarity_top_k: similarityTopK,
|
|
11359
|
+
vector_distance_threshold: vectorDistanceThreshold
|
|
11360
|
+
};
|
|
11361
|
+
}
|
|
11362
|
+
/**
|
|
11363
|
+
* Adds a session to the memory service
|
|
11364
|
+
*/
|
|
11365
|
+
async addSessionToMemory(session) {
|
|
11366
|
+
const tempFileName = `temp_${_crypto.randomUUID.call(void 0, )}.txt`;
|
|
11367
|
+
const tempFilePath = _path.join.call(void 0, _os.tmpdir.call(void 0, ), tempFileName);
|
|
11368
|
+
try {
|
|
11369
|
+
const outputLines = [];
|
|
11370
|
+
for (const event of session.events) {
|
|
11371
|
+
if (!event.content || !event.content.parts) {
|
|
11372
|
+
continue;
|
|
11373
|
+
}
|
|
11374
|
+
const textParts = event.content.parts.filter((part) => part.text).map((part) => part.text.replace(/\n/g, " "));
|
|
11375
|
+
if (textParts.length > 0) {
|
|
11376
|
+
outputLines.push(
|
|
11377
|
+
JSON.stringify({
|
|
11378
|
+
author: event.author,
|
|
11379
|
+
timestamp: event.timestamp,
|
|
11380
|
+
text: textParts.join(".")
|
|
11381
|
+
})
|
|
11382
|
+
);
|
|
11383
|
+
}
|
|
11384
|
+
}
|
|
11385
|
+
const outputString = outputLines.join("\n");
|
|
11386
|
+
_fs.writeFileSync.call(void 0, tempFilePath, outputString, "utf8");
|
|
11387
|
+
if (!this._vertexRagStore.rag_resources || this._vertexRagStore.rag_resources.length === 0) {
|
|
11388
|
+
throw new Error("Rag resources must be set.");
|
|
11389
|
+
}
|
|
11390
|
+
for (const ragResource of this._vertexRagStore.rag_resources) {
|
|
11391
|
+
await rag.upload_file({
|
|
11392
|
+
corpus_name: ragResource.rag_corpus,
|
|
11393
|
+
path: tempFilePath,
|
|
11394
|
+
// This is the temp workaround as upload file does not support
|
|
11395
|
+
// adding metadata, thus use display_name to store the session info.
|
|
11396
|
+
display_name: `${session.appName}.${session.userId}.${session.id}`
|
|
11397
|
+
});
|
|
11398
|
+
}
|
|
11399
|
+
} finally {
|
|
11400
|
+
try {
|
|
11401
|
+
_fs.unlinkSync.call(void 0, tempFilePath);
|
|
11402
|
+
} catch (error) {
|
|
11403
|
+
console.warn("Failed to delete temporary file:", tempFilePath, error);
|
|
11404
|
+
}
|
|
11405
|
+
}
|
|
11406
|
+
}
|
|
11407
|
+
/**
|
|
11408
|
+
* Searches for sessions that match the query using rag.retrieval_query
|
|
11409
|
+
*/
|
|
11410
|
+
async searchMemory(options) {
|
|
11411
|
+
const { appName, userId, query } = options;
|
|
11412
|
+
const response = await rag.retrieval_query({
|
|
11413
|
+
text: query,
|
|
11414
|
+
rag_resources: this._vertexRagStore.rag_resources,
|
|
11415
|
+
rag_corpora: this._vertexRagStore.rag_corpora,
|
|
11416
|
+
similarity_top_k: this._vertexRagStore.similarity_top_k,
|
|
11417
|
+
vector_distance_threshold: this._vertexRagStore.vector_distance_threshold
|
|
11418
|
+
});
|
|
11419
|
+
const memoryResults = [];
|
|
11420
|
+
const sessionEventsMap = /* @__PURE__ */ new Map();
|
|
11421
|
+
for (const context4 of response.contexts.contexts) {
|
|
11422
|
+
if (!context4.source_display_name.startsWith(`${appName}.${userId}.`)) {
|
|
11423
|
+
continue;
|
|
11424
|
+
}
|
|
11425
|
+
const sessionId = context4.source_display_name.split(".").pop();
|
|
11426
|
+
const events = [];
|
|
11427
|
+
if (context4.text) {
|
|
11428
|
+
const lines = context4.text.split("\n");
|
|
11429
|
+
for (const line of lines) {
|
|
11430
|
+
const trimmedLine = line.trim();
|
|
11431
|
+
if (!trimmedLine) {
|
|
11432
|
+
continue;
|
|
11433
|
+
}
|
|
11434
|
+
try {
|
|
11435
|
+
const eventData = JSON.parse(trimmedLine);
|
|
11436
|
+
const author = eventData.author || "";
|
|
11437
|
+
const timestamp = Number.parseFloat(eventData.timestamp || "0");
|
|
11438
|
+
const text = eventData.text || "";
|
|
11439
|
+
const content = {
|
|
11440
|
+
parts: [{ text }]
|
|
11441
|
+
};
|
|
11442
|
+
const event = {
|
|
11443
|
+
author,
|
|
11444
|
+
timestamp,
|
|
11445
|
+
content
|
|
11446
|
+
};
|
|
11447
|
+
events.push(event);
|
|
11448
|
+
} catch (e7) {
|
|
11449
|
+
}
|
|
11450
|
+
}
|
|
11451
|
+
}
|
|
11452
|
+
if (sessionEventsMap.has(sessionId)) {
|
|
11453
|
+
sessionEventsMap.get(sessionId).push(events);
|
|
11454
|
+
} else {
|
|
11455
|
+
sessionEventsMap.set(sessionId, [events]);
|
|
11456
|
+
}
|
|
11457
|
+
}
|
|
11458
|
+
for (const [sessionId, eventLists] of sessionEventsMap.entries()) {
|
|
11459
|
+
const mergedEventLists = _mergeEventLists(eventLists);
|
|
11460
|
+
for (const events of mergedEventLists) {
|
|
11461
|
+
const sortedEvents = events.sort((a, b) => a.timestamp - b.timestamp).filter((event) => event.content);
|
|
11462
|
+
memoryResults.push(
|
|
11463
|
+
...sortedEvents.map((event) => ({
|
|
11464
|
+
author: event.author,
|
|
11465
|
+
content: event.content,
|
|
11466
|
+
timestamp: formatTimestamp(event.timestamp)
|
|
11467
|
+
}))
|
|
11468
|
+
);
|
|
11469
|
+
}
|
|
11470
|
+
}
|
|
11471
|
+
return { memories: memoryResults };
|
|
11472
|
+
}
|
|
11473
|
+
};
|
|
11474
|
+
|
|
11272
11475
|
// src/sessions/index.ts
|
|
11273
11476
|
var sessions_exports = {};
|
|
11274
11477
|
__export(sessions_exports, {
|
|
@@ -11674,7 +11877,7 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
11674
11877
|
if (!jsonString) return defaultValue;
|
|
11675
11878
|
try {
|
|
11676
11879
|
return JSON.parse(jsonString);
|
|
11677
|
-
} catch (
|
|
11880
|
+
} catch (e8) {
|
|
11678
11881
|
return defaultValue;
|
|
11679
11882
|
}
|
|
11680
11883
|
}
|
|
@@ -13700,4 +13903,5 @@ var VERSION = "0.1.0";
|
|
|
13700
13903
|
|
|
13701
13904
|
|
|
13702
13905
|
|
|
13703
|
-
|
|
13906
|
+
|
|
13907
|
+
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.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
|
@@ -6531,7 +6531,6 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
6531
6531
|
}
|
|
6532
6532
|
const { tool, toolContext } = getToolAndContext(
|
|
6533
6533
|
invocationContext,
|
|
6534
|
-
functionCallEvent,
|
|
6535
6534
|
functionCall,
|
|
6536
6535
|
toolsDict
|
|
6537
6536
|
);
|
|
@@ -6541,10 +6540,44 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
6541
6540
|
const spanContext = trace2.setSpan(context2.active(), span);
|
|
6542
6541
|
try {
|
|
6543
6542
|
const functionResponse = await context2.with(spanContext, async () => {
|
|
6544
|
-
const
|
|
6543
|
+
const argsForTool = { ...functionArgs };
|
|
6544
|
+
if (isLlmAgent2(agent)) {
|
|
6545
|
+
for (const cb of agent.canonicalBeforeToolCallbacks) {
|
|
6546
|
+
const maybeOverride = await cb(tool, argsForTool, toolContext);
|
|
6547
|
+
if (maybeOverride !== null && maybeOverride !== void 0) {
|
|
6548
|
+
const overriddenEvent = buildResponseEvent(
|
|
6549
|
+
tool,
|
|
6550
|
+
maybeOverride,
|
|
6551
|
+
toolContext,
|
|
6552
|
+
invocationContext
|
|
6553
|
+
);
|
|
6554
|
+
telemetryService.traceToolCall(
|
|
6555
|
+
tool,
|
|
6556
|
+
argsForTool,
|
|
6557
|
+
overriddenEvent
|
|
6558
|
+
);
|
|
6559
|
+
return { result: maybeOverride, event: overriddenEvent };
|
|
6560
|
+
}
|
|
6561
|
+
}
|
|
6562
|
+
}
|
|
6563
|
+
let result = await callToolAsync(tool, argsForTool, toolContext);
|
|
6545
6564
|
if (tool.isLongRunning && !result) {
|
|
6546
6565
|
return null;
|
|
6547
6566
|
}
|
|
6567
|
+
if (isLlmAgent2(agent)) {
|
|
6568
|
+
for (const cb of agent.canonicalAfterToolCallbacks) {
|
|
6569
|
+
const maybeModified = await cb(
|
|
6570
|
+
tool,
|
|
6571
|
+
argsForTool,
|
|
6572
|
+
toolContext,
|
|
6573
|
+
result
|
|
6574
|
+
);
|
|
6575
|
+
if (maybeModified !== null && maybeModified !== void 0) {
|
|
6576
|
+
result = maybeModified;
|
|
6577
|
+
break;
|
|
6578
|
+
}
|
|
6579
|
+
}
|
|
6580
|
+
}
|
|
6548
6581
|
const functionResponseEvent = buildResponseEvent(
|
|
6549
6582
|
tool,
|
|
6550
6583
|
result,
|
|
@@ -6553,7 +6586,7 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
6553
6586
|
);
|
|
6554
6587
|
telemetryService.traceToolCall(
|
|
6555
6588
|
tool,
|
|
6556
|
-
|
|
6589
|
+
argsForTool,
|
|
6557
6590
|
functionResponseEvent
|
|
6558
6591
|
);
|
|
6559
6592
|
return { result, event: functionResponseEvent };
|
|
@@ -6583,7 +6616,7 @@ async function handleFunctionCallsLive(invocationContext, functionCallEvent, too
|
|
|
6583
6616
|
toolsDict
|
|
6584
6617
|
);
|
|
6585
6618
|
}
|
|
6586
|
-
function getToolAndContext(invocationContext,
|
|
6619
|
+
function getToolAndContext(invocationContext, functionCall, toolsDict) {
|
|
6587
6620
|
if (!(functionCall.name in toolsDict)) {
|
|
6588
6621
|
throw new Error(
|
|
6589
6622
|
`Function ${functionCall.name} is not found in the tools_dict.`
|
|
@@ -6700,12 +6733,10 @@ var BaseLlmFlow = class {
|
|
|
6700
6733
|
}
|
|
6701
6734
|
async *_runOneStepAsync(invocationContext) {
|
|
6702
6735
|
const llmRequest = new LlmRequest();
|
|
6703
|
-
let preprocessEventCount = 0;
|
|
6704
6736
|
for await (const event of this._preprocessAsync(
|
|
6705
6737
|
invocationContext,
|
|
6706
6738
|
llmRequest
|
|
6707
6739
|
)) {
|
|
6708
|
-
preprocessEventCount++;
|
|
6709
6740
|
yield event;
|
|
6710
6741
|
}
|
|
6711
6742
|
if (invocationContext.endInvocation) {
|
|
@@ -6718,13 +6749,11 @@ var BaseLlmFlow = class {
|
|
|
6718
6749
|
author: invocationContext.agent.name,
|
|
6719
6750
|
branch: invocationContext.branch
|
|
6720
6751
|
});
|
|
6721
|
-
let llmResponseCount = 0;
|
|
6722
6752
|
for await (const llmResponse of this._callLlmAsync(
|
|
6723
6753
|
invocationContext,
|
|
6724
6754
|
llmRequest,
|
|
6725
6755
|
modelResponseEvent
|
|
6726
6756
|
)) {
|
|
6727
|
-
llmResponseCount++;
|
|
6728
6757
|
for await (const event of this._postprocessAsync(
|
|
6729
6758
|
invocationContext,
|
|
6730
6759
|
llmRequest,
|
|
@@ -9241,7 +9270,7 @@ var LlmAgent = class _LlmAgent extends BaseAgent {
|
|
|
9241
9270
|
* The resolved tools field as a list of BaseTool based on the context
|
|
9242
9271
|
* This method is only for use by Agent Development Kit
|
|
9243
9272
|
*/
|
|
9244
|
-
async canonicalTools(
|
|
9273
|
+
async canonicalTools(_ctx) {
|
|
9245
9274
|
const resolvedTools = [];
|
|
9246
9275
|
for (const toolUnion of this.tools) {
|
|
9247
9276
|
if (typeof toolUnion === "function") {
|
|
@@ -11266,9 +11295,183 @@ var AgentBuilder = class _AgentBuilder {
|
|
|
11266
11295
|
// src/memory/index.ts
|
|
11267
11296
|
var memory_exports = {};
|
|
11268
11297
|
__export(memory_exports, {
|
|
11269
|
-
InMemoryMemoryService: () => InMemoryMemoryService
|
|
11298
|
+
InMemoryMemoryService: () => InMemoryMemoryService,
|
|
11299
|
+
VertexAiRagMemoryService: () => VertexAiRagMemoryService
|
|
11270
11300
|
});
|
|
11271
11301
|
|
|
11302
|
+
// src/memory/vertex-ai-rag-memory-service.ts
|
|
11303
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
11304
|
+
import { unlinkSync, writeFileSync } from "fs";
|
|
11305
|
+
import { tmpdir } from "os";
|
|
11306
|
+
import { join } from "path";
|
|
11307
|
+
var rag = {
|
|
11308
|
+
async upload_file(options) {
|
|
11309
|
+
console.log("Mock upload_file:", options);
|
|
11310
|
+
},
|
|
11311
|
+
async retrieval_query(options) {
|
|
11312
|
+
console.log("Mock retrieval_query:", options);
|
|
11313
|
+
return { contexts: { contexts: [] } };
|
|
11314
|
+
}
|
|
11315
|
+
};
|
|
11316
|
+
function _mergeEventLists(eventLists) {
|
|
11317
|
+
const merged = [];
|
|
11318
|
+
while (eventLists.length > 0) {
|
|
11319
|
+
const current = eventLists.shift();
|
|
11320
|
+
const currentTs = new Set(current.map((event) => event.timestamp));
|
|
11321
|
+
let mergeFound = true;
|
|
11322
|
+
while (mergeFound) {
|
|
11323
|
+
mergeFound = false;
|
|
11324
|
+
const remaining = [];
|
|
11325
|
+
for (const other of eventLists) {
|
|
11326
|
+
const otherTs = new Set(other.map((event) => event.timestamp));
|
|
11327
|
+
const hasOverlap = Array.from(currentTs).some((ts) => otherTs.has(ts));
|
|
11328
|
+
if (hasOverlap) {
|
|
11329
|
+
const newEvents = other.filter((e) => !currentTs.has(e.timestamp));
|
|
11330
|
+
current.push(...newEvents);
|
|
11331
|
+
newEvents.forEach((e) => currentTs.add(e.timestamp));
|
|
11332
|
+
mergeFound = true;
|
|
11333
|
+
} else {
|
|
11334
|
+
remaining.push(other);
|
|
11335
|
+
}
|
|
11336
|
+
}
|
|
11337
|
+
eventLists.splice(0, eventLists.length, ...remaining);
|
|
11338
|
+
}
|
|
11339
|
+
merged.push(current);
|
|
11340
|
+
}
|
|
11341
|
+
return merged;
|
|
11342
|
+
}
|
|
11343
|
+
var VertexAiRagMemoryService = class {
|
|
11344
|
+
_vertexRagStore;
|
|
11345
|
+
/**
|
|
11346
|
+
* Initializes a VertexAiRagMemoryService.
|
|
11347
|
+
*
|
|
11348
|
+
* @param ragCorpus The name of the Vertex AI RAG corpus to use. Format:
|
|
11349
|
+
* `projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
|
|
11350
|
+
* or `{rag_corpus_id}`
|
|
11351
|
+
* @param similarityTopK The number of contexts to retrieve.
|
|
11352
|
+
* @param vectorDistanceThreshold Only returns contexts with vector distance
|
|
11353
|
+
* smaller than the threshold.
|
|
11354
|
+
*/
|
|
11355
|
+
constructor(ragCorpus, similarityTopK, vectorDistanceThreshold = 10) {
|
|
11356
|
+
this._vertexRagStore = {
|
|
11357
|
+
rag_resources: ragCorpus ? [{ rag_corpus: ragCorpus }] : [],
|
|
11358
|
+
similarity_top_k: similarityTopK,
|
|
11359
|
+
vector_distance_threshold: vectorDistanceThreshold
|
|
11360
|
+
};
|
|
11361
|
+
}
|
|
11362
|
+
/**
|
|
11363
|
+
* Adds a session to the memory service
|
|
11364
|
+
*/
|
|
11365
|
+
async addSessionToMemory(session) {
|
|
11366
|
+
const tempFileName = `temp_${randomUUID2()}.txt`;
|
|
11367
|
+
const tempFilePath = join(tmpdir(), tempFileName);
|
|
11368
|
+
try {
|
|
11369
|
+
const outputLines = [];
|
|
11370
|
+
for (const event of session.events) {
|
|
11371
|
+
if (!event.content || !event.content.parts) {
|
|
11372
|
+
continue;
|
|
11373
|
+
}
|
|
11374
|
+
const textParts = event.content.parts.filter((part) => part.text).map((part) => part.text.replace(/\n/g, " "));
|
|
11375
|
+
if (textParts.length > 0) {
|
|
11376
|
+
outputLines.push(
|
|
11377
|
+
JSON.stringify({
|
|
11378
|
+
author: event.author,
|
|
11379
|
+
timestamp: event.timestamp,
|
|
11380
|
+
text: textParts.join(".")
|
|
11381
|
+
})
|
|
11382
|
+
);
|
|
11383
|
+
}
|
|
11384
|
+
}
|
|
11385
|
+
const outputString = outputLines.join("\n");
|
|
11386
|
+
writeFileSync(tempFilePath, outputString, "utf8");
|
|
11387
|
+
if (!this._vertexRagStore.rag_resources || this._vertexRagStore.rag_resources.length === 0) {
|
|
11388
|
+
throw new Error("Rag resources must be set.");
|
|
11389
|
+
}
|
|
11390
|
+
for (const ragResource of this._vertexRagStore.rag_resources) {
|
|
11391
|
+
await rag.upload_file({
|
|
11392
|
+
corpus_name: ragResource.rag_corpus,
|
|
11393
|
+
path: tempFilePath,
|
|
11394
|
+
// This is the temp workaround as upload file does not support
|
|
11395
|
+
// adding metadata, thus use display_name to store the session info.
|
|
11396
|
+
display_name: `${session.appName}.${session.userId}.${session.id}`
|
|
11397
|
+
});
|
|
11398
|
+
}
|
|
11399
|
+
} finally {
|
|
11400
|
+
try {
|
|
11401
|
+
unlinkSync(tempFilePath);
|
|
11402
|
+
} catch (error) {
|
|
11403
|
+
console.warn("Failed to delete temporary file:", tempFilePath, error);
|
|
11404
|
+
}
|
|
11405
|
+
}
|
|
11406
|
+
}
|
|
11407
|
+
/**
|
|
11408
|
+
* Searches for sessions that match the query using rag.retrieval_query
|
|
11409
|
+
*/
|
|
11410
|
+
async searchMemory(options) {
|
|
11411
|
+
const { appName, userId, query } = options;
|
|
11412
|
+
const response = await rag.retrieval_query({
|
|
11413
|
+
text: query,
|
|
11414
|
+
rag_resources: this._vertexRagStore.rag_resources,
|
|
11415
|
+
rag_corpora: this._vertexRagStore.rag_corpora,
|
|
11416
|
+
similarity_top_k: this._vertexRagStore.similarity_top_k,
|
|
11417
|
+
vector_distance_threshold: this._vertexRagStore.vector_distance_threshold
|
|
11418
|
+
});
|
|
11419
|
+
const memoryResults = [];
|
|
11420
|
+
const sessionEventsMap = /* @__PURE__ */ new Map();
|
|
11421
|
+
for (const context4 of response.contexts.contexts) {
|
|
11422
|
+
if (!context4.source_display_name.startsWith(`${appName}.${userId}.`)) {
|
|
11423
|
+
continue;
|
|
11424
|
+
}
|
|
11425
|
+
const sessionId = context4.source_display_name.split(".").pop();
|
|
11426
|
+
const events = [];
|
|
11427
|
+
if (context4.text) {
|
|
11428
|
+
const lines = context4.text.split("\n");
|
|
11429
|
+
for (const line of lines) {
|
|
11430
|
+
const trimmedLine = line.trim();
|
|
11431
|
+
if (!trimmedLine) {
|
|
11432
|
+
continue;
|
|
11433
|
+
}
|
|
11434
|
+
try {
|
|
11435
|
+
const eventData = JSON.parse(trimmedLine);
|
|
11436
|
+
const author = eventData.author || "";
|
|
11437
|
+
const timestamp = Number.parseFloat(eventData.timestamp || "0");
|
|
11438
|
+
const text = eventData.text || "";
|
|
11439
|
+
const content = {
|
|
11440
|
+
parts: [{ text }]
|
|
11441
|
+
};
|
|
11442
|
+
const event = {
|
|
11443
|
+
author,
|
|
11444
|
+
timestamp,
|
|
11445
|
+
content
|
|
11446
|
+
};
|
|
11447
|
+
events.push(event);
|
|
11448
|
+
} catch {
|
|
11449
|
+
}
|
|
11450
|
+
}
|
|
11451
|
+
}
|
|
11452
|
+
if (sessionEventsMap.has(sessionId)) {
|
|
11453
|
+
sessionEventsMap.get(sessionId).push(events);
|
|
11454
|
+
} else {
|
|
11455
|
+
sessionEventsMap.set(sessionId, [events]);
|
|
11456
|
+
}
|
|
11457
|
+
}
|
|
11458
|
+
for (const [sessionId, eventLists] of sessionEventsMap.entries()) {
|
|
11459
|
+
const mergedEventLists = _mergeEventLists(eventLists);
|
|
11460
|
+
for (const events of mergedEventLists) {
|
|
11461
|
+
const sortedEvents = events.sort((a, b) => a.timestamp - b.timestamp).filter((event) => event.content);
|
|
11462
|
+
memoryResults.push(
|
|
11463
|
+
...sortedEvents.map((event) => ({
|
|
11464
|
+
author: event.author,
|
|
11465
|
+
content: event.content,
|
|
11466
|
+
timestamp: formatTimestamp(event.timestamp)
|
|
11467
|
+
}))
|
|
11468
|
+
);
|
|
11469
|
+
}
|
|
11470
|
+
}
|
|
11471
|
+
return { memories: memoryResults };
|
|
11472
|
+
}
|
|
11473
|
+
};
|
|
11474
|
+
|
|
11272
11475
|
// src/sessions/index.ts
|
|
11273
11476
|
var sessions_exports = {};
|
|
11274
11477
|
__export(sessions_exports, {
|
|
@@ -13653,6 +13856,7 @@ export {
|
|
|
13653
13856
|
TransferToAgentTool,
|
|
13654
13857
|
UserInteractionTool,
|
|
13655
13858
|
VERSION,
|
|
13859
|
+
VertexAiRagMemoryService,
|
|
13656
13860
|
VertexAiSessionService,
|
|
13657
13861
|
_findFunctionCallEventIfLastEventIsFunctionResponse,
|
|
13658
13862
|
adkToMcpToolType,
|