@iqai/adk 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @iqai/adk
2
2
 
3
+ ## 0.5.2
4
+
5
+ ### Patch Changes
6
+
7
+ - ae81c74: Add event compaction feature with configurable summarization
8
+
9
+ ## 0.5.1
10
+
11
+ ### Patch Changes
12
+
13
+ - d8fd6e8: feat(agent-builder): add static withAgent method for cleaner API usage
14
+
3
15
  ## 0.5.0
4
16
 
5
17
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { Part, Content, Blob, SpeechConfig, AudioTranscriptionConfig, RealtimeInputConfig, ProactivityConfig, FunctionDeclaration, GroundingMetadata, GenerateContentResponseUsageMetadata, GenerateContentConfig, Schema, LiveConnectConfig, GoogleGenAI, FunctionCall } from '@google/genai';
1
+ import { Content, Part, Blob, SpeechConfig, AudioTranscriptionConfig, RealtimeInputConfig, ProactivityConfig, FunctionDeclaration, GroundingMetadata, GenerateContentResponseUsageMetadata, GenerateContentConfig, Schema, LiveConnectConfig, GoogleGenAI, FunctionCall } from '@google/genai';
2
2
  export { Blob, Content, FunctionDeclaration, Schema as JSONSchema } from '@google/genai';
3
3
  import { LanguageModel } from 'ai';
4
4
  import * as z from 'zod';
@@ -57,6 +57,15 @@ declare class Logger {
57
57
  private arrayToLines;
58
58
  }
59
59
 
60
+ /**
61
+ * Event compaction data structure containing the summarized content
62
+ * and the timestamp range it covers.
63
+ */
64
+ interface EventCompaction {
65
+ startTimestamp: number;
66
+ endTimestamp: number;
67
+ compactedContent: Content;
68
+ }
60
69
  /**
61
70
  * Represents the actions attached to an event.
62
71
  */
@@ -87,6 +96,11 @@ declare class EventActions {
87
96
  * Requested authentication configurations.
88
97
  */
89
98
  requestedAuthConfigs?: Record<string, any>;
99
+ /**
100
+ * Event compaction information. When set, this event represents
101
+ * a compaction of events within the specified timestamp range.
102
+ */
103
+ compaction?: EventCompaction;
90
104
  /**
91
105
  * Constructor for EventActions
92
106
  */
@@ -97,6 +111,7 @@ declare class EventActions {
97
111
  transferToAgent?: string;
98
112
  escalate?: boolean;
99
113
  requestedAuthConfigs?: Record<string, any>;
114
+ compaction?: EventCompaction;
100
115
  });
101
116
  }
102
117
 
@@ -4021,6 +4036,45 @@ declare class LangGraphAgent extends BaseAgent {
4021
4036
  setMaxSteps(maxSteps: number): void;
4022
4037
  }
4023
4038
 
4039
+ /**
4040
+ * Base interface for event summarizers.
4041
+ * Implementations convert a list of events into a single compaction event.
4042
+ */
4043
+ interface EventsSummarizer {
4044
+ /**
4045
+ * Attempts to summarize a list of events into a single compaction event.
4046
+ * @param events - The events to summarize
4047
+ * @returns A compaction carrier event with actions.compaction set, or undefined if no summarization is needed
4048
+ */
4049
+ maybeSummarizeEvents(events: Event[]): Promise<Event | undefined>;
4050
+ }
4051
+
4052
+ /**
4053
+ * Configuration for event compaction feature.
4054
+ * Controls how and when session histories are compacted via summarization.
4055
+ */
4056
+ interface EventsCompactionConfig {
4057
+ /**
4058
+ * The summarizer to use for compacting events.
4059
+ * If not provided, a default LLM-based summarizer will be used.
4060
+ */
4061
+ summarizer?: EventsSummarizer;
4062
+ /**
4063
+ * Number of new invocations required to trigger compaction.
4064
+ * When this many new invocations have been completed since the last
4065
+ * compaction, a new compaction will be triggered.
4066
+ * Default: 10
4067
+ */
4068
+ compactionInterval: number;
4069
+ /**
4070
+ * Number of prior invocations to include from the previous compacted
4071
+ * range for continuity when creating a new compaction.
4072
+ * This ensures some overlap between successive summaries.
4073
+ * Default: 2
4074
+ */
4075
+ overlapSize: number;
4076
+ }
4077
+
4024
4078
  /**
4025
4079
  * Configuration options for the AgentBuilder
4026
4080
  */
