@google/adk 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/a2a/agent_to_a2a.js +18 -2
- package/dist/cjs/a2a/event_converter_utils.js +8 -4
- package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
- package/dist/cjs/agents/active_streaming_tool.js +6 -1
- package/dist/cjs/agents/base_agent.js +39 -0
- package/dist/cjs/agents/context.js +1 -11
- package/dist/cjs/agents/functions.js +39 -35
- package/dist/cjs/agents/instructions.js +23 -5
- package/dist/cjs/agents/invocation_context.js +2 -5
- package/dist/cjs/agents/llm_agent.js +10 -7
- package/dist/cjs/agents/loop_agent.js +15 -3
- package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/cjs/agents/processors/content_processor_utils.js +18 -4
- 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/agents/routed_agent.js +31 -0
- package/dist/cjs/agents/run_config.js +3 -2
- 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 +12 -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 +76 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
- package/dist/cjs/context/anchored_context_compactor.js +127 -0
- package/dist/cjs/context/compaction_utils.js +52 -0
- package/dist/cjs/context/token_based_context_compactor.js +52 -33
- package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
- package/dist/cjs/events/compacted_event.js +9 -3
- package/dist/cjs/events/event.js +52 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- 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/plugins/global_instruction_plugin.js +97 -0
- package/dist/cjs/runner/in_memory_runner.js +13 -2
- package/dist/cjs/runner/runner.js +143 -83
- 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/enterprise_web_search_tool.js +81 -0
- package/dist/cjs/tools/example_tool.js +68 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
- package/dist/cjs/tools/load_web_page.js +250 -0
- package/dist/cjs/tools/mcp/load_mcp_resource_tool.js +140 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +63 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- package/dist/cjs/tools/skill/run_skill_inline_script_tool.js +54 -4
- package/dist/cjs/tools/skill/skill_toolset.js +4 -2
- package/dist/cjs/utils/async_hooks_shim.js +52 -0
- package/dist/cjs/utils/branch_trie.js +41 -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 +15 -9
- package/dist/cjs/utils/task.js +62 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/agent_to_a2a.js +18 -2
- package/dist/esm/a2a/event_converter_utils.js +8 -4
- package/dist/esm/a2a/metadata_converter_utils.js +1 -1
- package/dist/esm/agents/active_streaming_tool.js +6 -1
- package/dist/esm/agents/base_agent.js +39 -0
- package/dist/esm/agents/context.js +1 -11
- package/dist/esm/agents/functions.js +43 -32
- package/dist/esm/agents/instructions.js +23 -5
- package/dist/esm/agents/invocation_context.js +2 -5
- package/dist/esm/agents/llm_agent.js +12 -9
- package/dist/esm/agents/loop_agent.js +15 -3
- package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/esm/agents/processors/content_processor_utils.js +16 -3
- 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/agents/routed_agent.js +31 -0
- package/dist/esm/agents/run_config.js +3 -2
- 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 +12 -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 +67 -3
- package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
- package/dist/esm/context/anchored_context_compactor.js +99 -0
- package/dist/esm/context/compaction_utils.js +27 -0
- package/dist/esm/context/token_based_context_compactor.js +52 -33
- package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/esm/events/compacted_event.js +7 -2
- package/dist/esm/events/event.js +46 -0
- package/dist/esm/index.js +6 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- 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/plugins/global_instruction_plugin.js +69 -0
- package/dist/esm/runner/in_memory_runner.js +13 -2
- package/dist/esm/runner/runner.js +141 -84
- 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/enterprise_web_search_tool.js +55 -0
- package/dist/esm/tools/example_tool.js +42 -0
- package/dist/esm/tools/forwarding_artifact_service.js +16 -28
- package/dist/esm/tools/load_web_page.js +221 -0
- package/dist/esm/tools/mcp/load_mcp_resource_tool.js +114 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +63 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- package/dist/esm/tools/skill/run_skill_inline_script_tool.js +53 -4
- package/dist/esm/tools/skill/skill_toolset.js +4 -2
- package/dist/esm/utils/async_hooks_shim.js +24 -0
- package/dist/esm/utils/branch_trie.js +13 -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 +11 -5
- package/dist/esm/utils/task.js +34 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +5 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +38 -0
- package/dist/types/agents/active_streaming_tool.d.ts +3 -4
- package/dist/types/agents/base_agent.d.ts +29 -1
- package/dist/types/agents/functions.d.ts +12 -17
- package/dist/types/agents/invocation_context.d.ts +7 -3
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/loop_agent.d.ts +2 -2
- 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/agents/routed_agent.d.ts +24 -1
- package/dist/types/agents/run_config.d.ts +1 -1
- 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 +29 -5
- package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
- package/dist/types/context/anchored_context_compactor.d.ts +35 -0
- package/dist/types/context/base_context_compactor.d.ts +3 -0
- package/dist/types/context/compaction_utils.d.ts +15 -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/compacted_event.d.ts +10 -0
- package/dist/types/events/event.d.ts +21 -0
- package/dist/types/index.d.ts +3 -2
- 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/plugins/global_instruction_plugin.d.ts +38 -0
- package/dist/types/runner/in_memory_runner.d.ts +7 -1
- package/dist/types/runner/runner.d.ts +44 -10
- 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/enterprise_web_search_tool.d.ts +26 -0
- package/dist/types/tools/example_tool.d.ts +21 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +3 -2
- package/dist/types/tools/load_web_page.d.ts +33 -0
- package/dist/types/tools/mcp/load_mcp_resource_tool.d.ts +26 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +27 -0
- package/dist/types/tools/skill/run_skill_inline_script_tool.d.ts +25 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +9 -0
- package/dist/types/utils/async_hooks_shim.d.ts +10 -0
- package/dist/types/utils/branch_trie.d.ts +14 -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/a2a/agent_to_a2a.js +18 -2
- package/dist/web/a2a/event_converter_utils.js +8 -4
- package/dist/web/a2a/metadata_converter_utils.js +1 -1
- package/dist/web/agents/active_streaming_tool.js +6 -1
- package/dist/web/agents/base_agent.js +39 -0
- package/dist/web/agents/context.js +1 -11
- package/dist/web/agents/functions.js +43 -32
- package/dist/web/agents/instructions.js +23 -5
- package/dist/web/agents/invocation_context.js +2 -5
- package/dist/web/agents/llm_agent.js +12 -9
- package/dist/web/agents/loop_agent.js +27 -3
- package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/web/agents/processors/content_processor_utils.js +16 -3
- 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/agents/routed_agent.js +31 -0
- package/dist/web/agents/run_config.js +8 -3
- 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 +12 -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 +67 -3
- package/dist/web/context/agent_controlled_context_compactor.js +81 -0
- package/dist/web/context/anchored_context_compactor.js +117 -0
- package/dist/web/context/compaction_utils.js +27 -0
- package/dist/web/context/token_based_context_compactor.js +52 -33
- package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/web/events/compacted_event.js +7 -2
- package/dist/web/events/event.js +44 -0
- package/dist/web/index.js +6 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- 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/plugins/global_instruction_plugin.js +67 -0
- package/dist/web/runner/in_memory_runner.js +13 -2
- package/dist/web/runner/runner.js +157 -84
- 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/enterprise_web_search_tool.js +55 -0
- package/dist/web/tools/example_tool.js +42 -0
- package/dist/web/tools/forwarding_artifact_service.js +16 -28
- package/dist/web/tools/load_web_page.js +221 -0
- package/dist/web/tools/mcp/load_mcp_resource_tool.js +107 -0
- package/dist/web/tools/mcp/mcp_toolset.js +63 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- package/dist/web/tools/skill/run_skill_inline_script_tool.js +51 -4
- package/dist/web/tools/skill/skill_toolset.js +4 -2
- package/dist/web/utils/async_hooks_shim.js +24 -0
- package/dist/web/utils/branch_trie.js +13 -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 +11 -5
- package/dist/web/utils/task.js +34 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -2
package/dist/web/common.js
CHANGED
|
@@ -8,7 +8,11 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
8
8
|
import { ActiveStreamingTool } from "./agents/active_streaming_tool.js";
|
|
9
9
|
import { BaseAgent, isBaseAgent } from "./agents/base_agent.js";
|
|
10
10
|
import { Context } from "./agents/context.js";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
findEventByFunctionCallId,
|
|
13
|
+
findMatchingFunctionCall,
|
|
14
|
+
functionsExportedForTestingOnly
|
|
15
|
+
} from "./agents/functions.js";
|
|
12
16
|
import { InvocationContext } from "./agents/invocation_context.js";
|
|
13
17
|
import { LiveRequestQueue } from "./agents/live_request_queue.js";
|
|
14
18
|
import { LlmAgent, LlmAgent as LlmAgent2, isLlmAgent } from "./agents/llm_agent.js";
|
|
@@ -24,10 +28,15 @@ import {
|
|
|
24
28
|
ContentRequestProcessor
|
|
25
29
|
} from "./agents/processors/content_request_processor.js";
|
|
26
30
|
import { ContextCompactorRequestProcessor } from "./agents/processors/context_compactor_request_processor.js";
|
|
31
|
+
import {
|
|
32
|
+
INTERACTIONS_REQUEST_PROCESSOR,
|
|
33
|
+
InteractionsRequestProcessor
|
|
34
|
+
} from "./agents/processors/interactions_request_processor.js";
|
|
27
35
|
import { ReadonlyContext } from "./agents/readonly_context.js";
|
|
28
36
|
import { RoutedAgent, isRoutedAgent } from "./agents/routed_agent.js";
|
|
29
37
|
import { StreamingMode } from "./agents/run_config.js";
|
|
30
38
|
import { SequentialAgent, isSequentialAgent } from "./agents/sequential_agent.js";
|
|
39
|
+
import { createResumabilityConfig } from "./apps/resumability_config.js";
|
|
31
40
|
import { InMemoryArtifactService } from "./artifacts/in_memory_artifact_service.js";
|
|
32
41
|
import { AuthCredentialTypes } from "./auth/auth_credential.js";
|
|
33
42
|
import { AuthHandler } from "./auth/auth_handler.js";
|
|
@@ -46,16 +55,23 @@ import {
|
|
|
46
55
|
CodeExecutionLanguage,
|
|
47
56
|
FileContentEncoding
|
|
48
57
|
} from "./code_executors/code_execution_utils.js";
|
|
58
|
+
import { AgentControlledContextCompactor } from "./context/agent_controlled_context_compactor.js";
|
|
59
|
+
import { AnchoredContextCompactor } from "./context/anchored_context_compactor.js";
|
|
49
60
|
import { LlmSummarizer } from "./context/summarizers/llm_summarizer.js";
|
|
50
61
|
import { TokenBasedContextCompactor } from "./context/token_based_context_compactor.js";
|
|
62
|
+
import { TrajectoryThoughtPruningCompactor } from "./context/trajectory_thought_pruning_compactor.js";
|
|
51
63
|
import { TruncatingContextCompactor } from "./context/truncating_context_compactor.js";
|
|
52
|
-
import { isCompactedEvent } from "./events/compacted_event.js";
|
|
64
|
+
import { isCompactedEvent, isScratchpadEvent } from "./events/compacted_event.js";
|
|
53
65
|
import {
|
|
54
66
|
createEvent,
|
|
67
|
+
generateClientFunctionCallId,
|
|
55
68
|
getFunctionCalls,
|
|
56
69
|
getFunctionResponses,
|
|
70
|
+
hasThoughts,
|
|
57
71
|
hasTrailingCodeExecutionResult,
|
|
58
72
|
isFinalResponse,
|
|
73
|
+
populateClientFunctionCallId,
|
|
74
|
+
pruneThoughts,
|
|
59
75
|
stringifyContent
|
|
60
76
|
} from "./events/event.js";
|
|
61
77
|
import { createEventActions } from "./events/event_actions.js";
|
|
@@ -72,6 +88,7 @@ import { Gemini, geminiInitParams } from "./models/google_llm.js";
|
|
|
72
88
|
import { LLMRegistry } from "./models/registry.js";
|
|
73
89
|
import { RoutedLlm } from "./models/routed_llm.js";
|
|
74
90
|
import { BasePlugin, ContextCompactionTrigger } from "./plugins/base_plugin.js";
|
|
91
|
+
import { GlobalInstructionPlugin } from "./plugins/global_instruction_plugin.js";
|
|
75
92
|
import { LoggingPlugin } from "./plugins/logging_plugin.js";
|
|
76
93
|
import { PluginManager } from "./plugins/plugin_manager.js";
|
|
77
94
|
import {
|
|
@@ -82,7 +99,13 @@ import {
|
|
|
82
99
|
getAskUserConfirmationFunctionCalls
|
|
83
100
|
} from "./plugins/security_plugin.js";
|
|
84
101
|
import { InMemoryRunner } from "./runner/in_memory_runner.js";
|
|
85
|
-
import {
|
|
102
|
+
import {
|
|
103
|
+
Runner,
|
|
104
|
+
determineAgentForResumption,
|
|
105
|
+
findEventByLastFunctionResponseId,
|
|
106
|
+
isRoutableLlmAgent,
|
|
107
|
+
isRunner
|
|
108
|
+
} from "./runner/runner.js";
|
|
86
109
|
import { BaseSessionService } from "./sessions/base_session_service.js";
|
|
87
110
|
import { InMemorySessionService } from "./sessions/in_memory_session_service.js";
|
|
88
111
|
import { createSession } from "./sessions/session.js";
|
|
@@ -90,6 +113,12 @@ import { State } from "./sessions/state.js";
|
|
|
90
113
|
import { AgentTool, isAgentTool } from "./tools/agent_tool.js";
|
|
91
114
|
import { BaseTool, isBaseTool } from "./tools/base_tool.js";
|
|
92
115
|
import { BaseToolset, isBaseToolset } from "./tools/base_toolset.js";
|
|
116
|
+
import { ConsolidateContextTool } from "./tools/consolidate_context_tool.js";
|
|
117
|
+
import {
|
|
118
|
+
ENTERPRISE_WEB_SEARCH,
|
|
119
|
+
EnterpriseWebSearchTool
|
|
120
|
+
} from "./tools/enterprise_web_search_tool.js";
|
|
121
|
+
import { ExampleTool } from "./tools/example_tool.js";
|
|
93
122
|
import { EXIT_LOOP, ExitLoopTool } from "./tools/exit_loop_tool.js";
|
|
94
123
|
import { FunctionTool, isFunctionTool } from "./tools/function_tool.js";
|
|
95
124
|
import {
|
|
@@ -102,6 +131,7 @@ import {
|
|
|
102
131
|
LoadArtifactsTool
|
|
103
132
|
} from "./tools/load_artifacts_tool.js";
|
|
104
133
|
import { LOAD_MEMORY, LoadMemoryTool } from "./tools/load_memory_tool.js";
|
|
134
|
+
import { LOAD_WEB_PAGE, loadWebPage } from "./tools/load_web_page.js";
|
|
105
135
|
import { LongRunningFunctionTool } from "./tools/long_running_tool.js";
|
|
106
136
|
import {
|
|
107
137
|
PRELOAD_MEMORY,
|
|
@@ -111,9 +141,11 @@ import { ToolConfirmation } from "./tools/tool_confirmation.js";
|
|
|
111
141
|
import { URL_CONTEXT, UrlContextTool } from "./tools/url_context_tool.js";
|
|
112
142
|
import { VertexAiSearchTool } from "./tools/vertex_ai_search_tool.js";
|
|
113
143
|
import { VertexRagRetrievalTool } from "./tools/vertex_rag_retrieval_tool.js";
|
|
144
|
+
import { getClientLabels, runWithClientLabel } from "./utils/client_labels.js";
|
|
114
145
|
import { LogLevel, getLogger, setLogLevel, setLogger } from "./utils/logger.js";
|
|
115
146
|
import { isGemini2OrAbove, isGemini3xFlashLive } from "./utils/model_name.js";
|
|
116
147
|
import { zodObjectToSchema } from "./utils/simple_zod_to_json.js";
|
|
148
|
+
import { Task } from "./utils/task.js";
|
|
117
149
|
import { GoogleLLMVariant } from "./utils/variant_utils.js";
|
|
118
150
|
import { version } from "./version.js";
|
|
119
151
|
import { GCPSkillRegistry } from "./skills/gcp_skill_registry.js";
|
|
@@ -128,6 +160,11 @@ import { LoadSkillResourceTool } from "./tools/skill/load_skill_resource_tool.js
|
|
|
128
160
|
import { LoadSkillTool } from "./tools/skill/load_skill_tool.js";
|
|
129
161
|
import { SearchSkillsTool } from "./tools/skill/search_skills_tool.js";
|
|
130
162
|
import { SkillToolset } from "./tools/skill/skill_toolset.js";
|
|
163
|
+
export * from "./artifacts/base_artifact_service.js";
|
|
164
|
+
export * from "./features/feature_registry.js";
|
|
165
|
+
export * from "./memory/base_memory_service.js";
|
|
166
|
+
export * from "./sessions/base_session_service.js";
|
|
167
|
+
export * from "./tools/base_tool.js";
|
|
131
168
|
import { OpenApiSpecParser } from "./tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js";
|
|
132
169
|
import { OperationParser } from "./tools/openapi_tool/openapi_spec_parser/operation_parser.js";
|
|
133
170
|
import { ToolAuthHandler } from "./tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js";
|
|
@@ -136,6 +173,7 @@ import {
|
|
|
136
173
|
RestApiTool,
|
|
137
174
|
createRestApiTool
|
|
138
175
|
} from "./tools/openapi_tool/rest_api_tool.js";
|
|
176
|
+
export * from "./apps/app.js";
|
|
139
177
|
export * from "./artifacts/base_artifact_service.js";
|
|
140
178
|
export * from "./features/feature_registry.js";
|
|
141
179
|
export * from "./memory/base_memory_service.js";
|
|
@@ -145,8 +183,10 @@ export {
|
|
|
145
183
|
AUTH_PREPROCESSOR,
|
|
146
184
|
ActiveStreamingTool,
|
|
147
185
|
LlmAgent as Agent,
|
|
186
|
+
AgentControlledContextCompactor,
|
|
148
187
|
AgentTool,
|
|
149
188
|
AgentTransferLlmRequestProcessor,
|
|
189
|
+
AnchoredContextCompactor,
|
|
150
190
|
ApigeeLlm,
|
|
151
191
|
AuthCredentialTypes,
|
|
152
192
|
AuthHandler,
|
|
@@ -165,14 +205,18 @@ export {
|
|
|
165
205
|
BuiltInCodeExecutor,
|
|
166
206
|
CONTENT_REQUEST_PROCESSOR,
|
|
167
207
|
CodeExecutionLanguage,
|
|
208
|
+
ConsolidateContextTool,
|
|
168
209
|
ContentRequestProcessor,
|
|
169
210
|
Context,
|
|
170
211
|
ContextCompactionTrigger,
|
|
171
212
|
ContextCompactorRequestProcessor,
|
|
172
213
|
CredentialExchangeError,
|
|
173
214
|
CredentialRefresherRegistry,
|
|
215
|
+
ENTERPRISE_WEB_SEARCH,
|
|
174
216
|
EXIT_LOOP,
|
|
217
|
+
EnterpriseWebSearchTool,
|
|
175
218
|
EventType,
|
|
219
|
+
ExampleTool,
|
|
176
220
|
ExitLoopTool,
|
|
177
221
|
FileContentEncoding,
|
|
178
222
|
FunctionTool,
|
|
@@ -180,19 +224,23 @@ export {
|
|
|
180
224
|
GOOGLE_MAPS_GROUNDING,
|
|
181
225
|
GOOGLE_SEARCH,
|
|
182
226
|
Gemini,
|
|
227
|
+
GlobalInstructionPlugin,
|
|
183
228
|
GoogleLLMVariant,
|
|
184
229
|
GoogleMapsGroundingTool,
|
|
185
230
|
GoogleSearchTool,
|
|
231
|
+
INTERACTIONS_REQUEST_PROCESSOR,
|
|
186
232
|
InMemoryArtifactService,
|
|
187
233
|
InMemoryCredentialService,
|
|
188
234
|
InMemoryMemoryService,
|
|
189
235
|
InMemoryPolicyEngine,
|
|
190
236
|
InMemoryRunner,
|
|
191
237
|
InMemorySessionService,
|
|
238
|
+
InteractionsRequestProcessor,
|
|
192
239
|
InvocationContext,
|
|
193
240
|
LLMRegistry,
|
|
194
241
|
LOAD_ARTIFACTS,
|
|
195
242
|
LOAD_MEMORY,
|
|
243
|
+
LOAD_WEB_PAGE,
|
|
196
244
|
ListSkillsTool,
|
|
197
245
|
LiveRequestQueue,
|
|
198
246
|
LlmAgent2 as LlmAgent,
|
|
@@ -229,9 +277,11 @@ export {
|
|
|
229
277
|
SkillToolset,
|
|
230
278
|
State,
|
|
231
279
|
StreamingMode,
|
|
280
|
+
Task,
|
|
232
281
|
TokenBasedContextCompactor,
|
|
233
282
|
ToolAuthHandler,
|
|
234
283
|
ToolConfirmation,
|
|
284
|
+
TrajectoryThoughtPruningCompactor,
|
|
235
285
|
TruncatingContextCompactor,
|
|
236
286
|
URL_CONTEXT,
|
|
237
287
|
UrlContextTool,
|
|
@@ -241,13 +291,21 @@ export {
|
|
|
241
291
|
createEvent,
|
|
242
292
|
createEventActions,
|
|
243
293
|
createRestApiTool,
|
|
294
|
+
createResumabilityConfig,
|
|
244
295
|
createSession,
|
|
296
|
+
determineAgentForResumption,
|
|
297
|
+
findEventByFunctionCallId,
|
|
298
|
+
findEventByLastFunctionResponseId,
|
|
299
|
+
findMatchingFunctionCall,
|
|
245
300
|
functionsExportedForTestingOnly,
|
|
246
301
|
geminiInitParams,
|
|
302
|
+
generateClientFunctionCallId,
|
|
247
303
|
getAskUserConfirmationFunctionCalls,
|
|
304
|
+
getClientLabels,
|
|
248
305
|
getFunctionCalls,
|
|
249
306
|
getFunctionResponses,
|
|
250
307
|
getLogger,
|
|
308
|
+
hasThoughts,
|
|
251
309
|
hasTrailingCodeExecutionResult,
|
|
252
310
|
isAgentTool,
|
|
253
311
|
isBaseAgent,
|
|
@@ -263,12 +321,18 @@ export {
|
|
|
263
321
|
isLlmAgent,
|
|
264
322
|
isLoopAgent,
|
|
265
323
|
isParallelAgent,
|
|
324
|
+
isRoutableLlmAgent,
|
|
266
325
|
isRoutedAgent,
|
|
267
326
|
isRunner,
|
|
327
|
+
isScratchpadEvent,
|
|
268
328
|
isSequentialAgent,
|
|
269
329
|
loadAllSkillsInDir,
|
|
270
330
|
loadSkillFromDir,
|
|
271
331
|
loadSkillFromZipBuffer,
|
|
332
|
+
loadWebPage,
|
|
333
|
+
populateClientFunctionCallId,
|
|
334
|
+
pruneThoughts,
|
|
335
|
+
runWithClientLabel,
|
|
272
336
|
setLogLevel,
|
|
273
337
|
setLogger,
|
|
274
338
|
stringifyContent,
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
import { isCompactedEvent } from "../events/compacted_event.js";
|
|
9
|
+
import { createEvent } from "../events/event.js";
|
|
10
|
+
import { ContextCompactionTrigger } from "../plugins/base_plugin.js";
|
|
11
|
+
class AgentControlledContextCompactor {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.trigger = ContextCompactionTrigger.AgentControlled;
|
|
14
|
+
this.summarizer = options.summarizer;
|
|
15
|
+
}
|
|
16
|
+
shouldCompact(invocationContext) {
|
|
17
|
+
return invocationContext.session.state["temp:consolidate_context"] === true;
|
|
18
|
+
}
|
|
19
|
+
async compact(invocationContext) {
|
|
20
|
+
const events = invocationContext.session.events;
|
|
21
|
+
const activeEvents = this.getActiveEvents(events);
|
|
22
|
+
const consolidateToolCallIndex = activeEvents.reduce(
|
|
23
|
+
(acc, e, idx) => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
return ((_b = (_a = e.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.some(
|
|
26
|
+
(p) => {
|
|
27
|
+
var _a2;
|
|
28
|
+
return ((_a2 = p.functionCall) == null ? void 0 : _a2.name) === "consolidate_context";
|
|
29
|
+
}
|
|
30
|
+
)) ? idx : acc;
|
|
31
|
+
},
|
|
32
|
+
-1
|
|
33
|
+
);
|
|
34
|
+
if (consolidateToolCallIndex <= 0) {
|
|
35
|
+
this.clearFlags(invocationContext);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const eventsToCompact = activeEvents.slice(0, consolidateToolCallIndex);
|
|
39
|
+
const detail = invocationContext.session.state["temp:consolidate_context_detail"];
|
|
40
|
+
if (detail) {
|
|
41
|
+
eventsToCompact.push(
|
|
42
|
+
createEvent({
|
|
43
|
+
author: "system",
|
|
44
|
+
timestamp: eventsToCompact[eventsToCompact.length - 1].timestamp,
|
|
45
|
+
content: {
|
|
46
|
+
role: "user",
|
|
47
|
+
parts: [
|
|
48
|
+
{
|
|
49
|
+
text: "CRITICAL INSTRUCTION FOR SUMMARY: Please summarize the history. Focus especially on: ".concat(detail)
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const compactedEvent = await this.summarizer.summarize(eventsToCompact);
|
|
58
|
+
invocationContext.session.events.push(compactedEvent);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error("Compaction failed:", error);
|
|
61
|
+
} finally {
|
|
62
|
+
this.clearFlags(invocationContext);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
clearFlags(invocationContext) {
|
|
66
|
+
delete invocationContext.session.state["temp:consolidate_context"];
|
|
67
|
+
delete invocationContext.session.state["temp:consolidate_context_detail"];
|
|
68
|
+
}
|
|
69
|
+
getActiveEvents(events) {
|
|
70
|
+
const latest = events.filter(isCompactedEvent).pop();
|
|
71
|
+
return latest ? [
|
|
72
|
+
latest,
|
|
73
|
+
...events.filter(
|
|
74
|
+
(e) => !isCompactedEvent(e) && e.timestamp > latest.endTime
|
|
75
|
+
)
|
|
76
|
+
] : events;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
AgentControlledContextCompactor
|
|
81
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
/**
|
|
23
|
+
* @license
|
|
24
|
+
* Copyright 2026 Google LLC
|
|
25
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
26
|
+
*/
|
|
27
|
+
import { isScratchpadEvent } from "../events/compacted_event.js";
|
|
28
|
+
import { getEventTokens } from "../events/event.js";
|
|
29
|
+
import { calculateRetainStartIndex } from "./compaction_utils.js";
|
|
30
|
+
class AnchoredContextCompactor {
|
|
31
|
+
constructor(options) {
|
|
32
|
+
this.tokenThreshold = options.tokenThreshold;
|
|
33
|
+
this.eventRetentionSize = options.eventRetentionSize;
|
|
34
|
+
this.summarizer = options.summarizer;
|
|
35
|
+
}
|
|
36
|
+
getActiveEvents(events) {
|
|
37
|
+
let latestScratchpad = void 0;
|
|
38
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
39
|
+
const e = events[i];
|
|
40
|
+
if (isScratchpadEvent(e)) {
|
|
41
|
+
latestScratchpad = e;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (!latestScratchpad) {
|
|
46
|
+
return events;
|
|
47
|
+
}
|
|
48
|
+
const activeRawEvents = events.filter(
|
|
49
|
+
(e) => e.timestamp > latestScratchpad.endTime && !isScratchpadEvent(e)
|
|
50
|
+
);
|
|
51
|
+
return [latestScratchpad, ...activeRawEvents];
|
|
52
|
+
}
|
|
53
|
+
shouldCompact(invocationContext) {
|
|
54
|
+
const events = invocationContext.session.events;
|
|
55
|
+
const activeEvents = this.getActiveEvents(events);
|
|
56
|
+
const hasScratchpad = activeEvents.length > 0 && isScratchpadEvent(activeEvents[0]);
|
|
57
|
+
const rawEvents = hasScratchpad ? activeEvents.slice(1) : activeEvents;
|
|
58
|
+
if (rawEvents.length <= this.eventRetentionSize) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const retainStartIndex = calculateRetainStartIndex(
|
|
62
|
+
rawEvents,
|
|
63
|
+
this.eventRetentionSize
|
|
64
|
+
);
|
|
65
|
+
if (retainStartIndex === 0) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const totalTokens = activeEvents.reduce(
|
|
69
|
+
(sum, event) => sum + getEventTokens(event),
|
|
70
|
+
0
|
|
71
|
+
);
|
|
72
|
+
return totalTokens > this.tokenThreshold;
|
|
73
|
+
}
|
|
74
|
+
async compact(invocationContext) {
|
|
75
|
+
const events = invocationContext.session.events;
|
|
76
|
+
const activeEvents = this.getActiveEvents(events);
|
|
77
|
+
const hasScratchpad = activeEvents.length > 0 && isScratchpadEvent(activeEvents[0]);
|
|
78
|
+
const rawEvents = hasScratchpad ? activeEvents.slice(1) : activeEvents;
|
|
79
|
+
if (rawEvents.length <= this.eventRetentionSize) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const retainStartIndex = calculateRetainStartIndex(
|
|
83
|
+
rawEvents,
|
|
84
|
+
this.eventRetentionSize
|
|
85
|
+
);
|
|
86
|
+
if (retainStartIndex === 0) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const rawEventsToCompact = rawEvents.slice(0, retainStartIndex);
|
|
90
|
+
let scratchpadEvent;
|
|
91
|
+
if (hasScratchpad) {
|
|
92
|
+
const existingScratchpad = activeEvents[0];
|
|
93
|
+
scratchpadEvent = await this.summarizer.summarize([
|
|
94
|
+
existingScratchpad,
|
|
95
|
+
...rawEventsToCompact
|
|
96
|
+
]);
|
|
97
|
+
} else {
|
|
98
|
+
scratchpadEvent = await this.summarizer.summarize(rawEventsToCompact);
|
|
99
|
+
}
|
|
100
|
+
const updatedScratchpad = __spreadProps(__spreadValues({}, scratchpadEvent), {
|
|
101
|
+
isScratchpad: true,
|
|
102
|
+
author: "system"
|
|
103
|
+
});
|
|
104
|
+
const inactiveEvents = events.slice(0, events.indexOf(activeEvents[0]));
|
|
105
|
+
const retainedRawEvents = rawEvents.slice(retainStartIndex);
|
|
106
|
+
const newEventsList = [
|
|
107
|
+
...inactiveEvents,
|
|
108
|
+
updatedScratchpad,
|
|
109
|
+
...retainedRawEvents
|
|
110
|
+
];
|
|
111
|
+
events.length = 0;
|
|
112
|
+
events.push(...newEventsList);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
AnchoredContextCompactor
|
|
117
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
getFunctionCalls,
|
|
10
|
+
getFunctionResponses
|
|
11
|
+
} from "../events/event.js";
|
|
12
|
+
function calculateRetainStartIndex(rawEvents, eventRetentionSize) {
|
|
13
|
+
let retainStartIndex = Math.max(0, rawEvents.length - eventRetentionSize);
|
|
14
|
+
while (retainStartIndex > 0) {
|
|
15
|
+
const eventToRetain = rawEvents[retainStartIndex];
|
|
16
|
+
const previousEvent = rawEvents[retainStartIndex - 1];
|
|
17
|
+
if (getFunctionResponses(eventToRetain).length > 0 && getFunctionCalls(previousEvent).length > 0) {
|
|
18
|
+
retainStartIndex--;
|
|
19
|
+
} else {
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return retainStartIndex;
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
calculateRetainStartIndex
|
|
27
|
+
};
|
|
@@ -5,8 +5,10 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
5
5
|
* Copyright 2026 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
+
import { getContents } from "../agents/processors/content_processor_utils.js";
|
|
8
9
|
import { isCompactedEvent } from "../events/compacted_event.js";
|
|
9
|
-
import {
|
|
10
|
+
import { calculateRetainStartIndex } from "./compaction_utils.js";
|
|
11
|
+
const CHARS_PER_TOKEN = 4;
|
|
10
12
|
class TokenBasedContextCompactor {
|
|
11
13
|
constructor(options) {
|
|
12
14
|
this.tokenThreshold = options.tokenThreshold;
|
|
@@ -38,11 +40,21 @@ class TokenBasedContextCompactor {
|
|
|
38
40
|
if (rawEvents.length <= this.eventRetentionSize) {
|
|
39
41
|
return false;
|
|
40
42
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
const retainStartIndex = calculateRetainStartIndex(
|
|
44
|
+
rawEvents,
|
|
45
|
+
this.eventRetentionSize
|
|
46
|
+
);
|
|
47
|
+
if (retainStartIndex === 0) {
|
|
48
|
+
return false;
|
|
44
49
|
}
|
|
45
|
-
|
|
50
|
+
const promptTokenCount = latestPromptTokenCount(
|
|
51
|
+
activeEvents,
|
|
52
|
+
invocationContext
|
|
53
|
+
);
|
|
54
|
+
if (promptTokenCount === void 0) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return promptTokenCount > this.tokenThreshold;
|
|
46
58
|
}
|
|
47
59
|
async compact(invocationContext) {
|
|
48
60
|
const events = invocationContext.session.events;
|
|
@@ -51,19 +63,10 @@ class TokenBasedContextCompactor {
|
|
|
51
63
|
if (rawEvents.length <= this.eventRetentionSize) {
|
|
52
64
|
return;
|
|
53
65
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
const retainStartIndex = calculateRetainStartIndex(
|
|
67
|
+
rawEvents,
|
|
68
|
+
this.eventRetentionSize
|
|
57
69
|
);
|
|
58
|
-
while (retainStartIndex > 0) {
|
|
59
|
-
const eventToRetain = rawEvents[retainStartIndex];
|
|
60
|
-
const previousEvent = rawEvents[retainStartIndex - 1];
|
|
61
|
-
if (hasFunctionResponse(eventToRetain) && hasFunctionCall(previousEvent)) {
|
|
62
|
-
retainStartIndex--;
|
|
63
|
-
} else {
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
70
|
if (retainStartIndex === 0) {
|
|
68
71
|
return;
|
|
69
72
|
}
|
|
@@ -82,25 +85,41 @@ class TokenBasedContextCompactor {
|
|
|
82
85
|
invocationContext.session.events.push(compactedEvent);
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
|
-
function
|
|
88
|
+
function latestPromptTokenCount(activeEvents, invocationContext) {
|
|
86
89
|
var _a;
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
for (let i = activeEvents.length - 1; i >= 0; i--) {
|
|
91
|
+
const count = (_a = activeEvents[i].usageMetadata) == null ? void 0 : _a.promptTokenCount;
|
|
92
|
+
if (count !== void 0) {
|
|
93
|
+
return count;
|
|
94
|
+
}
|
|
89
95
|
}
|
|
90
|
-
|
|
91
|
-
return Math.ceil(contentStr.length / 4);
|
|
96
|
+
return estimatePromptTokenCount(activeEvents, invocationContext);
|
|
92
97
|
}
|
|
93
|
-
function
|
|
94
|
-
var _a
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
(part
|
|
103
|
-
|
|
98
|
+
function estimatePromptTokenCount(activeEvents, invocationContext) {
|
|
99
|
+
var _a;
|
|
100
|
+
const contents = getContents(
|
|
101
|
+
activeEvents,
|
|
102
|
+
invocationContext.agent.name,
|
|
103
|
+
invocationContext.branch
|
|
104
|
+
);
|
|
105
|
+
let totalChars = 0;
|
|
106
|
+
for (const content of contents) {
|
|
107
|
+
for (const part of (_a = content.parts) != null ? _a : []) {
|
|
108
|
+
if (part.text) {
|
|
109
|
+
totalChars += part.text.length;
|
|
110
|
+
}
|
|
111
|
+
if (part.functionCall) {
|
|
112
|
+
totalChars += JSON.stringify(part.functionCall).length;
|
|
113
|
+
}
|
|
114
|
+
if (part.functionResponse) {
|
|
115
|
+
totalChars += JSON.stringify(part.functionResponse).length;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (totalChars <= 0) {
|
|
120
|
+
return void 0;
|
|
121
|
+
}
|
|
122
|
+
return Math.ceil(totalChars / CHARS_PER_TOKEN);
|
|
104
123
|
}
|
|
105
124
|
export {
|
|
106
125
|
TokenBasedContextCompactor
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
import { hasThoughts, pruneThoughts } from "../events/event.js";
|
|
9
|
+
class TrajectoryThoughtPruningCompactor {
|
|
10
|
+
constructor(options) {
|
|
11
|
+
if (options.eventRetentionSize < 0) {
|
|
12
|
+
throw new Error("eventRetentionSize must be a non-negative integer.");
|
|
13
|
+
}
|
|
14
|
+
this.eventRetentionSize = options.eventRetentionSize;
|
|
15
|
+
}
|
|
16
|
+
shouldCompact(invocationContext) {
|
|
17
|
+
const events = invocationContext.session.events;
|
|
18
|
+
if (events.length <= this.eventRetentionSize) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const olderEvents = events.slice(
|
|
22
|
+
0,
|
|
23
|
+
events.length - this.eventRetentionSize
|
|
24
|
+
);
|
|
25
|
+
return olderEvents.some((event) => hasThoughts(event));
|
|
26
|
+
}
|
|
27
|
+
compact(invocationContext) {
|
|
28
|
+
const events = invocationContext.session.events;
|
|
29
|
+
if (events.length <= this.eventRetentionSize) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const pruneLimit = events.length - this.eventRetentionSize;
|
|
33
|
+
for (let i = 0; i < pruneLimit; i++) {
|
|
34
|
+
const event = events[i];
|
|
35
|
+
if (hasThoughts(event)) {
|
|
36
|
+
events[i] = pruneThoughts(event);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
TrajectoryThoughtPruningCompactor
|
|
43
|
+
};
|
|
@@ -28,15 +28,20 @@ import { createEvent } from "./event.js";
|
|
|
28
28
|
function isCompactedEvent(event) {
|
|
29
29
|
return "isCompacted" in event && event.isCompacted === true;
|
|
30
30
|
}
|
|
31
|
+
function isScratchpadEvent(event) {
|
|
32
|
+
return isCompactedEvent(event) && event.isScratchpad === true;
|
|
33
|
+
}
|
|
31
34
|
function createCompactedEvent(params = {}) {
|
|
32
35
|
return __spreadProps(__spreadValues({}, createEvent(params)), {
|
|
33
36
|
isCompacted: params.isCompacted || true,
|
|
34
37
|
startTime: params.startTime,
|
|
35
38
|
endTime: params.endTime,
|
|
36
|
-
compactedContent: params.compactedContent
|
|
39
|
+
compactedContent: params.compactedContent,
|
|
40
|
+
isScratchpad: params.isScratchpad
|
|
37
41
|
});
|
|
38
42
|
}
|
|
39
43
|
export {
|
|
40
44
|
createCompactedEvent,
|
|
41
|
-
isCompactedEvent
|
|
45
|
+
isCompactedEvent,
|
|
46
|
+
isScratchpadEvent
|
|
42
47
|
};
|