@google/adk 0.1.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/LICENSE +202 -0
- package/README.md +9 -0
- package/dist/cjs/agents/active_streaming_tool.js +44 -0
- package/dist/cjs/agents/base_agent.js +245 -0
- package/dist/cjs/agents/base_llm_processor.js +44 -0
- package/dist/cjs/agents/callback_context.js +98 -0
- package/dist/cjs/agents/content_processor_utils.js +299 -0
- package/dist/cjs/agents/functions.js +394 -0
- package/dist/cjs/agents/instructions.js +110 -0
- package/dist/cjs/agents/invocation_context.js +109 -0
- package/dist/cjs/agents/live_request_queue.js +136 -0
- package/dist/cjs/agents/llm_agent.js +859 -0
- package/dist/cjs/agents/loop_agent.js +68 -0
- package/dist/cjs/agents/parallel_agent.js +78 -0
- package/dist/cjs/agents/readonly_context.js +68 -0
- package/dist/cjs/agents/run_config.js +74 -0
- package/dist/cjs/agents/sequential_agent.js +84 -0
- package/dist/cjs/agents/transcription_entry.js +27 -0
- package/dist/cjs/artifacts/base_artifact_service.js +27 -0
- package/dist/cjs/artifacts/in_memory_artifact_service.js +119 -0
- package/dist/cjs/auth/auth_credential.js +46 -0
- package/dist/cjs/auth/auth_handler.js +92 -0
- package/dist/cjs/auth/auth_schemes.js +62 -0
- package/dist/cjs/auth/auth_tool.js +27 -0
- package/dist/cjs/auth/credential_service/base_credential_service.js +27 -0
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +63 -0
- package/dist/cjs/code_executors/base_code_executor.js +76 -0
- package/dist/cjs/code_executors/built_in_code_executor.js +58 -0
- package/dist/cjs/code_executors/code_execution_utils.js +142 -0
- package/dist/cjs/code_executors/code_executor_context.js +198 -0
- package/dist/cjs/common.js +161 -0
- package/dist/cjs/events/event.js +107 -0
- package/dist/cjs/events/event_actions.js +83 -0
- package/dist/cjs/examples/base_example_provider.js +40 -0
- package/dist/cjs/examples/example.js +27 -0
- package/dist/cjs/examples/example_util.js +107 -0
- package/dist/cjs/index.js +40 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/index_web.js +33 -0
- package/dist/cjs/memory/base_memory_service.js +27 -0
- package/dist/cjs/memory/in_memory_memory_service.js +97 -0
- package/dist/cjs/memory/memory_entry.js +27 -0
- package/dist/cjs/models/base_llm.js +77 -0
- package/dist/cjs/models/base_llm_connection.js +27 -0
- package/dist/cjs/models/gemini_llm_connection.js +132 -0
- package/dist/cjs/models/google_llm.js +321 -0
- package/dist/cjs/models/llm_request.js +82 -0
- package/dist/cjs/models/llm_response.js +71 -0
- package/dist/cjs/models/registry.js +121 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/plugins/base_plugin.js +236 -0
- package/dist/cjs/plugins/logging_plugin.js +222 -0
- package/dist/cjs/plugins/plugin_manager.js +239 -0
- package/dist/cjs/plugins/security_plugin.js +153 -0
- package/dist/cjs/runner/in_memory_runner.js +58 -0
- package/dist/cjs/runner/runner.js +276 -0
- package/dist/cjs/sessions/base_session_service.js +71 -0
- package/dist/cjs/sessions/in_memory_session_service.js +184 -0
- package/dist/cjs/sessions/session.js +48 -0
- package/dist/cjs/sessions/state.js +101 -0
- package/dist/cjs/tools/agent_tool.js +134 -0
- package/dist/cjs/tools/base_tool.js +107 -0
- package/dist/cjs/tools/base_toolset.js +76 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +71 -0
- package/dist/cjs/tools/function_tool.js +101 -0
- package/dist/cjs/tools/google_search_tool.js +76 -0
- package/dist/cjs/tools/long_running_tool.js +63 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +65 -0
- package/dist/cjs/tools/mcp/mcp_tool.js +65 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +61 -0
- package/dist/cjs/tools/tool_confirmation.js +49 -0
- package/dist/cjs/tools/tool_context.js +129 -0
- package/dist/cjs/utils/deep_clone.js +44 -0
- package/dist/cjs/utils/env_aware_utils.js +83 -0
- package/dist/cjs/utils/gemini_schema_util.js +88 -0
- package/dist/cjs/utils/logger.js +121 -0
- package/dist/cjs/utils/model_name.js +64 -0
- package/dist/cjs/utils/simple_zod_to_json.js +191 -0
- package/dist/cjs/utils/variant_utils.js +55 -0
- package/dist/cjs/version.js +39 -0
- package/dist/esm/agents/active_streaming_tool.js +14 -0
- package/dist/esm/agents/base_agent.js +214 -0
- package/dist/esm/agents/base_llm_processor.js +13 -0
- package/dist/esm/agents/callback_context.js +68 -0
- package/dist/esm/agents/content_processor_utils.js +268 -0
- package/dist/esm/agents/functions.js +353 -0
- package/dist/esm/agents/instructions.js +80 -0
- package/dist/esm/agents/invocation_context.js +78 -0
- package/dist/esm/agents/live_request_queue.js +106 -0
- package/dist/esm/agents/llm_agent.js +828 -0
- package/dist/esm/agents/loop_agent.js +38 -0
- package/dist/esm/agents/parallel_agent.js +48 -0
- package/dist/esm/agents/readonly_context.js +38 -0
- package/dist/esm/agents/run_config.js +43 -0
- package/dist/esm/agents/sequential_agent.js +54 -0
- package/dist/esm/agents/transcription_entry.js +5 -0
- package/dist/esm/artifacts/base_artifact_service.js +5 -0
- package/dist/esm/artifacts/in_memory_artifact_service.js +89 -0
- package/dist/esm/auth/auth_credential.js +16 -0
- package/dist/esm/auth/auth_handler.js +62 -0
- package/dist/esm/auth/auth_schemes.js +31 -0
- package/dist/esm/auth/auth_tool.js +5 -0
- package/dist/esm/auth/credential_service/base_credential_service.js +5 -0
- package/dist/esm/auth/credential_service/in_memory_credential_service.js +33 -0
- package/dist/esm/code_executors/base_code_executor.js +46 -0
- package/dist/esm/code_executors/built_in_code_executor.js +28 -0
- package/dist/esm/code_executors/code_execution_utils.js +108 -0
- package/dist/esm/code_executors/code_executor_context.js +168 -0
- package/dist/esm/common.js +85 -0
- package/dist/esm/events/event.js +72 -0
- package/dist/esm/events/event_actions.js +52 -0
- package/dist/esm/examples/base_example_provider.js +10 -0
- package/dist/esm/examples/example.js +5 -0
- package/dist/esm/examples/example_util.js +76 -0
- package/dist/esm/index.js +40 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/index_web.js +6 -0
- package/dist/esm/memory/base_memory_service.js +5 -0
- package/dist/esm/memory/in_memory_memory_service.js +67 -0
- package/dist/esm/memory/memory_entry.js +5 -0
- package/dist/esm/models/base_llm.js +47 -0
- package/dist/esm/models/base_llm_connection.js +5 -0
- package/dist/esm/models/gemini_llm_connection.js +102 -0
- package/dist/esm/models/google_llm.js +291 -0
- package/dist/esm/models/llm_request.js +50 -0
- package/dist/esm/models/llm_response.js +41 -0
- package/dist/esm/models/registry.js +91 -0
- package/dist/esm/plugins/base_plugin.js +206 -0
- package/dist/esm/plugins/logging_plugin.js +192 -0
- package/dist/esm/plugins/plugin_manager.js +209 -0
- package/dist/esm/plugins/security_plugin.js +119 -0
- package/dist/esm/runner/in_memory_runner.js +28 -0
- package/dist/esm/runner/runner.js +246 -0
- package/dist/esm/sessions/base_session_service.js +41 -0
- package/dist/esm/sessions/in_memory_session_service.js +154 -0
- package/dist/esm/sessions/session.js +18 -0
- package/dist/esm/sessions/state.js +71 -0
- package/dist/esm/tools/agent_tool.js +104 -0
- package/dist/esm/tools/base_tool.js +77 -0
- package/dist/esm/tools/base_toolset.js +46 -0
- package/dist/esm/tools/forwarding_artifact_service.js +41 -0
- package/dist/esm/tools/function_tool.js +71 -0
- package/dist/esm/tools/google_search_tool.js +46 -0
- package/dist/esm/tools/long_running_tool.js +33 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +35 -0
- package/dist/esm/tools/mcp/mcp_tool.js +35 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +31 -0
- package/dist/esm/tools/tool_confirmation.js +19 -0
- package/dist/esm/tools/tool_context.js +99 -0
- package/dist/esm/utils/deep_clone.js +14 -0
- package/dist/esm/utils/env_aware_utils.js +49 -0
- package/dist/esm/utils/gemini_schema_util.js +58 -0
- package/dist/esm/utils/logger.js +89 -0
- package/dist/esm/utils/model_name.js +31 -0
- package/dist/esm/utils/simple_zod_to_json.js +160 -0
- package/dist/esm/utils/variant_utils.js +24 -0
- package/dist/esm/version.js +9 -0
- package/dist/types/agents/active_streaming_tool.d.ts +29 -0
- package/dist/types/agents/base_agent.d.ts +167 -0
- package/dist/types/agents/base_llm_processor.d.ts +27 -0
- package/dist/types/agents/callback_context.d.ts +42 -0
- package/dist/types/agents/content_processor_utils.d.ts +36 -0
- package/dist/types/agents/functions.d.ts +90 -0
- package/dist/types/agents/instructions.d.ts +32 -0
- package/dist/types/agents/invocation_context.d.ts +155 -0
- package/dist/types/agents/live_request_queue.d.ts +67 -0
- package/dist/types/agents/llm_agent.d.ts +333 -0
- package/dist/types/agents/loop_agent.d.ts +31 -0
- package/dist/types/agents/parallel_agent.d.ts +21 -0
- package/dist/types/agents/readonly_context.d.ts +31 -0
- package/dist/types/agents/run_config.d.ts +76 -0
- package/dist/types/agents/sequential_agent.d.ts +26 -0
- package/dist/types/agents/transcription_entry.d.ts +17 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +127 -0
- package/dist/types/artifacts/in_memory_artifact_service.d.ts +18 -0
- package/dist/types/auth/auth_credential.d.ts +227 -0
- package/dist/types/auth/auth_handler.d.ts +27 -0
- package/dist/types/auth/auth_schemes.d.ts +36 -0
- package/dist/types/auth/auth_tool.d.ts +51 -0
- package/dist/types/auth/credential_service/base_credential_service.d.ts +27 -0
- package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +19 -0
- package/dist/types/code_executors/base_code_executor.d.ts +60 -0
- package/dist/types/code_executors/built_in_code_executor.d.ts +13 -0
- package/dist/types/code_executors/code_execution_utils.d.ts +99 -0
- package/dist/types/code_executors/code_executor_context.d.ts +92 -0
- package/dist/types/common.d.ts +51 -0
- package/dist/types/events/event.d.ts +81 -0
- package/dist/types/events/event_actions.d.ts +74 -0
- package/dist/types/examples/base_example_provider.d.ts +20 -0
- package/dist/types/examples/example.d.ts +19 -0
- package/dist/types/examples/example_util.d.ts +13 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index_web.d.ts +6 -0
- package/dist/types/memory/base_memory_service.d.ts +47 -0
- package/dist/types/memory/in_memory_memory_service.d.ts +18 -0
- package/dist/types/memory/memory_entry.d.ts +24 -0
- package/dist/types/models/base_llm.d.ts +46 -0
- package/dist/types/models/base_llm_connection.d.ts +51 -0
- package/dist/types/models/gemini_llm_connection.d.ts +54 -0
- package/dist/types/models/google_llm.d.ts +88 -0
- package/dist/types/models/llm_request.d.ts +49 -0
- package/dist/types/models/llm_response.d.ts +79 -0
- package/dist/types/models/registry.d.ts +45 -0
- package/dist/types/plugins/base_plugin.d.ts +310 -0
- package/dist/types/plugins/logging_plugin.d.ts +104 -0
- package/dist/types/plugins/plugin_manager.d.ts +155 -0
- package/dist/types/plugins/security_plugin.d.ts +60 -0
- package/dist/types/runner/in_memory_runner.d.ts +15 -0
- package/dist/types/runner/runner.d.ts +80 -0
- package/dist/types/sessions/base_session_service.d.ts +129 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +32 -0
- package/dist/types/sessions/session.d.ts +46 -0
- package/dist/types/sessions/state.d.ts +57 -0
- package/dist/types/tools/agent_tool.d.ts +37 -0
- package/dist/types/tools/base_tool.d.ts +84 -0
- package/dist/types/tools/base_toolset.d.ts +64 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +21 -0
- package/dist/types/tools/function_tool.d.ts +48 -0
- package/dist/types/tools/google_search_tool.d.ts +18 -0
- package/dist/types/tools/long_running_tool.d.ts +18 -0
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +57 -0
- package/dist/types/tools/mcp/mcp_tool.d.ts +30 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +39 -0
- package/dist/types/tools/tool_confirmation.d.ts +25 -0
- package/dist/types/tools/tool_context.d.ts +63 -0
- package/dist/types/utils/deep_clone.d.ts +1 -0
- package/dist/types/utils/env_aware_utils.d.ts +31 -0
- package/dist/types/utils/gemini_schema_util.d.ts +23 -0
- package/dist/types/utils/logger.d.ts +41 -0
- package/dist/types/utils/model_name.d.ts +34 -0
- package/dist/types/utils/simple_zod_to_json.d.ts +12 -0
- package/dist/types/utils/variant_utils.d.ts +24 -0
- package/dist/types/version.d.ts +6 -0
- package/dist/web/agents/active_streaming_tool.js +14 -0
- package/dist/web/agents/base_agent.js +265 -0
- package/dist/web/agents/base_llm_processor.js +13 -0
- package/dist/web/agents/callback_context.js +68 -0
- package/dist/web/agents/content_processor_utils.js +268 -0
- package/dist/web/agents/functions.js +353 -0
- package/dist/web/agents/instructions.js +80 -0
- package/dist/web/agents/invocation_context.js +78 -0
- package/dist/web/agents/live_request_queue.js +124 -0
- package/dist/web/agents/llm_agent.js +973 -0
- package/dist/web/agents/loop_agent.js +71 -0
- package/dist/web/agents/parallel_agent.js +83 -0
- package/dist/web/agents/readonly_context.js +38 -0
- package/dist/web/agents/run_config.js +43 -0
- package/dist/web/agents/sequential_agent.js +99 -0
- package/dist/web/agents/transcription_entry.js +5 -0
- package/dist/web/artifacts/base_artifact_service.js +5 -0
- package/dist/web/artifacts/in_memory_artifact_service.js +89 -0
- package/dist/web/auth/auth_credential.js +16 -0
- package/dist/web/auth/auth_handler.js +62 -0
- package/dist/web/auth/auth_schemes.js +31 -0
- package/dist/web/auth/auth_tool.js +5 -0
- package/dist/web/auth/credential_service/base_credential_service.js +5 -0
- package/dist/web/auth/credential_service/in_memory_credential_service.js +33 -0
- package/dist/web/code_executors/base_code_executor.js +46 -0
- package/dist/web/code_executors/built_in_code_executor.js +28 -0
- package/dist/web/code_executors/code_execution_utils.js +105 -0
- package/dist/web/code_executors/code_executor_context.js +168 -0
- package/dist/web/common.js +85 -0
- package/dist/web/events/event.js +90 -0
- package/dist/web/events/event_actions.js +67 -0
- package/dist/web/examples/base_example_provider.js +10 -0
- package/dist/web/examples/example.js +5 -0
- package/dist/web/examples/example_util.js +75 -0
- package/dist/web/index.js +13 -0
- package/dist/web/index.js.map +7 -0
- package/dist/web/index_web.js +6 -0
- package/dist/web/memory/base_memory_service.js +5 -0
- package/dist/web/memory/in_memory_memory_service.js +67 -0
- package/dist/web/memory/memory_entry.js +5 -0
- package/dist/web/models/base_llm.js +47 -0
- package/dist/web/models/base_llm_connection.js +5 -0
- package/dist/web/models/gemini_llm_connection.js +120 -0
- package/dist/web/models/google_llm.js +332 -0
- package/dist/web/models/llm_request.js +50 -0
- package/dist/web/models/llm_response.js +41 -0
- package/dist/web/models/registry.js +91 -0
- package/dist/web/plugins/base_plugin.js +206 -0
- package/dist/web/plugins/logging_plugin.js +192 -0
- package/dist/web/plugins/plugin_manager.js +209 -0
- package/dist/web/plugins/security_plugin.js +119 -0
- package/dist/web/runner/in_memory_runner.js +28 -0
- package/dist/web/runner/runner.js +277 -0
- package/dist/web/sessions/base_session_service.js +41 -0
- package/dist/web/sessions/in_memory_session_service.js +154 -0
- package/dist/web/sessions/session.js +18 -0
- package/dist/web/sessions/state.js +87 -0
- package/dist/web/tools/agent_tool.js +118 -0
- package/dist/web/tools/base_tool.js +77 -0
- package/dist/web/tools/base_toolset.js +46 -0
- package/dist/web/tools/forwarding_artifact_service.js +41 -0
- package/dist/web/tools/function_tool.js +71 -0
- package/dist/web/tools/google_search_tool.js +46 -0
- package/dist/web/tools/long_running_tool.js +50 -0
- package/dist/web/tools/mcp/mcp_session_manager.js +35 -0
- package/dist/web/tools/mcp/mcp_tool.js +35 -0
- package/dist/web/tools/mcp/mcp_toolset.js +31 -0
- package/dist/web/tools/tool_confirmation.js +19 -0
- package/dist/web/tools/tool_context.js +99 -0
- package/dist/web/utils/deep_clone.js +14 -0
- package/dist/web/utils/env_aware_utils.js +49 -0
- package/dist/web/utils/gemini_schema_util.js +58 -0
- package/dist/web/utils/logger.js +89 -0
- package/dist/web/utils/model_name.js +31 -0
- package/dist/web/utils/simple_zod_to_json.js +174 -0
- package/dist/web/utils/variant_utils.js +24 -0
- package/dist/web/version.js +9 -0
- package/package.json +61 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { GenerateContentConfig, Schema } from '@google/genai';
|
|
7
|
+
import { Event } from '../events/event.js';
|
|
8
|
+
import { BaseExampleProvider } from '../examples/base_example_provider.js';
|
|
9
|
+
import { Example } from '../examples/example.js';
|
|
10
|
+
import { BaseLlm } from '../models/base_llm.js';
|
|
11
|
+
import { LlmRequest } from '../models/llm_request.js';
|
|
12
|
+
import { LlmResponse } from '../models/llm_response.js';
|
|
13
|
+
import { BaseTool } from '../tools/base_tool.js';
|
|
14
|
+
import { BaseToolset } from '../tools/base_toolset.js';
|
|
15
|
+
import { ToolContext } from '../tools/tool_context.js';
|
|
16
|
+
import { BaseAgent, BaseAgentConfig } from './base_agent.js';
|
|
17
|
+
import { BaseLlmRequestProcessor, BaseLlmResponseProcessor } from './base_llm_processor.js';
|
|
18
|
+
import { CallbackContext } from './callback_context.js';
|
|
19
|
+
import { InvocationContext } from './invocation_context.js';
|
|
20
|
+
import { ReadonlyContext } from './readonly_context.js';
|
|
21
|
+
/** An object that can provide an instruction string. */
|
|
22
|
+
export type InstructionProvider = (context: ReadonlyContext) => string | Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* A callback that runs before a request is sent to the model.
|
|
25
|
+
*
|
|
26
|
+
* @param context The current callback context.
|
|
27
|
+
* @param request The raw model request. Callback can mutate the request.
|
|
28
|
+
* @returns The content to return to the user. When present, the model call
|
|
29
|
+
* will be skipped and the provided content will be returned to user.
|
|
30
|
+
*/
|
|
31
|
+
export type SingleBeforeModelCallback = (params: {
|
|
32
|
+
context: CallbackContext;
|
|
33
|
+
request: LlmRequest;
|
|
34
|
+
}) => LlmResponse | undefined | Promise<LlmResponse | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* A single callback or a list of callbacks.
|
|
37
|
+
*
|
|
38
|
+
* When a list of callbacks is provided, the callbacks will be called in the
|
|
39
|
+
* order they are listed until a callback does not return None.
|
|
40
|
+
*/
|
|
41
|
+
export type BeforeModelCallback = SingleBeforeModelCallback | SingleBeforeModelCallback[];
|
|
42
|
+
/**
|
|
43
|
+
* A callback that runs after a response is received from the model.
|
|
44
|
+
*
|
|
45
|
+
* @param context The current callback context.
|
|
46
|
+
* @param response The actual model response.
|
|
47
|
+
* @returns The content to return to the user. When present, the actual model
|
|
48
|
+
* response will be ignored and the provided content will be returned to
|
|
49
|
+
* user.
|
|
50
|
+
*/
|
|
51
|
+
export type SingleAfterModelCallback = (params: {
|
|
52
|
+
context: CallbackContext;
|
|
53
|
+
response: LlmResponse;
|
|
54
|
+
}) => LlmResponse | undefined | Promise<LlmResponse | undefined>;
|
|
55
|
+
/**
|
|
56
|
+
* A single callback or a list of callbacks.
|
|
57
|
+
*
|
|
58
|
+
* When a list of callbacks is provided, the callbacks will be called in the
|
|
59
|
+
order they are listed until a callback does not return None.
|
|
60
|
+
*/
|
|
61
|
+
export type AfterModelCallback = SingleAfterModelCallback | SingleAfterModelCallback[];
|
|
62
|
+
/** A generic dictionary type. */
|
|
63
|
+
export type Dict = {
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* A callback that runs before a tool is called.
|
|
68
|
+
*
|
|
69
|
+
* @param tool The tool to be called.
|
|
70
|
+
* @param args The arguments to the tool.
|
|
71
|
+
* @param tool_context: ToolContext,
|
|
72
|
+
* @returns The tool response. When present, the returned tool response will
|
|
73
|
+
* be used and the framework will skip calling the actual tool.
|
|
74
|
+
*/
|
|
75
|
+
export type SingleBeforeToolCallback = (params: {
|
|
76
|
+
tool: BaseTool;
|
|
77
|
+
args: Dict;
|
|
78
|
+
context: ToolContext;
|
|
79
|
+
}) => Dict | undefined | Promise<Dict | undefined>;
|
|
80
|
+
/**
|
|
81
|
+
* A single callback or a list of callbacks.
|
|
82
|
+
*
|
|
83
|
+
* When a list of callbacks is provided, the callbacks will be called in the
|
|
84
|
+
* order they are listed until a callback does not return None.
|
|
85
|
+
*/
|
|
86
|
+
export type BeforeToolCallback = SingleBeforeToolCallback | SingleBeforeToolCallback[];
|
|
87
|
+
/**
|
|
88
|
+
* A callback that runs after a tool is called.
|
|
89
|
+
*
|
|
90
|
+
* @param tool The tool to be called.
|
|
91
|
+
* @param args The arguments to the tool.
|
|
92
|
+
* @param tool_context: ToolContext,
|
|
93
|
+
* @param tool_response: The response from the tool.
|
|
94
|
+
* @returns When present, the returned dict will be used as tool result.
|
|
95
|
+
*/
|
|
96
|
+
export type SingleAfterToolCallback = (params: {
|
|
97
|
+
tool: BaseTool;
|
|
98
|
+
args: Dict;
|
|
99
|
+
context: ToolContext;
|
|
100
|
+
response: Dict;
|
|
101
|
+
}) => Dict | undefined | Promise<Dict | undefined>;
|
|
102
|
+
/**
|
|
103
|
+
* A single callback or a list of callbacks.
|
|
104
|
+
*
|
|
105
|
+
* When a list of callbacks is provided, the callbacks will be called in the
|
|
106
|
+
* order they are listed until acallback does not return None.
|
|
107
|
+
*/
|
|
108
|
+
export type AfterToolCallback = SingleAfterToolCallback | SingleAfterToolCallback[];
|
|
109
|
+
/** A list of examples or an example provider. */
|
|
110
|
+
export type ExamplesUnion = Example[] | BaseExampleProvider;
|
|
111
|
+
/** A union of tool types that can be provided to an agent. */
|
|
112
|
+
export type ToolUnion = BaseTool | BaseToolset;
|
|
113
|
+
export interface LlmAgentConfig extends BaseAgentConfig {
|
|
114
|
+
/**
|
|
115
|
+
* The model to use for the agent.
|
|
116
|
+
*/
|
|
117
|
+
model?: string | BaseLlm;
|
|
118
|
+
/** Instructions for the LLM model, guiding the agent's behavior. */
|
|
119
|
+
instruction?: string | InstructionProvider;
|
|
120
|
+
/**
|
|
121
|
+
* Instructions for all the agents in the entire agent tree.
|
|
122
|
+
*
|
|
123
|
+
* ONLY the globalInstruction in root agent will take effect.
|
|
124
|
+
*
|
|
125
|
+
* For example: use globalInstruction to make all agents have a stable
|
|
126
|
+
* identity or personality.
|
|
127
|
+
*/
|
|
128
|
+
globalInstruction?: string | InstructionProvider;
|
|
129
|
+
/** Tools available to this agent. */
|
|
130
|
+
tools?: ToolUnion[];
|
|
131
|
+
/**
|
|
132
|
+
* The additional content generation configurations.
|
|
133
|
+
*
|
|
134
|
+
* NOTE: not all fields are usable, e.g. tools must be configured via
|
|
135
|
+
* `tools`, thinking_config must be configured via `planner` in LlmAgent.
|
|
136
|
+
*
|
|
137
|
+
* For example: use this config to adjust model temperature, configure safety
|
|
138
|
+
* settings, etc.
|
|
139
|
+
*/
|
|
140
|
+
generateContentConfig?: GenerateContentConfig;
|
|
141
|
+
/**
|
|
142
|
+
* Disallows LLM-controlled transferring to the parent agent.
|
|
143
|
+
*
|
|
144
|
+
* NOTE: Setting this as True also prevents this agent to continue reply to
|
|
145
|
+
* the end-user. This behavior prevents one-way transfer, in which end-user
|
|
146
|
+
* may be stuck with one agent that cannot transfer to other agents in the
|
|
147
|
+
* agent tree.
|
|
148
|
+
*/
|
|
149
|
+
disallowTransferToParent?: boolean;
|
|
150
|
+
/** Disallows LLM-controlled transferring to the peer agents. */
|
|
151
|
+
disallowTransferToPeers?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Controls content inclusion in model requests.
|
|
154
|
+
*
|
|
155
|
+
* Options:
|
|
156
|
+
* default: Model receives relevant conversation history
|
|
157
|
+
* none: Model receives no prior history, operates solely on current
|
|
158
|
+
* instruction and input
|
|
159
|
+
*/
|
|
160
|
+
includeContents?: 'default' | 'none';
|
|
161
|
+
/** The input schema when agent is used as a tool. */
|
|
162
|
+
inputSchema?: Schema;
|
|
163
|
+
/**
|
|
164
|
+
* The output schema when agent replies.
|
|
165
|
+
*
|
|
166
|
+
* NOTE:
|
|
167
|
+
* When this is set, agent can ONLY reply and CANNOT use any tools, such as
|
|
168
|
+
* function tools, RAGs, agent transfer, etc.
|
|
169
|
+
*/
|
|
170
|
+
outputSchema?: Schema;
|
|
171
|
+
/**
|
|
172
|
+
* The key in session state to store the output of the agent.
|
|
173
|
+
*
|
|
174
|
+
* Typically use cases:
|
|
175
|
+
* - Extracts agent reply for later use, such as in tools, callbacks, etc.
|
|
176
|
+
* - Connects agents to coordinate with each other.
|
|
177
|
+
*/
|
|
178
|
+
outputKey?: string;
|
|
179
|
+
/**
|
|
180
|
+
* Callbacks to be called before calling the LLM.
|
|
181
|
+
*/
|
|
182
|
+
beforeModelCallback?: BeforeModelCallback;
|
|
183
|
+
/**
|
|
184
|
+
* Callbacks to be called after calling the LLM.
|
|
185
|
+
*/
|
|
186
|
+
afterModelCallback?: AfterModelCallback;
|
|
187
|
+
/**
|
|
188
|
+
* Callbacks to be called before calling the tool.
|
|
189
|
+
*/
|
|
190
|
+
beforeToolCallback?: BeforeToolCallback;
|
|
191
|
+
/**
|
|
192
|
+
* Callbacks to be called after calling the tool.
|
|
193
|
+
*/
|
|
194
|
+
afterToolCallback?: AfterToolCallback;
|
|
195
|
+
/**
|
|
196
|
+
* Processors to run before the LLM request is sent.
|
|
197
|
+
*/
|
|
198
|
+
requestProcessors?: BaseLlmRequestProcessor[];
|
|
199
|
+
/**
|
|
200
|
+
* Processors to run after the LLM response is received.
|
|
201
|
+
*/
|
|
202
|
+
responseProcessors?: BaseLlmResponseProcessor[];
|
|
203
|
+
}
|
|
204
|
+
declare class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
205
|
+
/** Handles tool confirmation information to build the LLM request. */
|
|
206
|
+
runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
|
|
207
|
+
}
|
|
208
|
+
export declare const REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR: RequestConfirmationLlmRequestProcessor;
|
|
209
|
+
/**
|
|
210
|
+
* An agent that uses a large language model to generate responses.
|
|
211
|
+
*/
|
|
212
|
+
export declare class LlmAgent extends BaseAgent {
|
|
213
|
+
model?: string | BaseLlm;
|
|
214
|
+
instruction: string | InstructionProvider;
|
|
215
|
+
globalInstruction: string | InstructionProvider;
|
|
216
|
+
tools: ToolUnion[];
|
|
217
|
+
generateContentConfig?: GenerateContentConfig;
|
|
218
|
+
disallowTransferToParent: boolean;
|
|
219
|
+
disallowTransferToPeers: boolean;
|
|
220
|
+
includeContents: 'default' | 'none';
|
|
221
|
+
inputSchema?: Schema;
|
|
222
|
+
outputSchema?: Schema;
|
|
223
|
+
outputKey?: string;
|
|
224
|
+
beforeModelCallback?: BeforeModelCallback;
|
|
225
|
+
afterModelCallback?: AfterModelCallback;
|
|
226
|
+
beforeToolCallback?: BeforeToolCallback;
|
|
227
|
+
afterToolCallback?: AfterToolCallback;
|
|
228
|
+
requestProcessors: BaseLlmRequestProcessor[];
|
|
229
|
+
responseProcessors: BaseLlmResponseProcessor[];
|
|
230
|
+
constructor(config: LlmAgentConfig);
|
|
231
|
+
/**
|
|
232
|
+
* The resolved BaseLlm instance.
|
|
233
|
+
*
|
|
234
|
+
* When not set, the agent will inherit the model from its ancestor.
|
|
235
|
+
*/
|
|
236
|
+
get canonicalModel(): BaseLlm;
|
|
237
|
+
/**
|
|
238
|
+
* The resolved self.instruction field to construct instruction for this
|
|
239
|
+
* agent.
|
|
240
|
+
*
|
|
241
|
+
* This method is only for use by Agent Development Kit.
|
|
242
|
+
* @param context The context to retrieve the session state.
|
|
243
|
+
* @returns The resolved self.instruction field.
|
|
244
|
+
*/
|
|
245
|
+
canonicalInstruction(context: ReadonlyContext): Promise<{
|
|
246
|
+
instruction: string;
|
|
247
|
+
requireStateInjection: boolean;
|
|
248
|
+
}>;
|
|
249
|
+
/**
|
|
250
|
+
* The resolved self.instruction field to construct global instruction.
|
|
251
|
+
*
|
|
252
|
+
* This method is only for use by Agent Development Kit.
|
|
253
|
+
* @param context The context to retrieve the session state.
|
|
254
|
+
* @returns The resolved self.global_instruction field.
|
|
255
|
+
*/
|
|
256
|
+
canonicalGlobalInstruction(context: ReadonlyContext): Promise<{
|
|
257
|
+
instruction: string;
|
|
258
|
+
requireStateInjection: boolean;
|
|
259
|
+
}>;
|
|
260
|
+
/**
|
|
261
|
+
* The resolved self.tools field as a list of BaseTool based on the context.
|
|
262
|
+
*
|
|
263
|
+
* This method is only for use by Agent Development Kit.
|
|
264
|
+
*/
|
|
265
|
+
canonicalTools(context?: ReadonlyContext): Promise<BaseTool[]>;
|
|
266
|
+
/**
|
|
267
|
+
* Normalizes a callback or an array of callbacks into an array of callbacks.
|
|
268
|
+
*
|
|
269
|
+
* @param callback The callback or an array of callbacks.
|
|
270
|
+
* @returns An array of callbacks.
|
|
271
|
+
*/
|
|
272
|
+
private static normalizeCallbackArray;
|
|
273
|
+
/**
|
|
274
|
+
* The resolved self.before_model_callback field as a list of
|
|
275
|
+
* SingleBeforeModelCallback.
|
|
276
|
+
*
|
|
277
|
+
* This method is only for use by Agent Development Kit.
|
|
278
|
+
*/
|
|
279
|
+
get canonicalBeforeModelCallbacks(): SingleBeforeModelCallback[];
|
|
280
|
+
/**
|
|
281
|
+
* The resolved self.after_model_callback field as a list of
|
|
282
|
+
* SingleAfterModelCallback.
|
|
283
|
+
*
|
|
284
|
+
* This method is only for use by Agent Development Kit.
|
|
285
|
+
*/
|
|
286
|
+
get canonicalAfterModelCallbacks(): SingleAfterModelCallback[];
|
|
287
|
+
/**
|
|
288
|
+
* The resolved self.before_tool_callback field as a list of
|
|
289
|
+
* BeforeToolCallback.
|
|
290
|
+
*
|
|
291
|
+
* This method is only for use by Agent Development Kit.
|
|
292
|
+
*/
|
|
293
|
+
get canonicalBeforeToolCallbacks(): SingleBeforeToolCallback[];
|
|
294
|
+
/**
|
|
295
|
+
* The resolved self.after_tool_callback field as a list of AfterToolCallback.
|
|
296
|
+
*
|
|
297
|
+
* This method is only for use by Agent Development Kit.
|
|
298
|
+
*/
|
|
299
|
+
get canonicalAfterToolCallbacks(): SingleAfterToolCallback[];
|
|
300
|
+
/**
|
|
301
|
+
* Saves the agent's final response to the session state if configured.
|
|
302
|
+
*
|
|
303
|
+
* It extracts the text content from the final response event, optionally
|
|
304
|
+
* parses it as JSON based on the output schema, and stores the result in the
|
|
305
|
+
* session state using the specified output key.
|
|
306
|
+
*
|
|
307
|
+
* @param event The event to process.
|
|
308
|
+
*/
|
|
309
|
+
private maybeSaveOutputToState;
|
|
310
|
+
protected runAsyncImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
|
|
311
|
+
protected runLiveImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
|
|
312
|
+
private runLiveFlow;
|
|
313
|
+
private runOneStepAsync;
|
|
314
|
+
private postprocess;
|
|
315
|
+
/**
|
|
316
|
+
* Retrieves an agent from the agent tree by its name.
|
|
317
|
+
*
|
|
318
|
+
* Performing a depth-first search to locate the agent with the given name.
|
|
319
|
+
* - Starts searching from the root agent of the current invocation context.
|
|
320
|
+
* - Traverses down the agent tree to find the specified agent.
|
|
321
|
+
*
|
|
322
|
+
* @param invocationContext The current invocation context.
|
|
323
|
+
* @param agentName The name of the agent to retrieve.
|
|
324
|
+
* @returns The agent with the given name.
|
|
325
|
+
* @throws Error if the agent is not found.
|
|
326
|
+
*/
|
|
327
|
+
private getAgentByName;
|
|
328
|
+
private callLlmAsync;
|
|
329
|
+
private handleBeforeModelCallback;
|
|
330
|
+
private handleAfterModelCallback;
|
|
331
|
+
private runAndHandleError;
|
|
332
|
+
}
|
|
333
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Event } from '../events/event.js';
|
|
7
|
+
import { BaseAgent, BaseAgentConfig } from './base_agent.js';
|
|
8
|
+
import { InvocationContext } from './invocation_context.js';
|
|
9
|
+
/**
|
|
10
|
+
* The configuration options for creating a loop agent.
|
|
11
|
+
*/
|
|
12
|
+
export interface LoopAgentConfig extends BaseAgentConfig {
|
|
13
|
+
/**
|
|
14
|
+
* The maximum number of iterations the loop agent will run.
|
|
15
|
+
*
|
|
16
|
+
* If not provided, the loop agent will run indefinitely.
|
|
17
|
+
*/
|
|
18
|
+
maxIterations?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A shell agent that run its sub-agents in a loop.
|
|
22
|
+
*
|
|
23
|
+
* When sub-agent generates an event with escalate or max_iterations are
|
|
24
|
+
* reached, the loop agent will stop.
|
|
25
|
+
*/
|
|
26
|
+
export declare class LoopAgent extends BaseAgent {
|
|
27
|
+
private readonly maxIterations;
|
|
28
|
+
constructor(config: LoopAgentConfig);
|
|
29
|
+
protected runAsyncImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
|
|
30
|
+
protected runLiveImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Event } from '../events/event.js';
|
|
7
|
+
import { BaseAgent } from './base_agent.js';
|
|
8
|
+
import { InvocationContext } from './invocation_context.js';
|
|
9
|
+
/**
|
|
10
|
+
* A shell agent that run its sub-agents in parallel in isolated manner.
|
|
11
|
+
*
|
|
12
|
+
* This approach is beneficial for scenarios requiring multiple perspectives or
|
|
13
|
+
* attempts on a single task, such as:
|
|
14
|
+
*
|
|
15
|
+
* - Running different algorithms simultaneously.
|
|
16
|
+
* - Generating multiple responses for review by a subsequent evaluation agent.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ParallelAgent extends BaseAgent {
|
|
19
|
+
protected runAsyncImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
|
|
20
|
+
protected runLiveImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Content } from '@google/genai';
|
|
7
|
+
import { State } from '../sessions/state.js';
|
|
8
|
+
import { InvocationContext } from './invocation_context.js';
|
|
9
|
+
/**
|
|
10
|
+
* A readonly context represents the data of a single invocation of an agent.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ReadonlyContext {
|
|
13
|
+
readonly invocationContext: InvocationContext;
|
|
14
|
+
constructor(invocationContext: InvocationContext);
|
|
15
|
+
/**
|
|
16
|
+
* The user content that started this invocation.
|
|
17
|
+
*/
|
|
18
|
+
get userContent(): Content | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The current invocation id.
|
|
21
|
+
*/
|
|
22
|
+
get invocationId(): string;
|
|
23
|
+
/**
|
|
24
|
+
* The current agent name.
|
|
25
|
+
*/
|
|
26
|
+
get agentName(): string;
|
|
27
|
+
/**
|
|
28
|
+
* The state of the current session.
|
|
29
|
+
*/
|
|
30
|
+
get state(): Readonly<State>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { AudioTranscriptionConfig, Modality, ProactivityConfig, RealtimeInputConfig, SpeechConfig } from '@google/genai';
|
|
7
|
+
/**
|
|
8
|
+
* The streaming mode for the run config.
|
|
9
|
+
*/
|
|
10
|
+
export declare enum StreamingMode {
|
|
11
|
+
NONE = "none",
|
|
12
|
+
SSE = "sse",
|
|
13
|
+
BIDI = "bidi"
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Configs for runtime behavior of agents.
|
|
17
|
+
*/
|
|
18
|
+
export declare class RunConfig {
|
|
19
|
+
/**
|
|
20
|
+
* Speech configuration for the live agent.
|
|
21
|
+
*/
|
|
22
|
+
speechConfig?: SpeechConfig;
|
|
23
|
+
/**
|
|
24
|
+
* The output modalities. If not set, it's default to AUDIO.
|
|
25
|
+
*/
|
|
26
|
+
responseModalities?: Modality[];
|
|
27
|
+
/**
|
|
28
|
+
* Whether or not to save the input blobs as artifacts.
|
|
29
|
+
*/
|
|
30
|
+
saveInputBlobsAsArtifacts: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to support CFC (Compositional Function Calling). Only applicable
|
|
33
|
+
* for StreamingMode.SSE. If it's true. the LIVE API will be invoked. Since
|
|
34
|
+
* only LIVE API supports CFC
|
|
35
|
+
*
|
|
36
|
+
* WARNING: This feature is **experimental** and its API or behavior may
|
|
37
|
+
* change in future releases.
|
|
38
|
+
*/
|
|
39
|
+
supportCfc: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Streaming mode, None or StreamingMode.SSE or StreamingMode.BIDI.
|
|
42
|
+
*/
|
|
43
|
+
streamingMode: StreamingMode;
|
|
44
|
+
/**
|
|
45
|
+
* Output audio transcription config.
|
|
46
|
+
*/
|
|
47
|
+
outputAudioTranscription?: AudioTranscriptionConfig;
|
|
48
|
+
/**
|
|
49
|
+
* Input transcription for live agents with audio input from user.
|
|
50
|
+
*/
|
|
51
|
+
inputAudioTranscription?: AudioTranscriptionConfig;
|
|
52
|
+
/**
|
|
53
|
+
* If enabled, the model will detect emotions and adapt its responses
|
|
54
|
+
* accordingly.
|
|
55
|
+
*/
|
|
56
|
+
enableAffectiveDialog: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Configures the proactivity of the model. This allows the model to respond
|
|
59
|
+
* proactively to the input and to ignore irrelevant input.
|
|
60
|
+
*/
|
|
61
|
+
proactivity?: ProactivityConfig;
|
|
62
|
+
/**
|
|
63
|
+
* Realtime input config for live agents with audio input from user.
|
|
64
|
+
*/
|
|
65
|
+
realtimeInputConfig?: RealtimeInputConfig;
|
|
66
|
+
/**
|
|
67
|
+
* A limit on the total number of llm calls for a given run.
|
|
68
|
+
*
|
|
69
|
+
* Valid Values:
|
|
70
|
+
* - More than 0 and less than sys.maxsize: The bound on the number of llm
|
|
71
|
+
* calls is enforced, if the value is set in this range.
|
|
72
|
+
* - Less than or equal to 0: This allows for unbounded number of llm calls.
|
|
73
|
+
*/
|
|
74
|
+
maxLlmCalls: number;
|
|
75
|
+
constructor(params?: Partial<RunConfig>);
|
|
76
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Event } from '../events/event.js';
|
|
7
|
+
import { BaseAgent } from './base_agent.js';
|
|
8
|
+
import { InvocationContext } from './invocation_context.js';
|
|
9
|
+
/**
|
|
10
|
+
* A shell agent that runs its sub-agents in a sequential order.
|
|
11
|
+
*/
|
|
12
|
+
export declare class SequentialAgent extends BaseAgent {
|
|
13
|
+
protected runAsyncImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
|
|
14
|
+
/**
|
|
15
|
+
* Implementation for live SequentialAgent.
|
|
16
|
+
*
|
|
17
|
+
* Compared to the non-live case, live agents process a continuous stream of
|
|
18
|
+
* audio or video, so there is no way to tell if it's finished and should pass
|
|
19
|
+
* to the next agent or not. So we introduce a task_completed() function so
|
|
20
|
+
* the model can call this function to signal that it's finished the task and
|
|
21
|
+
* we can move on to the next agent.
|
|
22
|
+
*
|
|
23
|
+
* @param context: The invocation context of the agent.
|
|
24
|
+
*/
|
|
25
|
+
protected runLiveImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Blob, Content } from '@google/genai';
|
|
7
|
+
/**
|
|
8
|
+
* Store the data that can be used for transcription.
|
|
9
|
+
*/
|
|
10
|
+
export interface TranscriptionEntry {
|
|
11
|
+
/**
|
|
12
|
+
* The role that created this data, typically "user" or "model". For function
|
|
13
|
+
* call, this is undefined.
|
|
14
|
+
*/
|
|
15
|
+
role?: string;
|
|
16
|
+
data: Blob | Content;
|
|
17
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Part } from '@google/genai';
|
|
7
|
+
/**
|
|
8
|
+
* The parameters for `saveArtifact`.
|
|
9
|
+
*/
|
|
10
|
+
export interface SaveArtifactRequest {
|
|
11
|
+
/** The app name. */
|
|
12
|
+
appName: string;
|
|
13
|
+
/** The user ID. */
|
|
14
|
+
userId: string;
|
|
15
|
+
/** The session ID. */
|
|
16
|
+
sessionId: string;
|
|
17
|
+
/** The filename of the artifact. */
|
|
18
|
+
filename: string;
|
|
19
|
+
/** The artifact to save. */
|
|
20
|
+
artifact: Part;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The parameters for `loadArtifact`.
|
|
24
|
+
*/
|
|
25
|
+
export interface LoadArtifactRequest {
|
|
26
|
+
/** The app name. */
|
|
27
|
+
appName: string;
|
|
28
|
+
/** The user ID. */
|
|
29
|
+
userId: string;
|
|
30
|
+
/** The session ID. */
|
|
31
|
+
sessionId: string;
|
|
32
|
+
/** The filename of the artifact. */
|
|
33
|
+
filename: string;
|
|
34
|
+
/**
|
|
35
|
+
* The version of the artifact to load. If not provided, the latest version
|
|
36
|
+
* of the artifact is loaded.
|
|
37
|
+
*/
|
|
38
|
+
version?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The parameters for `listArtifactKeys`.
|
|
42
|
+
*/
|
|
43
|
+
export interface ListArtifactKeysRequest {
|
|
44
|
+
/** The app name. */
|
|
45
|
+
appName: string;
|
|
46
|
+
/** The user ID. */
|
|
47
|
+
userId: string;
|
|
48
|
+
/** The session ID. */
|
|
49
|
+
sessionId: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The parameters for `deleteArtifact`.
|
|
53
|
+
*/
|
|
54
|
+
export interface DeleteArtifactRequest {
|
|
55
|
+
/** The app name. */
|
|
56
|
+
appName: string;
|
|
57
|
+
/** The user ID. */
|
|
58
|
+
userId: string;
|
|
59
|
+
/** The session ID. */
|
|
60
|
+
sessionId: string;
|
|
61
|
+
/** The filename of the artifact. */
|
|
62
|
+
filename: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The parameters for `listVersions`.
|
|
66
|
+
*/
|
|
67
|
+
export interface ListVersionsRequest {
|
|
68
|
+
/** The app name. */
|
|
69
|
+
appName: string;
|
|
70
|
+
/** The user ID. */
|
|
71
|
+
userId: string;
|
|
72
|
+
/** The session ID. */
|
|
73
|
+
sessionId: string;
|
|
74
|
+
/** The filename of the artifact. */
|
|
75
|
+
filename: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Interface for artifact services.
|
|
79
|
+
*/
|
|
80
|
+
export interface BaseArtifactService {
|
|
81
|
+
/**
|
|
82
|
+
* Saves an artifact to the artifact service storage.
|
|
83
|
+
*
|
|
84
|
+
* The artifact is a file identified by the app name, user ID, session ID, and
|
|
85
|
+
* filename. After saving the artifact, a revision ID is returned to identify
|
|
86
|
+
* the artifact version.
|
|
87
|
+
*
|
|
88
|
+
* @param request The request to save an artifact.
|
|
89
|
+
* @return A promise that resolves to The revision ID. The first version of
|
|
90
|
+
* the artifact has a revision ID of 0. This is incremented by 1 after each
|
|
91
|
+
* successful save.
|
|
92
|
+
*/
|
|
93
|
+
saveArtifact(request: SaveArtifactRequest): Promise<number>;
|
|
94
|
+
/**
|
|
95
|
+
* Gets an artifact from the artifact service storage.
|
|
96
|
+
*
|
|
97
|
+
* The artifact is a file identified by the app name, user ID, session ID, and
|
|
98
|
+
* filename.
|
|
99
|
+
*
|
|
100
|
+
* @param request The request to load an artifact.
|
|
101
|
+
* @return A promise that resolves to the artifact or undefined if not found.
|
|
102
|
+
*/
|
|
103
|
+
loadArtifact(request: LoadArtifactRequest): Promise<Part | undefined>;
|
|
104
|
+
/**
|
|
105
|
+
* Lists all the artifact filenames within a session.
|
|
106
|
+
*
|
|
107
|
+
* @param request The request to list artifact keys.
|
|
108
|
+
* @return A promise that resolves to a list of all artifact filenames within
|
|
109
|
+
* a session.
|
|
110
|
+
*/
|
|
111
|
+
listArtifactKeys(request: ListArtifactKeysRequest): Promise<string[]>;
|
|
112
|
+
/**
|
|
113
|
+
* Deletes an artifact.
|
|
114
|
+
*
|
|
115
|
+
* @param request The request to delete an artifact.
|
|
116
|
+
* @return A promise that resolves when the artifact is deleted.
|
|
117
|
+
*/
|
|
118
|
+
deleteArtifact(request: DeleteArtifactRequest): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Lists all versions of an artifact.
|
|
121
|
+
*
|
|
122
|
+
* @param request The request to list versions.
|
|
123
|
+
* @return A promise that resolves to a list of all available versions of the
|
|
124
|
+
* artifact.
|
|
125
|
+
*/
|
|
126
|
+
listVersions(request: ListVersionsRequest): Promise<number[]>;
|
|
127
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Part } from '@google/genai';
|
|
7
|
+
import { BaseArtifactService, DeleteArtifactRequest, ListArtifactKeysRequest, ListVersionsRequest, LoadArtifactRequest, SaveArtifactRequest } from './base_artifact_service.js';
|
|
8
|
+
/**
|
|
9
|
+
* An in-memory implementation of the ArtifactService.
|
|
10
|
+
*/
|
|
11
|
+
export declare class InMemoryArtifactService implements BaseArtifactService {
|
|
12
|
+
private readonly artifacts;
|
|
13
|
+
saveArtifact({ appName, userId, sessionId, filename, artifact, }: SaveArtifactRequest): Promise<number>;
|
|
14
|
+
loadArtifact({ appName, userId, sessionId, filename, version, }: LoadArtifactRequest): Promise<Part | undefined>;
|
|
15
|
+
listArtifactKeys({ appName, userId, sessionId }: ListArtifactKeysRequest): Promise<string[]>;
|
|
16
|
+
deleteArtifact({ appName, userId, sessionId, filename }: DeleteArtifactRequest): Promise<void>;
|
|
17
|
+
listVersions({ appName, userId, sessionId, filename }: ListVersionsRequest): Promise<number[]>;
|
|
18
|
+
}
|