@@ -4161,6 +4215,7 @@ declare class AgentBuilder<TOut = string, TMulti extends boolean = false> {
4161
4215
  private sessionOptions?;
4162
4216
  private memoryService?;
4163
4217
  private artifactService?;
4218
+ private eventsCompactionConfig?;
4164
4219
  private agentType;
4165
4220
  private existingSession?;
4166
4221
  private existingAgent?;
@@ -4273,6 +4328,12 @@ declare class AgentBuilder<TOut = string, TMulti extends boolean = false> {
4273
4328
  * @returns This builder instance for chaining
4274
4329
  */
4275
4330
  withAfterToolCallback(callback: AfterToolCallback): this;
4331
+ /**
4332
+ * Convenience method to start building with an existing agent
4333
+ * @param agent The agent instance to wrap
4334
+ * @returns New AgentBuilder instance with agent set
4335
+ */
4336
+ static withAgent(agent: BaseAgent): AgentBuilder<string, false>;
4276
4337
  /**
4277
4338
  * Provide an already constructed agent instance. Further definition-mutating calls
4278
4339
  * (model/tools/instruction/etc.) will be ignored with a dev warning.
@@ -4334,6 +4395,23 @@ declare class AgentBuilder<TOut = string, TMulti extends boolean = false> {
4334
4395
  * Configure runtime behavior for runs
4335
4396
  */
4336
4397
  withRunConfig(config: RunConfig | Partial<RunConfig>): this;
4398
+ /**
4399
+ * Configure event compaction for automatic history management
4400
+ * @param config Event compaction configuration
4401
+ * @returns This builder instance for chaining
4402
+ * @example
4403
+ * ```typescript
4404
+ * const { runner } = await AgentBuilder
4405
+ * .create("assistant")
4406
+ * .withModel("gemini-2.5-flash")
4407
+ * .withEventsCompaction({
4408
+ * compactionInterval: 10, // Compact every 10 invocations
4409
+ * overlapSize: 2, // Include 2 prior invocations
4410
+ * })
4411
+ * .build();
4412
+ * ```
4413
+ */
4414
+ withEventsCompaction(config: EventsCompactionConfig): this;
4337
4415
  /**
4338
4416
  * Configure with an in-memory session with custom IDs
4339
4417
  * Note: In-memory sessions are created automatically by default, use this only if you need custom appName/userId
@@ -4834,12 +4912,46 @@ declare class InMemoryArtifactService implements BaseArtifactService {
4834
4912
  }): Promise<number[]>;
4835
4913
  }
4836
4914
 
4915
+ /**
4916
+ * LLM-based event summarizer that uses a language model to generate summaries.
4917
+ */
4918
+ declare class LlmEventSummarizer implements EventsSummarizer {
4919
+ private model;
4920
+ private prompt;
4921
+ /**
4922
+ * Creates a new LLM event summarizer.
4923
+ * @param model - The LLM model to use for summarization
4924
+ * @param prompt - Optional custom prompt template. Use {events} as placeholder for event content.
4925
+ */
4926
+ constructor(model: BaseLlm, prompt?: string);
4927
+ /**
4928
+ * Summarizes events using the configured LLM.
4929
+ */
4930
+ maybeSummarizeEvents(events: Event[]): Promise<Event | undefined>;
4931
+ /**
4932
+ * Formats events into a readable text format for summarization.
4933
+ */
4934
+ private formatEventsForSummarization;
4935
+ }
4936
+
4937
+ /**
4938
+ * Runs compaction for a sliding window of invocations.
4939
+ * This function implements the core sliding window logic from ADK Python.
4940
+ */
4941
+ declare function runCompactionForSlidingWindow(config: EventsCompactionConfig, session: Session, sessionService: BaseSessionService, summarizer: EventsSummarizer): Promise<void>;
4942
+
4837
4943
  type index$2_Event = Event;
4838
4944
  declare const index$2_Event: typeof Event;
4839
4945
  type index$2_EventActions = EventActions;
4840
4946
  declare const index$2_EventActions: typeof EventActions;
4947
+ type index$2_EventCompaction = EventCompaction;
4948
+ type index$2_EventsCompactionConfig = EventsCompactionConfig;
4949
+ type index$2_EventsSummarizer = EventsSummarizer;
4950
+ type index$2_LlmEventSummarizer = LlmEventSummarizer;
4951
+ declare const index$2_LlmEventSummarizer: typeof LlmEventSummarizer;
4952
+ declare const index$2_runCompactionForSlidingWindow: typeof runCompactionForSlidingWindow;
4841
4953
  declare namespace index$2 {
4842
- export { index$2_Event as Event, index$2_EventActions as EventActions };
4954
+ export { index$2_Event as Event, index$2_EventActions as EventActions, type index$2_EventCompaction as EventCompaction, type index$2_EventsCompactionConfig as EventsCompactionConfig, type index$2_EventsSummarizer as EventsSummarizer, index$2_LlmEventSummarizer as LlmEventSummarizer, index$2_runCompactionForSlidingWindow as runCompactionForSlidingWindow };
4843
4955
  }
4844
4956
 
4845
4957
  declare abstract class BaseLlmFlow {
@@ -5537,16 +5649,21 @@ declare class Runner<T extends BaseAgent = BaseAgent> {
5537
5649
  * The memory service for the runner.
5538
5650
  */
5539
5651
  memoryService?: BaseMemoryService;
5652
+ /**
5653
+ * Configuration for event compaction.
5654
+ */
5655
+ eventsCompactionConfig?: EventsCompactionConfig;
5540
5656
  protected logger: Logger;
5541
5657
  /**
5542
5658
  * Initializes the Runner.
5543
5659
  */
5544
- constructor({ appName, agent, artifactService, sessionService, memoryService, }: {
5660
+ constructor({ appName, agent, artifactService, sessionService, memoryService, eventsCompactionConfig, }: {
5545
5661
  appName: string;
5546
5662
  agent: T;
5547
5663
  artifactService?: BaseArtifactService;
5548
5664
  sessionService: BaseSessionService;
5549
5665
  memoryService?: BaseMemoryService;
5666
+ eventsCompactionConfig?: EventsCompactionConfig;
5550
5667
  });
5551
5668
  /**
5552
5669
  * Runs the agent synchronously.
@@ -5584,6 +5701,14 @@ declare class Runner<T extends BaseAgent = BaseAgent> {
5584
5701
  * Creates a new invocation context.
5585
5702
  */
5586
5703
  private _newInvocationContext;
5704
+ /**
5705
+ * Runs compaction if configured.
5706
+ */
5707
+ private _runCompaction;
5708
+ /**
5709
+ * Gets the configured summarizer or creates a default LLM-based one.
5710
+ */
5711
+ private _getOrCreateSummarizer;
5587
5712
  }
5588
5713
  /**
5589
5714
  * An in-memory Runner for testing and development.
@@ -5673,4 +5798,4 @@ declare const traceLlmCall: (invocationContext: InvocationContext, eventId: stri
5673
5798
 
5674
5799
  declare const VERSION = "0.1.0";
5675
5800
 
5676
- export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, type AfterModelCallback, type AfterToolCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentBuilderWithSchema, AgentEvaluator, AgentTool, type AgentToolConfig, type AgentType, index$5 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, type BaseAgentType, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BeforeModelCallback, type BeforeToolCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, type CreateToolConfig, type CreateToolConfigWithSchema, type CreateToolConfigWithoutSchema, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, type EvalCase, type EvalCaseResult, type EvalMetric, type EvalMetricResult, type EvalMetricResultPerInvocation, EvalResult, type EvalSet, type EvalSetResult, EvalStatus, type EvaluateConfig, index as Evaluation, type EvaluationResult, Evaluator, Event, EventActions, index$2 as Events, ExitLoopTool, type File, FileOperationsTool, FinalResponseMatchV2Evaluator, index$1 as Flows, type FullMessage, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, type IntermediateData, type Interval, type Invocation, InvocationContext, type JudgeModelOptions, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, McpCoinGeckoPro, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntents, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, McpUpbit, index$4 as Memory, type MessagePart, type MetricInfo, type MetricValueInfo, index$6 as Models, type MultiAgentResponse, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, type PerInvocationResult, PlanReActPlanner, PrebuiltMetrics, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RougeEvaluator, RunConfig, Runner, type RunnerAskReturn, SafetyEvaluatorV1, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionInput, type SessionOptions, index$3 as Sessions, type SingleAfterModelCallback, type SingleAfterToolCallback, type SingleAgentCallback, type SingleBeforeModelCallback, type SingleBeforeToolCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$7 as Tools, TrajectoryEvaluator, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiRagMemoryService, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, convertMcpToolToBaseTool, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, createTool, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
5801
+ export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, type AfterModelCallback, type AfterToolCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentBuilderWithSchema, AgentEvaluator, AgentTool, type AgentToolConfig, type AgentType, index$5 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, type BaseAgentType, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BeforeModelCallback, type BeforeToolCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, type CreateToolConfig, type CreateToolConfigWithSchema, type CreateToolConfigWithoutSchema, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, type EvalCase, type EvalCaseResult, type EvalMetric, type EvalMetricResult, type EvalMetricResultPerInvocation, EvalResult, type EvalSet, type EvalSetResult, EvalStatus, type EvaluateConfig, index as Evaluation, type EvaluationResult, Evaluator, Event, EventActions, type EventCompaction, index$2 as Events, type EventsCompactionConfig, type EventsSummarizer, ExitLoopTool, type File, FileOperationsTool, FinalResponseMatchV2Evaluator, index$1 as Flows, type FullMessage, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, type IntermediateData, type Interval, type Invocation, InvocationContext, type JudgeModelOptions, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, LlmEventSummarizer, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, McpCoinGeckoPro, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntents, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, McpUpbit, index$4 as Memory, type MessagePart, type MetricInfo, type MetricValueInfo, index$6 as Models, type MultiAgentResponse, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, type PerInvocationResult, PlanReActPlanner, PrebuiltMetrics, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RougeEvaluator, RunConfig, Runner, type RunnerAskReturn, SafetyEvaluatorV1, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionInput, type SessionOptions, index$3 as Sessions, type SingleAfterModelCallback, type SingleAfterToolCallback, type SingleAgentCallback, type SingleBeforeModelCallback, type SingleBeforeToolCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$7 as Tools, TrajectoryEvaluator, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiRagMemoryService, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, convertMcpToolToBaseTool, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, createTool, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, runCompactionForSlidingWindow, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Part, Content, Blob, SpeechConfig, AudioTranscriptionConfig, RealtimeInputConfig, ProactivityConfig, FunctionDeclaration, GroundingMetadata, GenerateContentResponseUsageMetadata, GenerateContentConfig, Schema, LiveConnectConfig, GoogleGenAI, FunctionCall } from '@google/genai';
1
+ import { Content, Part, Blob, SpeechConfig, AudioTranscriptionConfig, RealtimeInputConfig, ProactivityConfig, FunctionDeclaration, GroundingMetadata, GenerateContentResponseUsageMetadata, GenerateContentConfig, Schema, LiveConnectConfig, GoogleGenAI, FunctionCall } from '@google/genai';
2
2
  export { Blob, Content, FunctionDeclaration, Schema as JSONSchema } from '@google/genai';
3
3
  import { LanguageModel } from 'ai';
4
4
  import * as z from 'zod';
@@ -57,6 +57,15 @@ declare class Logger {
57
57
  private arrayToLines;
58
58
  }
59
59
 
60
+ /**
61
+ * Event compaction data structure containing the summarized content
62
+ * and the timestamp range it covers.
63
+ */
64
+ interface EventCompaction {
65
+ startTimestamp: number;
66
+ endTimestamp: number;
67
+ compactedContent: Content;
68
+ }
60
69
  /**
61
70
  * Represents the actions attached to an event.
62
71
  */
@@ -87,6 +96,11 @@ declare class EventActions {
87
96
  * Requested authentication configurations.
88
97
  */
89
98
  requestedAuthConfigs?: Record<string, any>;
99
+ /**
100
+ * Event compaction information. When set, this event represents
101
+ * a compaction of events within the specified timestamp range.
102
+ */
103
+ compaction?: EventCompaction;
90
104
  /**
91
105
  * Constructor for EventActions
92
106
  */
@@ -97,6 +111,7 @@ declare class EventActions {
97
111
  transferToAgent?: string;
98
112
  escalate?: boolean;
99
113
  requestedAuthConfigs?: Record<string, any>;
114
+ compaction?: EventCompaction;
100
115
  });
101
116
  }
102
117
 
@@ -4021,6 +4036,45 @@ declare class LangGraphAgent extends BaseAgent {
4021
4036
  setMaxSteps(maxSteps: number): void;
4022
4037
  }
4023
4038
 
4039
+ /**
4040
+ * Base interface for event summarizers.
4041
+ * Implementations convert a list of events into a single compaction event.
4042
+ */
4043
+ interface EventsSummarizer {
4044
+ /**
4045
+ * Attempts to summarize a list of events into a single compaction event.
4046
+ * @param events - The events to summarize
4047
+ * @returns A compaction carrier event with actions.compaction set, or undefined if no summarization is needed
4048
+ */
4049
+ maybeSummarizeEvents(events: Event[]): Promise<Event | undefined>;
4050
+ }
4051
+
4052
+ /**
4053
+ * Configuration for event compaction feature.
4054
+ * Controls how and when session histories are compacted via summarization.
4055
+ */
4056
+ interface EventsCompactionConfig {
4057
+ /**
4058
+ * The summarizer to use for compacting events.
4059
+ * If not provided, a default LLM-based summarizer will be used.
4060
+ */
4061
+ summarizer?: EventsSummarizer;
4062
+ /**
4063
+ * Number of new invocations required to trigger compaction.
4064
+ * When this many new invocations have been completed since the last
4065
+ * compaction, a new compaction will be triggered.
4066
+ * Default: 10
4067
+ */
4068
+ compactionInterval: number;
4069
+ /**
4070
+ * Number of prior invocations to include from the previous compacted
4071
+ * range for continuity when creating a new compaction.
4072
+ * This ensures some overlap between successive summaries.
4073
+ * Default: 2
4074
+ */
4075
+ overlapSize: number;
4076
+ }
4077
+
4024
4078
  /**
4025
4079
  * Configuration options for the AgentBuilder
4026
4080
  */
@@ -4161,6 +4215,7 @@ declare class AgentBuilder<TOut = string, TMulti extends boolean = false> {
4161
4215
  private sessionOptions?;
4162
4216
  private memoryService?;
4163
4217
  private artifactService?;
4218
+ private eventsCompactionConfig?;
4164
4219
  private agentType;
4165
4220
  private existingSession?;
4166
4221
  private existingAgent?;
@@ -4273,6 +4328,12 @@ declare class AgentBuilder<TOut = string, TMulti extends boolean = false> {
4273
4328
  * @returns This builder instance for chaining
4274
4329
  */
4275
4330
  withAfterToolCallback(callback: AfterToolCallback): this;
4331
+ /**
4332
+ * Convenience method to start building with an existing agent
4333
+ * @param agent The agent instance to wrap
4334
+ * @returns New AgentBuilder instance with agent set
4335
+ */
4336
+ static withAgent(agent: BaseAgent): AgentBuilder<string, false>;
4276
4337
  /**
4277
4338
  * Provide an already constructed agent instance. Further definition-mutating calls
4278
4339
  * (model/tools/instruction/etc.) will be ignored with a dev warning.
@@ -4334,6 +4395,23 @@ declare class AgentBuilder<TOut = string, TMulti extends boolean = false> {
4334
4395
  * Configure runtime behavior for runs
4335
4396
  */
4336
4397
  withRunConfig(config: RunConfig | Partial<RunConfig>): this;
4398
+ /**
4399
+ * Configure event compaction for automatic history management
4400
+ * @param config Event compaction configuration
4401
+ * @returns This builder instance for chaining
4402
+ * @example
4403
+ * ```typescript
4404
+ * const { runner } = await AgentBuilder
4405
+ * .create("assistant")
4406
+ * .withModel("gemini-2.5-flash")
4407
+ * .withEventsCompaction({
4408
+ * compactionInterval: 10, // Compact every 10 invocations
4409
+ * overlapSize: 2, // Include 2 prior invocations
4410
+ * })
4411
+ * .build();
4412
+ * ```
4413
+ */
4414
+ withEventsCompaction(config: EventsCompactionConfig): this;
4337
4415
  /**
4338
4416
  * Configure with an in-memory session with custom IDs
4339
4417
  * Note: In-memory sessions are created automatically by default, use this only if you need custom appName/userId
@@ -4834,12 +4912,46 @@ declare class InMemoryArtifactService implements BaseArtifactService {
4834
4912
  }): Promise<number[]>;
4835
4913
  }
4836
4914
 
4915
+ /**
4916
+ * LLM-based event summarizer that uses a language model to generate summaries.
4917
+ */
4918
+ declare class LlmEventSummarizer implements EventsSummarizer {
4919
+ private model;
4920
+ private prompt;
4921
+ /**
4922
+ * Creates a new LLM event summarizer.
4923
+ * @param model - The LLM model to use for summarization
4924
+ * @param prompt - Optional custom prompt template. Use {events} as placeholder for event content.
4925
+ */
4926
+ constructor(model: BaseLlm, prompt?: string);
4927
+ /**
4928
+ * Summarizes events using the configured LLM.
4929
+ */
4930
+ maybeSummarizeEvents(events: Event[]): Promise<Event | undefined>;
4931
+ /**
4932
+ * Formats events into a readable text format for summarization.
4933
+ */
4934
+ private formatEventsForSummarization;
4935
+ }
4936
+
4937
+ /**
4938
+ * Runs compaction for a sliding window of invocations.
4939
+ * This function implements the core sliding window logic from ADK Python.
4940
+ */
4941
+ declare function runCompactionForSlidingWindow(config: EventsCompactionConfig, session: Session, sessionService: BaseSessionService, summarizer: EventsSummarizer): Promise<void>;
4942
+
4837
4943
  type index$2_Event = Event;
4838
4944
  declare const index$2_Event: typeof Event;
4839
4945
  type index$2_EventActions = EventActions;
4840
4946
  declare const index$2_EventActions: typeof EventActions;
4947
+ type index$2_EventCompaction = EventCompaction;
4948
+ type index$2_EventsCompactionConfig = EventsCompactionConfig;
4949
+ type index$2_EventsSummarizer = EventsSummarizer;
4950
+ type index$2_LlmEventSummarizer = LlmEventSummarizer;
4951
+ declare const index$2_LlmEventSummarizer: typeof LlmEventSummarizer;
4952
+ declare const index$2_runCompactionForSlidingWindow: typeof runCompactionForSlidingWindow;
4841
4953
  declare namespace index$2 {
4842
- export { index$2_Event as Event, index$2_EventActions as EventActions };
4954
+ export { index$2_Event as Event, index$2_EventActions as EventActions, type index$2_EventCompaction as EventCompaction, type index$2_EventsCompactionConfig as EventsCompactionConfig, type index$2_EventsSummarizer as EventsSummarizer, index$2_LlmEventSummarizer as LlmEventSummarizer, index$2_runCompactionForSlidingWindow as runCompactionForSlidingWindow };
4843
4955
  }
4844
4956
 
4845
4957
  declare abstract class BaseLlmFlow {
@@ -5537,16 +5649,21 @@ declare class Runner<T extends BaseAgent = BaseAgent> {
5537
5649
  * The memory service for the runner.
5538
5650
  */
5539
5651
  memoryService?: BaseMemoryService;
5652
+ /**
5653
+ * Configuration for event compaction.
5654
+ */
5655
+ eventsCompactionConfig?: EventsCompactionConfig;
5540
5656
  protected logger: Logger;
5541
5657
  /**
5542
5658
  * Initializes the Runner.
5543
5659
  */
5544
- constructor({ appName, agent, artifactService, sessionService, memoryService, }: {
5660
+ constructor({ appName, agent, artifactService, sessionService, memoryService, eventsCompactionConfig, }: {
5545
5661
  appName: string;
5546
5662
  agent: T;
5547
5663
  artifactService?: BaseArtifactService;
5548
5664
  sessionService: BaseSessionService;
5549
5665
  memoryService?: BaseMemoryService;
5666
+ eventsCompactionConfig?: EventsCompactionConfig;
5550
5667
  });
5551
5668
  /**
5552
5669
  * Runs the agent synchronously.
@@ -5584,6 +5701,14 @@ declare class Runner<T extends BaseAgent = BaseAgent> {
5584
5701
  * Creates a new invocation context.
5585
5702
  */
5586
5703
  private _newInvocationContext;
5704
+ /**
5705
+ * Runs compaction if configured.
5706
+ */
5707
+ private _runCompaction;
5708
+ /**
5709
+ * Gets the configured summarizer or creates a default LLM-based one.
5710
+ */
5711
+ private _getOrCreateSummarizer;
5587
5712
  }
5588
5713
  /**
5589
5714
  * An in-memory Runner for testing and development.
@@ -5673,4 +5798,4 @@ declare const traceLlmCall: (invocationContext: InvocationContext, eventId: stri
5673
5798
 
5674
5799
  declare const VERSION = "0.1.0";
5675
5800
 
5676
- export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, type AfterModelCallback, type AfterToolCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentBuilderWithSchema, AgentEvaluator, AgentTool, type AgentToolConfig, type AgentType, index$5 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, type BaseAgentType, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BeforeModelCallback, type BeforeToolCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, type CreateToolConfig, type CreateToolConfigWithSchema, type CreateToolConfigWithoutSchema, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, type EvalCase, type EvalCaseResult, type EvalMetric, type EvalMetricResult, type EvalMetricResultPerInvocation, EvalResult, type EvalSet, type EvalSetResult, EvalStatus, type EvaluateConfig, index as Evaluation, type EvaluationResult, Evaluator, Event, EventActions, index$2 as Events, ExitLoopTool, type File, FileOperationsTool, FinalResponseMatchV2Evaluator, index$1 as Flows, type FullMessage, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, type IntermediateData, type Interval, type Invocation, InvocationContext, type JudgeModelOptions, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, McpCoinGeckoPro, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntents, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, McpUpbit, index$4 as Memory, type MessagePart, type MetricInfo, type MetricValueInfo, index$6 as Models, type MultiAgentResponse, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, type PerInvocationResult, PlanReActPlanner, PrebuiltMetrics, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RougeEvaluator, RunConfig, Runner, type RunnerAskReturn, SafetyEvaluatorV1, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionInput, type SessionOptions, index$3 as Sessions, type SingleAfterModelCallback, type SingleAfterToolCallback, type SingleAgentCallback, type SingleBeforeModelCallback, type SingleBeforeToolCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$7 as Tools, TrajectoryEvaluator, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiRagMemoryService, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, convertMcpToolToBaseTool, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, createTool, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };
5801
+ export { AF_FUNCTION_CALL_ID_PREFIX, type AfterAgentCallback, type AfterModelCallback, type AfterToolCallback, LlmAgent as Agent, AgentBuilder, type AgentBuilderConfig, type AgentBuilderWithSchema, AgentEvaluator, AgentTool, type AgentToolConfig, type AgentType, index$5 as Agents, AiSdkLlm, AnthropicLlm, ApiKeyCredential, ApiKeyScheme, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, AuthTool, type AuthToolArguments, AutoFlow, BaseAgent, type BaseAgentType, BaseCodeExecutor, type BaseCodeExecutorConfig, BaseLLMConnection, BaseLlm, BaseLlmFlow, BaseLlmRequestProcessor, BaseLlmResponseProcessor, type BaseMemoryService, BasePlanner, BaseSessionService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BeforeAgentCallback, type BeforeModelCallback, type BeforeToolCallback, type BuildFunctionDeclarationOptions, type BuiltAgent, BuiltInCodeExecutor, BuiltInPlanner, CallbackContext, type CodeExecutionInput, type CodeExecutionResult, CodeExecutionUtils, CodeExecutorContext, type CreateToolConfig, type CreateToolConfigWithSchema, type CreateToolConfigWithoutSchema, DatabaseSessionService, EnhancedAuthConfig, type EnhancedRunner, type EvalCase, type EvalCaseResult, type EvalMetric, type EvalMetricResult, type EvalMetricResultPerInvocation, EvalResult, type EvalSet, type EvalSetResult, EvalStatus, type EvaluateConfig, index as Evaluation, type EvaluationResult, Evaluator, Event, EventActions, type EventCompaction, index$2 as Events, type EventsCompactionConfig, type EventsSummarizer, ExitLoopTool, type File, FileOperationsTool, FinalResponseMatchV2Evaluator, index$1 as Flows, type FullMessage, FunctionTool, GcsArtifactService, type GetSessionConfig, GetUserChoiceTool, GoogleLlm, GoogleSearch, HttpRequestTool, HttpScheme, InMemoryArtifactService, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, type InstructionProvider, type IntermediateData, type Interval, type Invocation, InvocationContext, type JudgeModelOptions, LLMRegistry, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionsResponse, LlmAgent, type LlmAgentConfig, LlmCallsLimitExceededError, LlmEventSummarizer, type LlmModel, type LlmModelConfig, LlmRequest, LlmResponse, LoadArtifactsTool, LoadMemoryTool, LocalEvalService, LoopAgent, type LoopAgentConfig, McpAbi, McpAtp, McpBamm, McpCoinGecko, McpCoinGeckoPro, type McpConfig, McpDiscord, McpError, McpErrorType, McpFilesystem, McpFraxlend, McpGeneric, McpIqWiki, McpMemory, McpNearAgent, McpNearIntents, McpOdos, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, type McpServerConfig, McpTelegram, McpToolset, type McpTransportType, McpUpbit, index$4 as Memory, type MessagePart, type MetricInfo, type MetricValueInfo, index$6 as Models, type MultiAgentResponse, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAiLlm, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, type PerInvocationResult, PlanReActPlanner, PrebuiltMetrics, REQUEST_EUC_FUNCTION_CALL_NAME, ReadonlyContext, RougeEvaluator, RunConfig, Runner, type RunnerAskReturn, SafetyEvaluatorV1, type SamplingHandler, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionInput, type SessionOptions, index$3 as Sessions, type SingleAfterModelCallback, type SingleAfterToolCallback, type SingleAgentCallback, type SingleBeforeModelCallback, type SingleBeforeToolCallback, SingleFlow, State, StreamingMode, type TelemetryConfig, TelemetryService, type ThinkingConfig, type ToolConfig, ToolContext, type ToolUnion, index$7 as Tools, TrajectoryEvaluator, TransferToAgentTool, UserInteractionTool, VERSION, VertexAiRagMemoryService, VertexAiSessionService, _findFunctionCallEventIfLastEventIsFunctionResponse, adkToMcpToolType, requestProcessor$2 as agentTransferRequestProcessor, requestProcessor$6 as basicRequestProcessor, buildFunctionDeclaration, requestProcessor as codeExecutionRequestProcessor, responseProcessor as codeExecutionResponseProcessor, requestProcessor$3 as contentRequestProcessor, convertMcpToolToBaseTool, createAuthToolArguments, createBranchContextForSubAgent, createDatabaseSessionService, createFunctionTool, createMysqlSessionService, createPostgresSessionService, createSamplingHandler, createSqliteSessionService, createTool, generateAuthEvent, generateClientFunctionCallId, getLongRunningFunctionCalls, getMcpTools, handleFunctionCallsAsync, handleFunctionCallsLive, requestProcessor$5 as identityRequestProcessor, initializeTelemetry, injectSessionState, requestProcessor$4 as instructionsRequestProcessor, isEnhancedAuthConfig, jsonSchemaToDeclaration, mcpSchemaToParameters, mergeAgentRun, mergeParallelFunctionResponseEvents, newInvocationContextId, requestProcessor$1 as nlPlanningRequestProcessor, responseProcessor$1 as nlPlanningResponseProcessor, normalizeJsonSchema, populateClientFunctionCallId, registerProviders, removeClientFunctionCallId, requestProcessor$7 as requestProcessor, runCompactionForSlidingWindow, shutdownTelemetry, telemetryService, traceLlmCall, traceToolCall, tracer };