@google/adk 1.3.0 → 1.4.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/dist/cjs/agents/active_streaming_tool.js +6 -1
- package/dist/cjs/agents/context.js +1 -11
- package/dist/cjs/agents/functions.js +35 -16
- package/dist/cjs/agents/instructions.js +23 -5
- package/dist/cjs/agents/invocation_context.js +2 -5
- package/dist/cjs/agents/llm_agent.js +8 -6
- package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/cjs/agents/processors/content_processor_utils.js +16 -3
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/cjs/agents/processors/interactions_request_processor.js +63 -0
- package/dist/cjs/apps/app.js +79 -0
- package/dist/cjs/apps/resumability_config.js +44 -0
- package/dist/cjs/artifacts/file_artifact_service.js +14 -1
- package/dist/cjs/artifacts/gcs_artifact_service.js +57 -15
- package/dist/cjs/artifacts/in_memory_artifact_service.js +5 -1
- package/dist/cjs/artifacts/scoped_artifact_service.js +101 -0
- package/dist/cjs/artifacts/session_artifact_service.js +27 -0
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +17 -5
- package/dist/cjs/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/cjs/common.js +47 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
- package/dist/cjs/context/token_based_context_compactor.js +42 -10
- package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
- package/dist/cjs/events/event.js +24 -0
- package/dist/cjs/models/google_llm.js +25 -10
- package/dist/cjs/models/interactions_utils.js +732 -0
- package/dist/cjs/plugins/base_plugin.js +1 -0
- package/dist/cjs/runner/in_memory_runner.js +13 -2
- package/dist/cjs/runner/runner.js +93 -72
- package/dist/cjs/sessions/base_session_service.js +6 -1
- package/dist/cjs/sessions/database_session_service.js +24 -7
- package/dist/cjs/sessions/vertex_ai_session_service.js +19 -4
- package/dist/cjs/skills/loader.js +2 -2
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/consolidate_context_tool.js +79 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +2 -12
- package/dist/cjs/utils/async_hooks_shim.js +52 -0
- package/dist/cjs/utils/client_labels.js +41 -3
- package/dist/cjs/utils/env_aware_utils.js +10 -1
- package/dist/cjs/utils/streaming_utils.js +10 -4
- package/dist/cjs/utils/task.js +62 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/active_streaming_tool.js +6 -1
- package/dist/esm/agents/context.js +1 -11
- package/dist/esm/agents/functions.js +36 -15
- package/dist/esm/agents/instructions.js +23 -5
- package/dist/esm/agents/invocation_context.js +2 -5
- package/dist/esm/agents/llm_agent.js +8 -6
- package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/esm/agents/processors/content_processor_utils.js +14 -2
- package/dist/esm/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/esm/agents/processors/interactions_request_processor.js +34 -0
- package/dist/esm/apps/app.js +49 -0
- package/dist/esm/apps/resumability_config.js +16 -0
- package/dist/esm/artifacts/file_artifact_service.js +14 -1
- package/dist/esm/artifacts/gcs_artifact_service.js +57 -15
- package/dist/esm/artifacts/in_memory_artifact_service.js +5 -1
- package/dist/esm/artifacts/scoped_artifact_service.js +73 -0
- package/dist/esm/artifacts/session_artifact_service.js +7 -0
- package/dist/esm/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/esm/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/esm/common.js +42 -2
- package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
- package/dist/esm/context/token_based_context_compactor.js +42 -10
- package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/esm/events/event.js +22 -0
- package/dist/esm/models/google_llm.js +23 -9
- package/dist/esm/models/interactions_utils.js +697 -0
- package/dist/esm/plugins/base_plugin.js +1 -0
- package/dist/esm/runner/in_memory_runner.js +13 -2
- package/dist/esm/runner/runner.js +91 -73
- package/dist/esm/sessions/base_session_service.js +6 -1
- package/dist/esm/sessions/database_session_service.js +24 -7
- package/dist/esm/sessions/vertex_ai_session_service.js +17 -3
- package/dist/esm/skills/loader.js +2 -2
- package/dist/esm/tools/base_toolset.js +1 -1
- package/dist/esm/tools/consolidate_context_tool.js +51 -0
- package/dist/esm/tools/forwarding_artifact_service.js +16 -28
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +2 -12
- package/dist/esm/utils/async_hooks_shim.js +24 -0
- package/dist/esm/utils/client_labels.js +38 -2
- package/dist/esm/utils/env_aware_utils.js +10 -1
- package/dist/esm/utils/streaming_utils.js +10 -4
- package/dist/esm/utils/task.js +34 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/agents/active_streaming_tool.d.ts +3 -4
- package/dist/types/agents/functions.d.ts +12 -9
- package/dist/types/agents/invocation_context.d.ts +7 -3
- package/dist/types/agents/processors/content_processor_utils.d.ts +8 -0
- package/dist/types/agents/processors/interactions_request_processor.d.ts +17 -0
- package/dist/types/apps/app.d.ts +52 -0
- package/dist/types/apps/resumability_config.d.ts +27 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +6 -36
- package/dist/types/artifacts/gcs_artifact_service.d.ts +2 -1
- package/dist/types/artifacts/scoped_artifact_service.d.ts +25 -0
- package/dist/types/artifacts/session_artifact_service.d.ts +25 -0
- package/dist/types/auth/oauth2/oauth2_discovery.d.ts +11 -0
- package/dist/types/common.d.ts +20 -3
- package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
- package/dist/types/context/base_context_compactor.d.ts +3 -0
- package/dist/types/context/token_based_context_compactor.d.ts +6 -1
- package/dist/types/context/trajectory_thought_pruning_compactor.d.ts +27 -0
- package/dist/types/events/event.d.ts +8 -0
- package/dist/types/models/google_llm.d.ts +15 -1
- package/dist/types/models/interactions_utils.d.ts +92 -0
- package/dist/types/models/llm_request.d.ts +4 -0
- package/dist/types/models/llm_response.d.ts +4 -0
- package/dist/types/plugins/base_plugin.d.ts +2 -1
- package/dist/types/runner/in_memory_runner.d.ts +7 -1
- package/dist/types/runner/runner.d.ts +43 -9
- package/dist/types/sessions/base_session_service.d.ts +3 -16
- package/dist/types/sessions/session.d.ts +11 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +9 -1
- package/dist/types/tools/consolidate_context_tool.d.ts +19 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +3 -2
- package/dist/types/utils/async_hooks_shim.d.ts +10 -0
- package/dist/types/utils/client_labels.d.ts +10 -0
- package/dist/types/utils/env_aware_utils.d.ts +3 -3
- package/dist/types/utils/task.d.ts +24 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/active_streaming_tool.js +6 -1
- package/dist/web/agents/context.js +1 -11
- package/dist/web/agents/functions.js +36 -15
- package/dist/web/agents/instructions.js +23 -5
- package/dist/web/agents/invocation_context.js +2 -5
- package/dist/web/agents/llm_agent.js +8 -6
- package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/web/agents/processors/content_processor_utils.js +14 -2
- package/dist/web/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/web/agents/processors/interactions_request_processor.js +52 -0
- package/dist/web/apps/app.js +49 -0
- package/dist/web/apps/resumability_config.js +31 -0
- package/dist/web/artifacts/file_artifact_service.js +14 -1
- package/dist/web/artifacts/gcs_artifact_service.js +55 -15
- package/dist/web/artifacts/in_memory_artifact_service.js +5 -1
- package/dist/web/artifacts/scoped_artifact_service.js +86 -0
- package/dist/web/artifacts/session_artifact_service.js +7 -0
- package/dist/web/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/web/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/web/common.js +42 -2
- package/dist/web/context/agent_controlled_context_compactor.js +81 -0
- package/dist/web/context/token_based_context_compactor.js +42 -10
- package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/web/events/event.js +20 -0
- package/dist/web/models/google_llm.js +54 -9
- package/dist/web/models/interactions_utils.js +728 -0
- package/dist/web/plugins/base_plugin.js +1 -0
- package/dist/web/runner/in_memory_runner.js +13 -2
- package/dist/web/runner/runner.js +111 -75
- package/dist/web/sessions/base_session_service.js +6 -1
- package/dist/web/sessions/database_session_service.js +24 -7
- package/dist/web/sessions/vertex_ai_session_service.js +17 -3
- package/dist/web/skills/loader.js +2 -2
- package/dist/web/tools/base_toolset.js +1 -1
- package/dist/web/tools/consolidate_context_tool.js +51 -0
- package/dist/web/tools/forwarding_artifact_service.js +16 -28
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +2 -12
- package/dist/web/utils/async_hooks_shim.js +24 -0
- package/dist/web/utils/client_labels.js +38 -2
- package/dist/web/utils/env_aware_utils.js +10 -1
- package/dist/web/utils/streaming_utils.js +10 -4
- package/dist/web/utils/task.js +34 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -2
|
@@ -39,20 +39,33 @@ export interface GeminiParams {
|
|
|
39
39
|
* Headers to merge with internally crafted headers.
|
|
40
40
|
*/
|
|
41
41
|
headers?: Record<string, string>;
|
|
42
|
+
/**
|
|
43
|
+
* Whether to use the Interactions API for stateful conversations.
|
|
44
|
+
*/
|
|
45
|
+
useInteractionsApi?: boolean;
|
|
42
46
|
}
|
|
47
|
+
declare const GEMINI_MODEL_SYMBOL: unique symbol;
|
|
48
|
+
/**
|
|
49
|
+
* Type guard to check if an object is an instance of Gemini.
|
|
50
|
+
* @param obj The object to check.
|
|
51
|
+
* @returns True if the object is an instance of Gemini, false otherwise.
|
|
52
|
+
*/
|
|
53
|
+
export declare function isGemini(obj: unknown): obj is Gemini;
|
|
43
54
|
/**
|
|
44
55
|
* Integration for Gemini models.
|
|
45
56
|
*/
|
|
46
57
|
export declare class Gemini extends BaseLlm {
|
|
58
|
+
readonly [GEMINI_MODEL_SYMBOL] = true;
|
|
47
59
|
private readonly apiKey?;
|
|
48
60
|
protected readonly vertexai: boolean;
|
|
49
61
|
private readonly project?;
|
|
50
62
|
private readonly location?;
|
|
51
63
|
private readonly headers?;
|
|
64
|
+
readonly useInteractionsApi: boolean;
|
|
52
65
|
/**
|
|
53
66
|
* @param params The parameters for creating a Gemini instance.
|
|
54
67
|
*/
|
|
55
|
-
constructor({ model, apiKey, vertexai, project, location, headers, }: GeminiParams);
|
|
68
|
+
constructor({ model, apiKey, vertexai, project, location, headers, useInteractionsApi, }: GeminiParams);
|
|
56
69
|
/**
|
|
57
70
|
* A list of model name patterns that are supported by this LLM.
|
|
58
71
|
*
|
|
@@ -88,3 +101,4 @@ export declare class Gemini extends BaseLlm {
|
|
|
88
101
|
private preprocessRequest;
|
|
89
102
|
}
|
|
90
103
|
export declare function geminiInitParams({ model, vertexai, project, location, apiKey, }: GeminiParams): GeminiParams;
|
|
104
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Content, GenerateContentConfig, GoogleGenAI, Interactions, Part } from '@google/genai';
|
|
7
|
+
import { LlmRequest } from './llm_request.js';
|
|
8
|
+
import { LlmResponse } from './llm_response.js';
|
|
9
|
+
export interface ExtendedInteraction extends Interactions.Interaction {
|
|
10
|
+
error?: {
|
|
11
|
+
code: string;
|
|
12
|
+
message: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface ExtendedInteractionStatusUpdate extends Omit<Interactions.InteractionStatusUpdate, 'error'> {
|
|
16
|
+
error?: {
|
|
17
|
+
code: string;
|
|
18
|
+
message: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export interface ExtendedFunctionCallStep extends Interactions.FunctionCallStep {
|
|
22
|
+
signature?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ExtendedInteractionSSEEvent extends Omit<Interactions.InteractionSSEEvent, 'error' | 'interaction_id' | 'status' | 'event_type'> {
|
|
25
|
+
event_type?: string;
|
|
26
|
+
eventType?: string;
|
|
27
|
+
delta?: {
|
|
28
|
+
type: string;
|
|
29
|
+
text?: string;
|
|
30
|
+
name?: string;
|
|
31
|
+
id?: string;
|
|
32
|
+
arguments?: Record<string, unknown>;
|
|
33
|
+
thought_signature?: string;
|
|
34
|
+
signature?: string;
|
|
35
|
+
data?: string;
|
|
36
|
+
uri?: string;
|
|
37
|
+
mime_type: string;
|
|
38
|
+
};
|
|
39
|
+
status?: string;
|
|
40
|
+
error?: {
|
|
41
|
+
code: string;
|
|
42
|
+
message: string;
|
|
43
|
+
};
|
|
44
|
+
code?: string;
|
|
45
|
+
message?: string;
|
|
46
|
+
interaction_id?: string;
|
|
47
|
+
interactionId?: string;
|
|
48
|
+
interaction?: {
|
|
49
|
+
id: string;
|
|
50
|
+
};
|
|
51
|
+
id?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Extracts the latest turn contents for interactions API.
|
|
55
|
+
*/
|
|
56
|
+
export declare function getLatestUserContents(contents: Content[]): Content[];
|
|
57
|
+
/**
|
|
58
|
+
* Convert a Content to a list of Steps.
|
|
59
|
+
*/
|
|
60
|
+
export declare function convertContentToSteps(content: Content): Interactions.Step[];
|
|
61
|
+
/**
|
|
62
|
+
* Convert a Step to a list of Parts.
|
|
63
|
+
*/
|
|
64
|
+
export declare function convertStepToParts(step: Interactions.Step): Part[];
|
|
65
|
+
/**
|
|
66
|
+
* Convert tools config to interactions format.
|
|
67
|
+
*/
|
|
68
|
+
export declare function convertToolsConfigToInteractionsFormat(config: GenerateContentConfig): Interactions.Tool[];
|
|
69
|
+
/**
|
|
70
|
+
* Extract the latest model generated parts from a list of steps.
|
|
71
|
+
*/
|
|
72
|
+
export declare function getLatestModelParts(steps: Interactions.Step[]): Part[];
|
|
73
|
+
/**
|
|
74
|
+
* Convert Interaction response to an LlmResponse.
|
|
75
|
+
*/
|
|
76
|
+
export declare function convertInteractionToLlmResponse(interaction: ExtendedInteraction): LlmResponse;
|
|
77
|
+
/**
|
|
78
|
+
* Convert InteractionSSEEvent to LlmResponse.
|
|
79
|
+
*/
|
|
80
|
+
export declare function convertInteractionEventToLlmResponse(event: ExtendedInteractionSSEEvent, aggregatedParts: Part[], interactionId?: string): LlmResponse | null;
|
|
81
|
+
/**
|
|
82
|
+
* Build generation config.
|
|
83
|
+
*/
|
|
84
|
+
export declare function buildGenerationConfig(config: GenerateContentConfig): Record<string, unknown>;
|
|
85
|
+
/**
|
|
86
|
+
* Extract system instruction.
|
|
87
|
+
*/
|
|
88
|
+
export declare function extractSystemInstruction(config: GenerateContentConfig): string | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Generate content using the interactions API.
|
|
91
|
+
*/
|
|
92
|
+
export declare function generateContentViaInteractions(apiClient: GoogleGenAI, llmRequest: LlmRequest, stream: boolean): AsyncGenerator<LlmResponse, void, void>;
|
|
@@ -34,6 +34,10 @@ export interface LlmRequest {
|
|
|
34
34
|
* The set of allowed tools, populated by request processors.
|
|
35
35
|
*/
|
|
36
36
|
allowedTools?: string[];
|
|
37
|
+
/**
|
|
38
|
+
* The interaction ID from the previous turn, if any.
|
|
39
|
+
*/
|
|
40
|
+
previousInteractionId?: string;
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
43
|
* Appends instructions to the system instruction.
|
|
@@ -77,6 +77,10 @@ export interface LlmResponse {
|
|
|
77
77
|
* Audio transcription of model output.
|
|
78
78
|
*/
|
|
79
79
|
outputTranscription?: Transcription;
|
|
80
|
+
/**
|
|
81
|
+
* The interaction ID returned by the model, if any.
|
|
82
|
+
*/
|
|
83
|
+
interactionId?: string;
|
|
80
84
|
/** The model version used to generate the response. */
|
|
81
85
|
modelVersion?: string;
|
|
82
86
|
/** The session ID of the Live session. */
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { BaseAgent } from '../agents/base_agent.js';
|
|
7
|
+
import { App } from '../apps/app.js';
|
|
8
|
+
import { ResumabilityConfig } from '../apps/resumability_config.js';
|
|
7
9
|
import { BasePlugin } from '../plugins/base_plugin.js';
|
|
8
10
|
import { Runner } from './runner.js';
|
|
9
11
|
/**
|
|
@@ -30,13 +32,17 @@ export declare class InMemoryRunner extends Runner {
|
|
|
30
32
|
* Creates a new InMemoryRunner instance.
|
|
31
33
|
*
|
|
32
34
|
* @param params The configuration for the runner.
|
|
35
|
+
* @param params.app An optional application instance to run.
|
|
33
36
|
* @param params.agent The root agent to run.
|
|
34
37
|
* @param params.appName The application name. Defaults to `'InMemoryRunner'`.
|
|
35
38
|
* @param params.plugins An optional list of plugins.
|
|
39
|
+
* @param params.resumabilityConfig An optional resumability configuration.
|
|
36
40
|
*/
|
|
37
41
|
constructor(params: {
|
|
38
|
-
|
|
42
|
+
app?: App;
|
|
43
|
+
agent?: BaseAgent;
|
|
39
44
|
appName?: string;
|
|
40
45
|
plugins?: BasePlugin[];
|
|
46
|
+
resumabilityConfig?: ResumabilityConfig;
|
|
41
47
|
});
|
|
42
48
|
}
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
import { Content } from '@google/genai';
|
|
7
7
|
import { BaseAgent } from '../agents/base_agent.js';
|
|
8
8
|
import { RunConfig } from '../agents/run_config.js';
|
|
9
|
+
import { App } from '../apps/app.js';
|
|
10
|
+
import { ResumabilityConfig } from '../apps/resumability_config.js';
|
|
9
11
|
import { BaseArtifactService } from '../artifacts/base_artifact_service.js';
|
|
10
12
|
import { BaseCredentialService } from '../auth/credential_service/base_credential_service.js';
|
|
11
13
|
import { Event } from '../events/event.js';
|
|
@@ -13,18 +15,23 @@ import { BaseMemoryService } from '../memory/base_memory_service.js';
|
|
|
13
15
|
import { BasePlugin } from '../plugins/base_plugin.js';
|
|
14
16
|
import { PluginManager } from '../plugins/plugin_manager.js';
|
|
15
17
|
import { BaseSessionService } from '../sessions/base_session_service.js';
|
|
18
|
+
import { Session } from '../sessions/session.js';
|
|
16
19
|
/**
|
|
17
20
|
* The configuration parameters for the Runner.
|
|
18
21
|
*/
|
|
19
22
|
export interface RunnerConfig {
|
|
20
23
|
/**
|
|
21
|
-
* The application
|
|
24
|
+
* The application object. If provided, `appName`, `agent`, and `plugins` will default from this app.
|
|
22
25
|
*/
|
|
23
|
-
|
|
26
|
+
app?: App;
|
|
24
27
|
/**
|
|
25
|
-
* The
|
|
28
|
+
* The application name. Required if `app` is not provided.
|
|
26
29
|
*/
|
|
27
|
-
|
|
30
|
+
appName?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The agent to run. Required if `app` is not provided.
|
|
33
|
+
*/
|
|
34
|
+
agent?: BaseAgent;
|
|
28
35
|
/**
|
|
29
36
|
* An optional list of plugins to apply globally across all agents.
|
|
30
37
|
*/
|
|
@@ -45,6 +52,10 @@ export interface RunnerConfig {
|
|
|
45
52
|
* An optional service for managing authentication credentials.
|
|
46
53
|
*/
|
|
47
54
|
credentialService?: BaseCredentialService;
|
|
55
|
+
/**
|
|
56
|
+
* An optional resumability configuration applied to the runner.
|
|
57
|
+
*/
|
|
58
|
+
resumabilityConfig?: ResumabilityConfig;
|
|
48
59
|
}
|
|
49
60
|
/**
|
|
50
61
|
* A unique symbol to identify ADK agent classes.
|
|
@@ -91,6 +102,7 @@ export declare class Runner {
|
|
|
91
102
|
readonly sessionService: BaseSessionService;
|
|
92
103
|
readonly memoryService?: BaseMemoryService;
|
|
93
104
|
readonly credentialService?: BaseCredentialService;
|
|
105
|
+
readonly resumabilityConfig?: ResumabilityConfig;
|
|
94
106
|
/**
|
|
95
107
|
* Creates a new Runner instance.
|
|
96
108
|
*
|
|
@@ -147,18 +159,40 @@ export declare class Runner {
|
|
|
147
159
|
* Determines the next agent to run to continue the session. This is primarily
|
|
148
160
|
* used for session resumption.
|
|
149
161
|
*/
|
|
162
|
+
/**
|
|
163
|
+
* Determines the next agent to run to continue the session. This is primarily
|
|
164
|
+
* used for session resumption across tool and LRO boundaries.
|
|
165
|
+
*/
|
|
150
166
|
private determineAgentForResumption;
|
|
151
167
|
/**
|
|
152
168
|
* Whether the agent to run can transfer to any other agent in the agent tree.
|
|
153
169
|
*
|
|
154
|
-
* An agent is transferable if:
|
|
155
|
-
* - It is an instance of `LlmAgent`.
|
|
156
|
-
* - All its ancestors are also transferable (i.e., they have
|
|
157
|
-
* `disallowTransferToParent` set to false).
|
|
158
|
-
*
|
|
159
170
|
* @param agentToRun The agent to check for transferability.
|
|
160
171
|
* @returns True if the agent can transfer, False otherwise.
|
|
161
172
|
*/
|
|
162
173
|
private isRoutableLlmAgent;
|
|
163
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Determines the next agent to run to continue the session. This is primarily
|
|
177
|
+
* used for session resumption across tool and LRO boundaries.
|
|
178
|
+
*/
|
|
179
|
+
export declare function determineAgentForResumption(session: Session, rootAgent: BaseAgent, resumabilityConfig?: ResumabilityConfig): BaseAgent;
|
|
180
|
+
/**
|
|
181
|
+
* Whether the agent to run can transfer to any other agent in the agent tree.
|
|
182
|
+
*
|
|
183
|
+
* An agent is transferable if:
|
|
184
|
+
* - It is an instance of `LlmAgent`.
|
|
185
|
+
* - All its ancestors are also transferable (i.e., they have
|
|
186
|
+
* `disallowTransferToParent` set to false).
|
|
187
|
+
*
|
|
188
|
+
* @param agentToRun The agent to check for transferability.
|
|
189
|
+
* @returns True if the agent can transfer, False otherwise.
|
|
190
|
+
*/
|
|
191
|
+
export declare function isRoutableLlmAgent(agentToRun: BaseAgent): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* It iterates through the events in reverse order, and returns the event
|
|
194
|
+
* containing a function call with a functionCall.id matching the
|
|
195
|
+
* functionResponse.id from the last event in the session.
|
|
196
|
+
*/
|
|
197
|
+
export declare function findEventByLastFunctionResponseId(events: Event[]): Event | null;
|
|
164
198
|
export {};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { Event } from '../events/event.js';
|
|
7
|
-
import { Session } from './session.js';
|
|
7
|
+
import { CompositeSessionKey, Session } from './session.js';
|
|
8
8
|
/**
|
|
9
9
|
* The configuration of getting a session.
|
|
10
10
|
*/
|
|
@@ -30,13 +30,7 @@ export interface CreateSessionRequest {
|
|
|
30
30
|
/**
|
|
31
31
|
* The parameters for `getSession`.
|
|
32
32
|
*/
|
|
33
|
-
export interface GetSessionRequest {
|
|
34
|
-
/** The name of the application. */
|
|
35
|
-
appName: string;
|
|
36
|
-
/** The ID of the user. */
|
|
37
|
-
userId: string;
|
|
38
|
-
/** The ID of the session. */
|
|
39
|
-
sessionId: string;
|
|
33
|
+
export interface GetSessionRequest extends CompositeSessionKey {
|
|
40
34
|
/** The configurations for getting the session. */
|
|
41
35
|
config?: GetSessionConfig;
|
|
42
36
|
}
|
|
@@ -60,14 +54,7 @@ export interface ListSessionsRequest {
|
|
|
60
54
|
/**
|
|
61
55
|
* The parameters for `deleteSession`.
|
|
62
56
|
*/
|
|
63
|
-
export
|
|
64
|
-
/** The name of the application. */
|
|
65
|
-
appName: string;
|
|
66
|
-
/** The ID of the user. */
|
|
67
|
-
userId: string;
|
|
68
|
-
/** The ID of the session. */
|
|
69
|
-
sessionId: string;
|
|
70
|
-
}
|
|
57
|
+
export type DeleteSessionRequest = CompositeSessionKey;
|
|
71
58
|
/**
|
|
72
59
|
* The parameters for `appendEvent`.
|
|
73
60
|
*/
|
|
@@ -4,6 +4,17 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { Event } from '../events/event.js';
|
|
7
|
+
/**
|
|
8
|
+
* Represents a unified composite session key grouping application, user, and session identifiers.
|
|
9
|
+
*/
|
|
10
|
+
export interface CompositeSessionKey {
|
|
11
|
+
/** The name of the application. */
|
|
12
|
+
appName: string;
|
|
13
|
+
/** The ID of the user. */
|
|
14
|
+
userId: string;
|
|
15
|
+
/** The ID of the session. */
|
|
16
|
+
sessionId: string;
|
|
17
|
+
}
|
|
7
18
|
/**
|
|
8
19
|
* Represents a session in a conversation between agents and users.
|
|
9
20
|
*/
|
|
@@ -11,6 +11,14 @@ import { Session } from './session.js';
|
|
|
11
11
|
* Checks if the given URI is a Vertex AI session service URI.
|
|
12
12
|
*/
|
|
13
13
|
export declare function isVertexAiConnectionString(uri?: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Quotes a value for safe use as a Google AIP-160 filter string literal.
|
|
16
|
+
*
|
|
17
|
+
* Backslashes are escaped first, then double quotes, so that caller-controlled
|
|
18
|
+
* input stays inside the quoted value and cannot break out to inject additional
|
|
19
|
+
* filter predicates. See https://google.aip.dev/160.
|
|
20
|
+
*/
|
|
21
|
+
export declare function quoteFilterLiteral(value: string): string;
|
|
14
22
|
export interface VertexAiSessionServiceOptions {
|
|
15
23
|
projectId?: string;
|
|
16
24
|
location?: string;
|
|
@@ -32,6 +40,6 @@ export declare class VertexAiSessionService extends BaseSessionService {
|
|
|
32
40
|
createSession({ appName, userId, state, sessionId, }: CreateSessionRequest): Promise<Session>;
|
|
33
41
|
getSession({ appName, userId, sessionId, config, }: GetSessionRequest): Promise<Session | undefined>;
|
|
34
42
|
listSessions({ appName, userId, limit, offset, page, order, }: ListSessionsRequest): Promise<ListSessionsResponse>;
|
|
35
|
-
deleteSession({ appName, userId
|
|
43
|
+
deleteSession({ appName, userId, sessionId, }: DeleteSessionRequest): Promise<void>;
|
|
36
44
|
appendEvent({ session, event, }: AppendEventRequest): Promise<Event>;
|
|
37
45
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { FunctionDeclaration } from '@google/genai';
|
|
7
|
+
import { BaseTool, RunAsyncToolRequest } from './base_tool.js';
|
|
8
|
+
/**
|
|
9
|
+
* Tool for requesting context consolidation (compaction).
|
|
10
|
+
*
|
|
11
|
+
* When called by an LLM agent, this tool sets the state flags
|
|
12
|
+
* `temp:consolidate_context` and optionally `temp:consolidate_context_detail`,
|
|
13
|
+
* signalling the context compactor to trigger compaction.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ConsolidateContextTool extends BaseTool {
|
|
16
|
+
constructor();
|
|
17
|
+
_getDeclaration(): FunctionDeclaration;
|
|
18
|
+
runAsync({ args, toolContext, }: RunAsyncToolRequest): Promise<unknown>;
|
|
19
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { Part } from '@google/genai';
|
|
7
|
-
import { ArtifactVersion, BaseArtifactService, DeleteArtifactRequest, ListVersionsRequest, LoadArtifactRequest, SaveArtifactRequest } from '../artifacts/base_artifact_service.js';
|
|
7
|
+
import { ArtifactVersion, BaseArtifactService, DeleteArtifactRequest, ListArtifactKeysRequest, ListVersionsRequest, LoadArtifactRequest, SaveArtifactRequest } from '../artifacts/base_artifact_service.js';
|
|
8
8
|
import { Context } from '../agents/context.js';
|
|
9
9
|
/**
|
|
10
10
|
* Artifact service that forwards to the parent tool context.
|
|
@@ -15,7 +15,8 @@ export declare class ForwardingArtifactService implements BaseArtifactService {
|
|
|
15
15
|
constructor(toolContext: Context);
|
|
16
16
|
saveArtifact(request: SaveArtifactRequest): Promise<number>;
|
|
17
17
|
loadArtifact(request: LoadArtifactRequest): Promise<Part | undefined>;
|
|
18
|
-
listArtifactKeys(): Promise<string[]>;
|
|
18
|
+
listArtifactKeys(_request: ListArtifactKeysRequest): Promise<string[]>;
|
|
19
|
+
private getArtifactService;
|
|
19
20
|
deleteArtifact(request: DeleteArtifactRequest): Promise<void>;
|
|
20
21
|
listVersions(request: ListVersionsRequest): Promise<number[]>;
|
|
21
22
|
listArtifactVersions(request: ListVersionsRequest): Promise<ArtifactVersion[]>;
|
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
export declare function parseUserAgent(userAgent: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Runs the given callback within a context that has the specified client label.
|
|
9
|
+
* All LLM calls made within this callback will include the client label in their tracking headers.
|
|
10
|
+
*
|
|
11
|
+
* @param clientLabel The custom client label to apply.
|
|
12
|
+
* @param callback The callback function to execute.
|
|
13
|
+
* @return The result of the callback.
|
|
14
|
+
*/
|
|
15
|
+
export declare function runWithClientLabel<R>(clientLabel: string, callback: () => R): R;
|
|
6
16
|
/**
|
|
7
17
|
* Returns the current list of client labels that can be added to HTTP Headers.
|
|
8
18
|
*/
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
export declare function isBrowser(): boolean;
|
|
10
10
|
export declare function randomUUID(): string;
|
|
11
11
|
/**
|
|
12
|
-
* Encodes the given string to base64.
|
|
12
|
+
* Encodes the given string or Uint8Array to base64.
|
|
13
13
|
*
|
|
14
|
-
* @param data The
|
|
14
|
+
* @param data The data to encode.
|
|
15
15
|
* @return The base64-encoded string.
|
|
16
16
|
*/
|
|
17
|
-
export declare function base64Encode(data: string): string;
|
|
17
|
+
export declare function base64Encode(data: string | Uint8Array): string;
|
|
18
18
|
/**
|
|
19
19
|
* Decodes the given base64 string to a string.
|
|
20
20
|
*
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export type TaskExecutable<T = void> = (abortSignal: AbortSignal) => Promise<T>;
|
|
7
|
+
/**
|
|
8
|
+
* Represents a runtime task wrapping a promise, allowing status check and cancellation.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Task<T = void> {
|
|
11
|
+
executable: TaskExecutable<T>;
|
|
12
|
+
private isDone;
|
|
13
|
+
private abortController;
|
|
14
|
+
promise: Promise<T>;
|
|
15
|
+
constructor(executable: TaskExecutable<T>);
|
|
16
|
+
/**
|
|
17
|
+
* Cancels the task execution.
|
|
18
|
+
*/
|
|
19
|
+
cancel(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Returns true if the task has completed (either resolved or rejected).
|
|
22
|
+
*/
|
|
23
|
+
done(): boolean;
|
|
24
|
+
}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -5,9 +5,14 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
5
5
|
* Copyright 2025 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
+
import { Task } from "../utils/task.js";
|
|
8
9
|
class ActiveStreamingTool {
|
|
9
10
|
constructor(params = {}) {
|
|
10
|
-
|
|
11
|
+
if (params.task instanceof Promise) {
|
|
12
|
+
this.task = new Task(() => params.task);
|
|
13
|
+
} else {
|
|
14
|
+
this.task = params.task;
|
|
15
|
+
}
|
|
11
16
|
this.stream = params.stream;
|
|
12
17
|
}
|
|
13
18
|
}
|
|
@@ -56,9 +56,6 @@ class Context extends ReadonlyContext {
|
|
|
56
56
|
throw new Error("Artifact service is not initialized.");
|
|
57
57
|
}
|
|
58
58
|
return this.invocationContext.artifactService.loadArtifact({
|
|
59
|
-
appName: this.invocationContext.appName,
|
|
60
|
-
userId: this.invocationContext.userId,
|
|
61
|
-
sessionId: this.invocationContext.session.id,
|
|
62
59
|
filename,
|
|
63
60
|
version
|
|
64
61
|
});
|
|
@@ -75,9 +72,6 @@ class Context extends ReadonlyContext {
|
|
|
75
72
|
throw new Error("Artifact service is not initialized.");
|
|
76
73
|
}
|
|
77
74
|
const version = await this.invocationContext.artifactService.saveArtifact({
|
|
78
|
-
appName: this.invocationContext.appName,
|
|
79
|
-
userId: this.invocationContext.userId,
|
|
80
|
-
sessionId: this.invocationContext.session.id,
|
|
81
75
|
filename,
|
|
82
76
|
artifact
|
|
83
77
|
});
|
|
@@ -110,11 +104,7 @@ class Context extends ReadonlyContext {
|
|
|
110
104
|
if (!this.invocationContext.artifactService) {
|
|
111
105
|
throw new Error("Artifact service is not initialized.");
|
|
112
106
|
}
|
|
113
|
-
return this.invocationContext.artifactService.listArtifactKeys(
|
|
114
|
-
appName: this.invocationContext.session.appName,
|
|
115
|
-
userId: this.invocationContext.session.userId,
|
|
116
|
-
sessionId: this.invocationContext.session.id
|
|
117
|
-
});
|
|
107
|
+
return this.invocationContext.artifactService.listArtifactKeys();
|
|
118
108
|
}
|
|
119
109
|
/**
|
|
120
110
|
* Searches the memory of the current user.
|
|
@@ -7,7 +7,11 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
7
7
|
*/
|
|
8
8
|
import { createUserContent } from "@google/genai";
|
|
9
9
|
import { isEmpty } from "lodash-es";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
createEvent,
|
|
12
|
+
getFunctionCalls,
|
|
13
|
+
getFunctionResponses
|
|
14
|
+
} from "../events/event.js";
|
|
11
15
|
import { mergeEventActions } from "../events/event_actions.js";
|
|
12
16
|
import { randomUUID } from "../utils/env_aware_utils.js";
|
|
13
17
|
import { logger } from "../utils/logger.js";
|
|
@@ -39,18 +43,6 @@ function populateClientFunctionCallId(modelResponseEvent) {
|
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
|
-
function removeClientFunctionCallId(content) {
|
|
43
|
-
if (content && content.parts) {
|
|
44
|
-
for (const part of content.parts) {
|
|
45
|
-
if (part.functionCall && part.functionCall.id && part.functionCall.id.startsWith(AF_FUNCTION_CALL_ID_PREFIX)) {
|
|
46
|
-
part.functionCall.id = void 0;
|
|
47
|
-
}
|
|
48
|
-
if (part.functionResponse && part.functionResponse.id && part.functionResponse.id.startsWith(AF_FUNCTION_CALL_ID_PREFIX)) {
|
|
49
|
-
part.functionResponse.id = void 0;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
46
|
function getLongRunningFunctionCalls(functionCalls, toolsDict) {
|
|
55
47
|
const longRunningToolIds = /* @__PURE__ */ new Set();
|
|
56
48
|
for (const functionCall of functionCalls) {
|
|
@@ -393,9 +385,39 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
393
385
|
timestamp: baseEvent.timestamp
|
|
394
386
|
});
|
|
395
387
|
}
|
|
388
|
+
function findEventByFunctionCallId(events, functionCallId, endIndex = events.length) {
|
|
389
|
+
for (let i = endIndex - 1; i >= 0; i--) {
|
|
390
|
+
const event = events[i];
|
|
391
|
+
const functionCalls = getFunctionCalls(event);
|
|
392
|
+
for (const functionCall of functionCalls) {
|
|
393
|
+
if (functionCall.id === functionCallId) {
|
|
394
|
+
return event;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return void 0;
|
|
399
|
+
}
|
|
400
|
+
function findMatchingFunctionCall(events) {
|
|
401
|
+
if (!events.length) {
|
|
402
|
+
return void 0;
|
|
403
|
+
}
|
|
404
|
+
const lastEvent = events[events.length - 1];
|
|
405
|
+
const functionResponses = getFunctionResponses(lastEvent);
|
|
406
|
+
if (!functionResponses.length || !functionResponses[0].id) {
|
|
407
|
+
return void 0;
|
|
408
|
+
}
|
|
409
|
+
return findEventByFunctionCallId(
|
|
410
|
+
events,
|
|
411
|
+
functionResponses[0].id,
|
|
412
|
+
events.length - 1
|
|
413
|
+
);
|
|
414
|
+
}
|
|
396
415
|
export {
|
|
416
|
+
AF_FUNCTION_CALL_ID_PREFIX,
|
|
397
417
|
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
398
418
|
REQUEST_EUC_FUNCTION_CALL_NAME,
|
|
419
|
+
findEventByFunctionCallId,
|
|
420
|
+
findMatchingFunctionCall,
|
|
399
421
|
functionsExportedForTestingOnly,
|
|
400
422
|
generateAuthEvent,
|
|
401
423
|
generateClientFunctionCallId,
|
|
@@ -404,6 +426,5 @@ export {
|
|
|
404
426
|
handleFunctionCallList,
|
|
405
427
|
handleFunctionCallsAsync,
|
|
406
428
|
mergeParallelFunctionResponseEvents,
|
|
407
|
-
populateClientFunctionCallId
|
|
408
|
-
removeClientFunctionCallId
|
|
429
|
+
populateClientFunctionCallId
|
|
409
430
|
};
|