@google/adk 0.5.0 → 0.6.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/README.md +1 -1
- package/dist/cjs/a2a/a2a_event.js +53 -26
- package/dist/cjs/a2a/a2a_remote_agent.js +174 -0
- package/dist/cjs/a2a/a2a_remote_agent_run_processor.js +198 -0
- package/dist/cjs/a2a/a2a_remote_agent_utils.js +165 -0
- package/dist/cjs/a2a/agent_card.js +380 -0
- package/dist/cjs/a2a/agent_executor.js +221 -0
- package/dist/cjs/a2a/agent_to_a2a.js +115 -0
- package/dist/cjs/a2a/event_processor_utils.js +180 -0
- package/dist/cjs/a2a/executor_context.js +1 -1
- package/dist/cjs/a2a/metadata_converter_utils.js +1 -0
- package/dist/cjs/a2a/part_converter_utils.js +24 -13
- package/dist/cjs/agents/llm_agent.js +17 -0
- package/dist/cjs/agents/{content_processor_utils.js → processors/content_processor_utils.js} +21 -2
- package/dist/cjs/agents/processors/content_request_processor.js +24 -3
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +61 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/cjs/artifacts/file_artifact_service.js +35 -4
- package/dist/cjs/common.js +37 -0
- package/dist/cjs/context/base_context_compactor.js +27 -0
- package/dist/cjs/context/summarizers/base_summarizer.js +27 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +93 -0
- package/dist/cjs/context/token_based_context_compactor.js +135 -0
- package/dist/cjs/context/truncating_context_compactor.js +58 -0
- package/dist/cjs/events/compacted_event.js +53 -0
- package/dist/cjs/index.js +38 -14
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/memory/in_memory_memory_service.js +1 -1
- package/dist/cjs/runner/runner.js +19 -10
- package/dist/cjs/sessions/db/operations.js +4 -14
- package/dist/cjs/sessions/state.js +2 -2
- package/dist/cjs/tools/agent_tool.js +6 -5
- package/dist/cjs/tools/load_artifacts_tool.js +188 -0
- package/dist/cjs/tools/load_memory_tool.js +107 -0
- package/dist/cjs/tools/preload_memory_tool.js +109 -0
- package/dist/cjs/utils/logger.js +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_event.js +52 -26
- package/dist/esm/a2a/a2a_remote_agent.js +148 -0
- package/dist/esm/a2a/a2a_remote_agent_run_processor.js +175 -0
- package/dist/esm/a2a/a2a_remote_agent_utils.js +131 -0
- package/dist/esm/a2a/agent_card.js +340 -0
- package/dist/esm/a2a/agent_executor.js +202 -0
- package/dist/esm/a2a/agent_to_a2a.js +80 -0
- package/dist/esm/a2a/event_processor_utils.js +159 -0
- package/dist/esm/a2a/executor_context.js +1 -1
- package/dist/esm/a2a/metadata_converter_utils.js +1 -0
- package/dist/esm/a2a/part_converter_utils.js +24 -13
- package/dist/esm/agents/llm_agent.js +17 -0
- package/dist/esm/agents/{content_processor_utils.js → processors/content_processor_utils.js} +23 -2
- package/dist/esm/agents/processors/content_request_processor.js +25 -4
- package/dist/esm/agents/processors/context_compactor_request_processor.js +31 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/esm/artifacts/file_artifact_service.js +30 -3
- package/dist/esm/common.js +33 -1
- package/dist/esm/context/base_context_compactor.js +5 -0
- package/dist/esm/context/summarizers/base_summarizer.js +5 -0
- package/dist/esm/context/summarizers/llm_summarizer.js +65 -0
- package/dist/esm/context/token_based_context_compactor.js +105 -0
- package/dist/esm/context/truncating_context_compactor.js +28 -0
- package/dist/esm/events/compacted_event.js +22 -0
- package/dist/esm/index.js +38 -14
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/memory/in_memory_memory_service.js +1 -1
- package/dist/esm/runner/runner.js +17 -9
- package/dist/esm/sessions/db/operations.js +4 -14
- package/dist/esm/sessions/state.js +2 -2
- package/dist/esm/tools/agent_tool.js +6 -5
- package/dist/esm/tools/load_artifacts_tool.js +159 -0
- package/dist/esm/tools/load_memory_tool.js +78 -0
- package/dist/esm/tools/preload_memory_tool.js +80 -0
- package/dist/esm/utils/logger.js +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_event.d.ts +23 -6
- package/dist/types/a2a/a2a_remote_agent.d.ts +63 -0
- package/dist/types/a2a/a2a_remote_agent_run_processor.d.ts +31 -0
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +38 -0
- package/dist/types/a2a/agent_card.d.ts +23 -0
- package/dist/types/a2a/agent_executor.d.ts +52 -0
- package/dist/types/a2a/agent_to_a2a.d.ts +45 -0
- package/dist/types/a2a/event_processor_utils.d.ts +24 -0
- package/dist/types/a2a/executor_context.d.ts +1 -1
- package/dist/types/a2a/metadata_converter_utils.d.ts +2 -1
- package/dist/types/agents/llm_agent.d.ts +6 -0
- package/dist/types/agents/loop_agent.d.ts +1 -1
- package/dist/types/agents/{content_processor_utils.d.ts → processors/content_processor_utils.d.ts} +1 -1
- package/dist/types/agents/processors/context_compactor_request_processor.d.ts +22 -0
- package/dist/types/artifacts/file_artifact_service.d.ts +4 -0
- package/dist/types/common.d.ts +16 -1
- package/dist/types/context/base_context_compactor.d.ts +24 -0
- package/dist/types/context/summarizers/base_summarizer.d.ts +19 -0
- package/dist/types/context/summarizers/llm_summarizer.d.ts +23 -0
- package/dist/types/context/token_based_context_compactor.d.ts +33 -0
- package/dist/types/context/truncating_context_compactor.d.ts +24 -0
- package/dist/types/events/compacted_event.d.ts +33 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/runner/runner.d.ts +13 -0
- package/dist/types/sessions/db/operations.d.ts +2 -3
- package/dist/types/tools/load_artifacts_tool.d.ts +21 -0
- package/dist/types/tools/load_memory_tool.d.ts +22 -0
- package/dist/types/tools/preload_memory_tool.d.ts +23 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_event.js +52 -26
- package/dist/web/a2a/a2a_remote_agent.js +193 -0
- package/dist/web/a2a/a2a_remote_agent_run_processor.js +175 -0
- package/dist/web/a2a/a2a_remote_agent_utils.js +131 -0
- package/dist/web/a2a/agent_card.js +340 -0
- package/dist/web/a2a/agent_executor.js +216 -0
- package/dist/web/a2a/agent_to_a2a.js +80 -0
- package/dist/web/a2a/event_processor_utils.js +168 -0
- package/dist/web/a2a/executor_context.js +1 -1
- package/dist/web/a2a/metadata_converter_utils.js +1 -0
- package/dist/web/a2a/part_converter_utils.js +24 -13
- package/dist/web/agents/llm_agent.js +17 -0
- package/dist/web/agents/{content_processor_utils.js → processors/content_processor_utils.js} +22 -2
- package/dist/web/agents/processors/content_request_processor.js +25 -4
- package/dist/web/agents/processors/context_compactor_request_processor.js +49 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/web/artifacts/file_artifact_service.js +30 -3
- package/dist/web/common.js +33 -1
- package/dist/web/context/base_context_compactor.js +5 -0
- package/dist/web/context/summarizers/base_summarizer.js +5 -0
- package/dist/web/context/summarizers/llm_summarizer.js +74 -0
- package/dist/web/context/token_based_context_compactor.js +105 -0
- package/dist/web/context/truncating_context_compactor.js +28 -0
- package/dist/web/events/compacted_event.js +40 -0
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +4 -4
- package/dist/web/memory/in_memory_memory_service.js +1 -1
- package/dist/web/runner/runner.js +17 -9
- package/dist/web/sessions/db/operations.js +4 -14
- package/dist/web/sessions/state.js +2 -2
- package/dist/web/tools/agent_tool.js +6 -5
- package/dist/web/tools/load_artifacts_tool.js +150 -0
- package/dist/web/tools/load_memory_tool.js +77 -0
- package/dist/web/tools/preload_memory_tool.js +75 -0
- package/dist/web/utils/logger.js +1 -0
- package/dist/web/version.js +1 -1
- package/package.json +6 -4
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Part as A2APart } from '@a2a-js/sdk';
|
|
7
|
+
import { InvocationContext } from '../agents/invocation_context.js';
|
|
8
|
+
import { Event as AdkEvent } from '../events/event.js';
|
|
9
|
+
import { Session } from '../sessions/session.js';
|
|
10
|
+
export interface UserFunctionCall {
|
|
11
|
+
response: AdkEvent;
|
|
12
|
+
taskId: string;
|
|
13
|
+
contextId: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns a UserFunctionCall when the event at index has a FunctionResponse.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getUserFunctionCallAt(session: Session, index: number): UserFunctionCall | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if an event contains a function call with the given ID.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isFunctionCallEvent(event: AdkEvent, callId: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Finds the first part with a FunctionResponse and returns the call ID.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getFunctionResponseCallId(event: AdkEvent): string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Returns content parts for all events not present in the remote session
|
|
29
|
+
* and a2a contextId if found in a remote agent event metadata.
|
|
30
|
+
*/
|
|
31
|
+
export declare function toMissingRemoteSessionParts(ctx: InvocationContext, session: Session): {
|
|
32
|
+
parts: A2APart[];
|
|
33
|
+
contextId?: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Wraps an agent event as a user message for context.
|
|
37
|
+
*/
|
|
38
|
+
export declare function presentAsUserMessage(ctx: InvocationContext, agentEvent: AdkEvent): AdkEvent;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { AgentCard, AgentInterface, AgentSkill } from '@a2a-js/sdk';
|
|
7
|
+
import { BaseAgent } from '../agents/base_agent.js';
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the AgentCard from the provided source.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveAgentCard(agentCard: AgentCard | string): Promise<AgentCard>;
|
|
12
|
+
/**
|
|
13
|
+
* Converts an ADK agent to an A2A AgentCard.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getA2AAgentCard(agent: BaseAgent, transports: AgentInterface[]): Promise<AgentCard>;
|
|
16
|
+
/**
|
|
17
|
+
* Builds a list of AgentSkills based on agent descriptions and types.
|
|
18
|
+
* This information can be used in AgentCard to help clients understand agent capabilities.
|
|
19
|
+
*
|
|
20
|
+
* @param agent The agent to build skills for.
|
|
21
|
+
* @returns A promise resolving to a list of AgentSkills.
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildAgentSkills(agent: BaseAgent): Promise<AgentSkill[]>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { TaskArtifactUpdateEvent, TaskStatusUpdateEvent } from '@a2a-js/sdk';
|
|
7
|
+
import { AgentExecutor, ExecutionEventBus, RequestContext } from '@a2a-js/sdk/server';
|
|
8
|
+
import { RunConfig } from '../agents/run_config.js';
|
|
9
|
+
import { Event as AdkEvent } from '../events/event.js';
|
|
10
|
+
import { Runner, RunnerConfig } from '../runner/runner.js';
|
|
11
|
+
import { ExecutorContext } from './executor_context.js';
|
|
12
|
+
/**
|
|
13
|
+
* Represents a runner or a configuration for a runner.
|
|
14
|
+
*/
|
|
15
|
+
export type RunnerOrRunnerConfig = Runner | RunnerConfig | (() => Runner | RunnerConfig) | (() => Promise<Runner | RunnerConfig>);
|
|
16
|
+
/**
|
|
17
|
+
* Callback called before execution starts.
|
|
18
|
+
*/
|
|
19
|
+
export type BeforeExecuteCallback = (reqCtx: RequestContext) => Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Callback called after an ADK event is converted to an A2A event.
|
|
22
|
+
*/
|
|
23
|
+
export type AfterEventCallback = (ctx: ExecutorContext, adkEvent: AdkEvent, a2aEvent?: TaskArtifactUpdateEvent) => Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Callback called after execution resolved into a completed or failed task.
|
|
26
|
+
*/
|
|
27
|
+
export type AfterExecuteCallback = (ctx: ExecutorContext, finalA2aEvent: TaskStatusUpdateEvent, err?: Error) => Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Configuration for the Executor.
|
|
30
|
+
*/
|
|
31
|
+
export interface AgentExecutorConfig {
|
|
32
|
+
runner: RunnerOrRunnerConfig;
|
|
33
|
+
runConfig?: RunConfig;
|
|
34
|
+
beforeExecuteCallback?: BeforeExecuteCallback;
|
|
35
|
+
afterEventCallback?: AfterEventCallback;
|
|
36
|
+
afterExecuteCallback?: AfterExecuteCallback;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* AgentExecutor invokes an ADK agent and translates session events to A2A events.
|
|
40
|
+
*/
|
|
41
|
+
export declare class A2AAgentExecutor implements AgentExecutor {
|
|
42
|
+
private readonly config;
|
|
43
|
+
private agentPartialArtifactIdsMap;
|
|
44
|
+
constructor(config: AgentExecutorConfig);
|
|
45
|
+
execute(ctx: RequestContext, eventBus: ExecutionEventBus): Promise<void>;
|
|
46
|
+
cancelTask(_taskId: string): Promise<void>;
|
|
47
|
+
private convertAdkEventToA2AEvent;
|
|
48
|
+
/**
|
|
49
|
+
* Writes the final status event to the queue.
|
|
50
|
+
*/
|
|
51
|
+
private publishFinalTaskStatus;
|
|
52
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { AgentCard } from '@a2a-js/sdk';
|
|
7
|
+
import express from 'express';
|
|
8
|
+
import { BaseAgent } from '../agents/base_agent.js';
|
|
9
|
+
import { BaseArtifactService } from '../artifacts/base_artifact_service.js';
|
|
10
|
+
import { BaseMemoryService } from '../memory/base_memory_service.js';
|
|
11
|
+
import { Runner } from '../runner/runner.js';
|
|
12
|
+
import { BaseSessionService } from '../sessions/base_session_service.js';
|
|
13
|
+
/**
|
|
14
|
+
* Options for the `toA2a` function.
|
|
15
|
+
*/
|
|
16
|
+
export interface ToA2aOptions {
|
|
17
|
+
/** The host for the A2A RPC URL (default: "localhost") */
|
|
18
|
+
host?: string;
|
|
19
|
+
/** The port for the A2A RPC URL (default: 8000) */
|
|
20
|
+
port?: number;
|
|
21
|
+
/** The protocol for the A2A RPC URL (default: "http") */
|
|
22
|
+
protocol?: string;
|
|
23
|
+
/** The base path for the A2A RPC URL (default: "a2a") */
|
|
24
|
+
basePath?: string;
|
|
25
|
+
/** Optional pre-built AgentCard object or path to agent card JSON */
|
|
26
|
+
agentCard?: AgentCard | string;
|
|
27
|
+
/** Optional pre-built Runner object */
|
|
28
|
+
runner?: Runner;
|
|
29
|
+
/** Optional session service */
|
|
30
|
+
sessionService?: BaseSessionService;
|
|
31
|
+
/** Optional memory service */
|
|
32
|
+
memoryService?: BaseMemoryService;
|
|
33
|
+
/** Optional artifact service */
|
|
34
|
+
artifactService?: BaseArtifactService;
|
|
35
|
+
/** Optional existing express application */
|
|
36
|
+
app?: express.Application;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts an ADK agent to an Express application with A2A handlers.
|
|
40
|
+
*
|
|
41
|
+
* @param agent The ADK agent to convert
|
|
42
|
+
* @param options Configuration options
|
|
43
|
+
* @returns An Express application
|
|
44
|
+
*/
|
|
45
|
+
export declare function toA2a(agent: BaseAgent, options?: ToA2aOptions): Promise<express.Application>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Task, TaskStatusUpdateEvent } from '@a2a-js/sdk';
|
|
7
|
+
import { Content as GenAIContent } from '@google/genai';
|
|
8
|
+
import { Event as AdkEvent } from '../events/event.js';
|
|
9
|
+
import { ExecutorContext } from './executor_context.js';
|
|
10
|
+
/**
|
|
11
|
+
* Processes a list of ADK events and determines the final task status update event.
|
|
12
|
+
* If any of the ADK events contain an error, a TaskFailedEvent is returned immediately.
|
|
13
|
+
* If there are no errors, it checks for any input required events. If found, it returns a TaskInputRequiredEvent.
|
|
14
|
+
* If there are no input required events, it returns a TaskCompletedEvent.
|
|
15
|
+
*
|
|
16
|
+
* @param adkEvents - The list of ADK events to process.
|
|
17
|
+
* @param context - The executor context containing relevant information for processing the events.
|
|
18
|
+
* @returns A TaskStatusUpdateEvent representing the final status of the task after processing the ADK events.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getFinalTaskStatusUpdate(adkEvents: AdkEvent[], context: ExecutorContext): TaskStatusUpdateEvent;
|
|
21
|
+
/**
|
|
22
|
+
* Returns input required task status update events if the provided user request does not contain responses for all function calls in the task status.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getTaskInputRequiredEvent(task: Task, genAIContent: GenAIContent): TaskStatusUpdateEvent | undefined;
|
|
@@ -27,7 +27,8 @@ export declare enum A2AMetadataKeys {
|
|
|
27
27
|
CITATION_METADATA = "adk_citation_metadata",
|
|
28
28
|
GROUNDING_METADATA = "adk_grounding_metadata",
|
|
29
29
|
USAGE_METADATA = "adk_usage_metadata",
|
|
30
|
-
CUSTOM_METADATA = "adk_custom_metadata"
|
|
30
|
+
CUSTOM_METADATA = "adk_custom_metadata",
|
|
31
|
+
VIDEO_METADATA = "adk_video_metadata"
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
* Keys for metadata that will be stored in ADK event metadata and related to A2A messages.
|
|
@@ -18,6 +18,7 @@ import { BaseToolset } from '../tools/base_toolset.js';
|
|
|
18
18
|
import { Context } from './context.js';
|
|
19
19
|
import { BaseAgent, BaseAgentConfig } from './base_agent.js';
|
|
20
20
|
import { BaseLlmRequestProcessor, BaseLlmResponseProcessor } from './processors/base_llm_processor.js';
|
|
21
|
+
import { BaseContextCompactor } from '../context/base_context_compactor.js';
|
|
21
22
|
import { InvocationContext } from './invocation_context.js';
|
|
22
23
|
import { ReadonlyContext } from './readonly_context.js';
|
|
23
24
|
/**
|
|
@@ -199,6 +200,11 @@ export interface LlmAgentConfig extends BaseAgentConfig {
|
|
|
199
200
|
* Processors to run after the LLM response is received.
|
|
200
201
|
*/
|
|
201
202
|
responseProcessors?: BaseLlmResponseProcessor[];
|
|
203
|
+
/**
|
|
204
|
+
* A list of context compactors to evaluate in priority order.
|
|
205
|
+
* Modifies the session history to keep context overhead within limits.
|
|
206
|
+
*/
|
|
207
|
+
contextCompactors?: BaseContextCompactor[];
|
|
202
208
|
/**
|
|
203
209
|
* Instructs the agent to make a plan and execute it step by step.
|
|
204
210
|
*/
|
|
@@ -39,7 +39,7 @@ export declare class LoopAgent extends BaseAgent {
|
|
|
39
39
|
* A unique symbol to identify ADK loop agent class.
|
|
40
40
|
*/
|
|
41
41
|
readonly [LOOP_AGENT_SIGNATURE_SYMBOL] = true;
|
|
42
|
-
|
|
42
|
+
readonly maxIterations: number;
|
|
43
43
|
constructor(config: LoopAgentConfig);
|
|
44
44
|
protected runAsyncImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
|
|
45
45
|
protected runLiveImpl(_context: InvocationContext): AsyncGenerator<Event, void, void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { BaseContextCompactor } from '../../context/base_context_compactor.js';
|
|
7
|
+
import { Event } from '../../events/event.js';
|
|
8
|
+
import { LlmRequest } from '../../models/llm_request.js';
|
|
9
|
+
import { InvocationContext } from '../invocation_context.js';
|
|
10
|
+
import { BaseLlmRequestProcessor } from './base_llm_processor.js';
|
|
11
|
+
/**
|
|
12
|
+
* A processor that evaluates a set of compactors to optionally compact
|
|
13
|
+
* the conversation history (events) prior to generating an LLM request.
|
|
14
|
+
*
|
|
15
|
+
* It evaluates each compactor in priority order. The first one that indicates
|
|
16
|
+
* it should compact will perform the compaction and iteration stops.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ContextCompactorRequestProcessor implements BaseLlmRequestProcessor {
|
|
19
|
+
private compactors;
|
|
20
|
+
constructor(compactors: BaseContextCompactor[]);
|
|
21
|
+
runAsync(invocationContext: InvocationContext, _llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
|
|
22
|
+
}
|
|
@@ -41,3 +41,7 @@ export declare class FileArtifactService implements BaseArtifactService {
|
|
|
41
41
|
listArtifactVersions({ userId, sessionId, filename, }: ListVersionsRequest): Promise<ArtifactVersion[]>;
|
|
42
42
|
getArtifactVersion({ userId, sessionId, filename, version, }: LoadArtifactRequest): Promise<ArtifactVersion | undefined>;
|
|
43
43
|
}
|
|
44
|
+
export declare function assertSafeSegment(value: string, label: string): void;
|
|
45
|
+
export declare function assertInsideRoot(resolvedPath: string, rootDir: string, label: string): void;
|
|
46
|
+
export declare function getUserRoot(rootDir: string, userId: string): string;
|
|
47
|
+
export declare function getSessionArtifactsDir(baseRoot: string, sessionId: string): string;
|
package/dist/types/common.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export { LoopAgent, isLoopAgent } from './agents/loop_agent.js';
|
|
|
19
19
|
export type { LoopAgentConfig } from './agents/loop_agent.js';
|
|
20
20
|
export { ParallelAgent, isParallelAgent } from './agents/parallel_agent.js';
|
|
21
21
|
export { BaseLlmRequestProcessor, BaseLlmResponseProcessor, } from './agents/processors/base_llm_processor.js';
|
|
22
|
+
export { CONTENT_REQUEST_PROCESSOR, ContentRequestProcessor, } from './agents/processors/content_request_processor.js';
|
|
23
|
+
export { ContextCompactorRequestProcessor } from './agents/processors/context_compactor_request_processor.js';
|
|
22
24
|
export { ReadonlyContext } from './agents/readonly_context.js';
|
|
23
25
|
export { StreamingMode } from './agents/run_config.js';
|
|
24
26
|
export type { RunConfig } from './agents/run_config.js';
|
|
@@ -35,6 +37,16 @@ export { BaseCodeExecutor } from './code_executors/base_code_executor.js';
|
|
|
35
37
|
export type { ExecuteCodeParams } from './code_executors/base_code_executor.js';
|
|
36
38
|
export { BuiltInCodeExecutor } from './code_executors/built_in_code_executor.js';
|
|
37
39
|
export type { CodeExecutionInput, CodeExecutionResult, File, } from './code_executors/code_execution_utils.js';
|
|
40
|
+
export type { BaseContextCompactor } from './context/base_context_compactor.js';
|
|
41
|
+
export type { BaseSummarizer } from './context/summarizers/base_summarizer.js';
|
|
42
|
+
export { LlmSummarizer } from './context/summarizers/llm_summarizer.js';
|
|
43
|
+
export type { LlmSummarizerOptions } from './context/summarizers/llm_summarizer.js';
|
|
44
|
+
export { TokenBasedContextCompactor } from './context/token_based_context_compactor.js';
|
|
45
|
+
export type { TokenBasedContextCompactorOptions } from './context/token_based_context_compactor.js';
|
|
46
|
+
export { TruncatingContextCompactor } from './context/truncating_context_compactor.js';
|
|
47
|
+
export type { TruncatingContextCompactorOptions } from './context/truncating_context_compactor.js';
|
|
48
|
+
export { isCompactedEvent } from './events/compacted_event.js';
|
|
49
|
+
export type { CompactedEvent } from './events/compacted_event.js';
|
|
38
50
|
export { createEvent, getFunctionCalls, getFunctionResponses, hasTrailingCodeExecutionResult, isFinalResponse, stringifyContent, } from './events/event.js';
|
|
39
51
|
export type { Event } from './events/event.js';
|
|
40
52
|
export { createEventActions } from './events/event_actions.js';
|
|
@@ -62,7 +74,7 @@ export { PluginManager } from './plugins/plugin_manager.js';
|
|
|
62
74
|
export { InMemoryPolicyEngine, PolicyOutcome, REQUEST_CONFIRMATION_FUNCTION_CALL_NAME, SecurityPlugin, getAskUserConfirmationFunctionCalls, } from './plugins/security_plugin.js';
|
|
63
75
|
export type { BasePolicyEngine, PolicyCheckResult, ToolCallPolicyContext, } from './plugins/security_plugin.js';
|
|
64
76
|
export { InMemoryRunner } from './runner/in_memory_runner.js';
|
|
65
|
-
export { Runner } from './runner/runner.js';
|
|
77
|
+
export { Runner, isRunner } from './runner/runner.js';
|
|
66
78
|
export type { RunnerConfig } from './runner/runner.js';
|
|
67
79
|
export { BaseSessionService } from './sessions/base_session_service.js';
|
|
68
80
|
export type { AppendEventRequest, CreateSessionRequest, DeleteSessionRequest, GetSessionConfig, GetSessionRequest, ListSessionsRequest, ListSessionsResponse, } from './sessions/base_session_service.js';
|
|
@@ -80,7 +92,10 @@ export { EXIT_LOOP, ExitLoopTool } from './tools/exit_loop_tool.js';
|
|
|
80
92
|
export { FunctionTool, isFunctionTool } from './tools/function_tool.js';
|
|
81
93
|
export type { ToolExecuteArgument, ToolExecuteFunction, ToolInputParameters, ToolOptions, } from './tools/function_tool.js';
|
|
82
94
|
export { GOOGLE_SEARCH, GoogleSearchTool } from './tools/google_search_tool.js';
|
|
95
|
+
export { LOAD_ARTIFACTS, LoadArtifactsTool, } from './tools/load_artifacts_tool.js';
|
|
96
|
+
export { LOAD_MEMORY, LoadMemoryTool } from './tools/load_memory_tool.js';
|
|
83
97
|
export { LongRunningFunctionTool } from './tools/long_running_tool.js';
|
|
98
|
+
export { PRELOAD_MEMORY, PreloadMemoryTool, } from './tools/preload_memory_tool.js';
|
|
84
99
|
export { ToolConfirmation } from './tools/tool_confirmation.js';
|
|
85
100
|
export { LogLevel, getLogger, setLogLevel, setLogger } from './utils/logger.js';
|
|
86
101
|
export type { Logger } from './utils/logger.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { InvocationContext } from '../agents/invocation_context.js';
|
|
7
|
+
/**
|
|
8
|
+
* Interface for compacting the context history in an agent session.
|
|
9
|
+
*/
|
|
10
|
+
export interface BaseContextCompactor {
|
|
11
|
+
/**
|
|
12
|
+
* Determines whether the context should be compacted.
|
|
13
|
+
*
|
|
14
|
+
* @param invocationContext The current invocation context.
|
|
15
|
+
* @returns A boolean or a promise resolving to a boolean indicating if compaction should occur.
|
|
16
|
+
*/
|
|
17
|
+
shouldCompact(invocationContext: InvocationContext): boolean | Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Compacts the context in place.
|
|
20
|
+
*
|
|
21
|
+
* @param invocationContext The current invocation context.
|
|
22
|
+
*/
|
|
23
|
+
compact(invocationContext: InvocationContext): void | Promise<void>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Event } from '../../events/event.js';
|
|
7
|
+
import { CompactedEvent } from '../../events/compacted_event.js';
|
|
8
|
+
/**
|
|
9
|
+
* Interface for summarizing a list of events into a single CompactedEvent.
|
|
10
|
+
*/
|
|
11
|
+
export interface BaseSummarizer {
|
|
12
|
+
/**
|
|
13
|
+
* Summarizes the given events into a CompactedEvent.
|
|
14
|
+
*
|
|
15
|
+
* @param events The events to summarize.
|
|
16
|
+
* @returns A promise resolving to the CompactedEvent representation of the events.
|
|
17
|
+
*/
|
|
18
|
+
summarize(events: Event[]): Promise<CompactedEvent>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { CompactedEvent } from '../../events/compacted_event.js';
|
|
7
|
+
import { Event } from '../../events/event.js';
|
|
8
|
+
import { BaseLlm } from '../../models/base_llm.js';
|
|
9
|
+
import { BaseSummarizer } from './base_summarizer.js';
|
|
10
|
+
export interface LlmSummarizerOptions {
|
|
11
|
+
llm: BaseLlm;
|
|
12
|
+
prompt?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A summarizer that uses an LLM to generate a compacted representation
|
|
16
|
+
* of existing events.
|
|
17
|
+
*/
|
|
18
|
+
export declare class LlmSummarizer implements BaseSummarizer {
|
|
19
|
+
private readonly llm;
|
|
20
|
+
private readonly prompt;
|
|
21
|
+
constructor(options: LlmSummarizerOptions);
|
|
22
|
+
summarize(events: Event[]): Promise<CompactedEvent>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { InvocationContext } from '../agents/invocation_context.js';
|
|
7
|
+
import { BaseContextCompactor } from './base_context_compactor.js';
|
|
8
|
+
import { BaseSummarizer } from './summarizers/base_summarizer.js';
|
|
9
|
+
export interface TokenBasedContextCompactorOptions {
|
|
10
|
+
/** The maximum number of tokens to retain in the session history before compaction. */
|
|
11
|
+
tokenThreshold: number;
|
|
12
|
+
/**
|
|
13
|
+
* The minimum number of raw events to keep at the end of the session.
|
|
14
|
+
* Compaction will not affect these tail events (unless needed for tool splits).
|
|
15
|
+
*/
|
|
16
|
+
eventRetentionSize: number;
|
|
17
|
+
/** The summarizer used to create the compacted event content. */
|
|
18
|
+
summarizer: BaseSummarizer;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A context compactor that uses token count to determine when to compact events.
|
|
22
|
+
* Oldest events are summarized into a CompactedEvent when the session
|
|
23
|
+
* history exceeds the token threshold.
|
|
24
|
+
*/
|
|
25
|
+
export declare class TokenBasedContextCompactor implements BaseContextCompactor {
|
|
26
|
+
private readonly tokenThreshold;
|
|
27
|
+
private readonly eventRetentionSize;
|
|
28
|
+
private readonly summarizer;
|
|
29
|
+
constructor(options: TokenBasedContextCompactorOptions);
|
|
30
|
+
private getActiveEvents;
|
|
31
|
+
shouldCompact(invocationContext: InvocationContext): boolean | Promise<boolean>;
|
|
32
|
+
compact(invocationContext: InvocationContext): Promise<void>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { InvocationContext } from '../agents/invocation_context.js';
|
|
7
|
+
import { BaseContextCompactor } from './base_context_compactor.js';
|
|
8
|
+
export interface TruncatingContextCompactorOptions {
|
|
9
|
+
/** The maximum number of events to retain in the session history. */
|
|
10
|
+
threshold: number;
|
|
11
|
+
/** Keep the first X events in the history, which often act as the initial grounding prompt. */
|
|
12
|
+
preserveLeadingEvents?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A simple context compactor that truncates the oldest events to get under
|
|
16
|
+
* the given threshold limit.
|
|
17
|
+
*/
|
|
18
|
+
export declare class TruncatingContextCompactor implements BaseContextCompactor {
|
|
19
|
+
private readonly threshold;
|
|
20
|
+
private readonly preserveLeadingEvents;
|
|
21
|
+
constructor(options: TruncatingContextCompactorOptions);
|
|
22
|
+
shouldCompact(invocationContext: InvocationContext): boolean;
|
|
23
|
+
compact(invocationContext: InvocationContext): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Event } from './event.js';
|
|
7
|
+
/**
|
|
8
|
+
* A specialized Event type that represents a synthesized summary of past events.
|
|
9
|
+
* This is used to compress session history without losing critical context.
|
|
10
|
+
*/
|
|
11
|
+
export interface CompactedEvent extends Event {
|
|
12
|
+
/**
|
|
13
|
+
* Identifies this event as a compacted event.
|
|
14
|
+
*/
|
|
15
|
+
readonly isCompacted: true;
|
|
16
|
+
/**
|
|
17
|
+
* The start time of the context that was compacted.
|
|
18
|
+
*/
|
|
19
|
+
startTime: number;
|
|
20
|
+
/**
|
|
21
|
+
* The end time of the context that was compacted.
|
|
22
|
+
*/
|
|
23
|
+
endTime: number;
|
|
24
|
+
/**
|
|
25
|
+
* The summarized content of the compacted events.
|
|
26
|
+
*/
|
|
27
|
+
compactedContent: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Type guard to check if an event is a CompactedEvent.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isCompactedEvent(event: Event): event is CompactedEvent;
|
|
33
|
+
export declare function createCompactedEvent(params?: Partial<CompactedEvent>): CompactedEvent;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
export { AGENT_CARD_PATH, RemoteA2AAgent } from './a2a/a2a_remote_agent.js';
|
|
7
|
+
export type { A2AStreamEventData, AfterA2ARequestCallback, BeforeA2ARequestCallback, RemoteA2AAgentConfig, } from './a2a/a2a_remote_agent.js';
|
|
8
|
+
export { getA2AAgentCard } from './a2a/agent_card.js';
|
|
9
|
+
export { A2AAgentExecutor } from './a2a/agent_executor.js';
|
|
10
|
+
export type { AfterEventCallback, AfterExecuteCallback, AgentExecutorConfig, BeforeExecuteCallback, RunnerOrRunnerConfig, } from './a2a/agent_executor.js';
|
|
11
|
+
export { toA2a } from './a2a/agent_to_a2a.js';
|
|
12
|
+
export type { ToA2aOptions } from './a2a/agent_to_a2a.js';
|
|
13
|
+
export type { ExecutorContext } from './a2a/executor_context.js';
|
|
6
14
|
export { FileArtifactService } from './artifacts/file_artifact_service.js';
|
|
7
15
|
export { GcsArtifactService } from './artifacts/gcs_artifact_service.js';
|
|
8
16
|
export { getArtifactServiceFromUri } from './artifacts/registry.js';
|
|
@@ -31,7 +31,19 @@ export interface RunnerConfig {
|
|
|
31
31
|
memoryService?: BaseMemoryService;
|
|
32
32
|
credentialService?: BaseCredentialService;
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* A unique symbol to identify ADK agent classes.
|
|
36
|
+
* Defined once and shared by all Runner instances.
|
|
37
|
+
*/
|
|
38
|
+
declare const RUNNER_SIGNATURE_SYMBOL: unique symbol;
|
|
39
|
+
/**
|
|
40
|
+
* Type guard to check if an object is an instance of Runner.
|
|
41
|
+
* @param obj The object to check.
|
|
42
|
+
* @returns True if the object is an instance of Runner, false otherwise.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isRunner(obj: unknown): obj is Runner;
|
|
34
45
|
export declare class Runner {
|
|
46
|
+
readonly [RUNNER_SIGNATURE_SYMBOL] = true;
|
|
35
47
|
readonly appName: string;
|
|
36
48
|
readonly agent: BaseAgent;
|
|
37
49
|
readonly pluginManager: PluginManager;
|
|
@@ -101,3 +113,4 @@ export declare class Runner {
|
|
|
101
113
|
*/
|
|
102
114
|
private isRoutableLlmAgent;
|
|
103
115
|
}
|
|
116
|
+
export {};
|
|
@@ -15,11 +15,10 @@ export declare function getConnectionOptionsFromUri(uri: string): Promise<MikroO
|
|
|
15
15
|
/**
|
|
16
16
|
* Creates a database and tables if they don't exist.
|
|
17
17
|
*
|
|
18
|
-
* @param
|
|
18
|
+
* @param orm The MikroORM instance.
|
|
19
19
|
* @returns Promise<void>
|
|
20
|
-
* @throws Error if the URI is invalid or unsupported
|
|
21
20
|
*/
|
|
22
|
-
export declare function ensureDatabaseCreated(
|
|
21
|
+
export declare function ensureDatabaseCreated(orm: MikroORM): Promise<void>;
|
|
23
22
|
/**
|
|
24
23
|
* Validates the schema version.
|
|
25
24
|
*
|
|
@@ -0,0 +1,21 @@
|
|
|
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, ToolProcessLlmRequest } from './base_tool.js';
|
|
8
|
+
/**
|
|
9
|
+
* A tool that loads the artifacts and adds them to the session.
|
|
10
|
+
*/
|
|
11
|
+
export declare class LoadArtifactsTool extends BaseTool {
|
|
12
|
+
constructor();
|
|
13
|
+
_getDeclaration(): FunctionDeclaration | undefined;
|
|
14
|
+
runAsync({ args }: RunAsyncToolRequest): Promise<unknown>;
|
|
15
|
+
processLlmRequest(request: ToolProcessLlmRequest): Promise<void>;
|
|
16
|
+
private appendArtifactsToLlmRequest;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A global instance of {@link LoadArtifactsTool}.
|
|
20
|
+
*/
|
|
21
|
+
export declare const LOAD_ARTIFACTS: LoadArtifactsTool;
|
|
@@ -0,0 +1,22 @@
|
|
|
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, ToolProcessLlmRequest } from './base_tool.js';
|
|
8
|
+
/**
|
|
9
|
+
* A tool that loads the memory for the current user.
|
|
10
|
+
*
|
|
11
|
+
* NOTE: Currently this tool only uses text part from the memory.
|
|
12
|
+
*/
|
|
13
|
+
export declare class LoadMemoryTool extends BaseTool {
|
|
14
|
+
constructor();
|
|
15
|
+
_getDeclaration(): FunctionDeclaration | undefined;
|
|
16
|
+
runAsync({ args, toolContext, }: RunAsyncToolRequest): Promise<unknown>;
|
|
17
|
+
processLlmRequest(request: ToolProcessLlmRequest): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A global instance of {@link LoadMemoryTool}.
|
|
21
|
+
*/
|
|
22
|
+
export declare const LOAD_MEMORY: LoadMemoryTool;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { BaseTool, RunAsyncToolRequest, ToolProcessLlmRequest } from './base_tool.js';
|
|
7
|
+
/**
|
|
8
|
+
* A tool that preloads the memory for the current user.
|
|
9
|
+
*
|
|
10
|
+
* This tool will be automatically executed for each llm_request, and it won't be
|
|
11
|
+
* called by the model.
|
|
12
|
+
*
|
|
13
|
+
* NOTE: Currently this tool only uses text part from the memory.
|
|
14
|
+
*/
|
|
15
|
+
export declare class PreloadMemoryTool extends BaseTool {
|
|
16
|
+
constructor();
|
|
17
|
+
runAsync({ args, toolContext, }: RunAsyncToolRequest): Promise<unknown>;
|
|
18
|
+
processLlmRequest(request: ToolProcessLlmRequest): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A global instance of {@link PreloadMemoryTool}.
|
|
22
|
+
*/
|
|
23
|
+
export declare const PRELOAD_MEMORY: PreloadMemoryTool;
|
package/dist/types/version.d.ts
CHANGED