@inkeep/agents-run-api 0.0.0-dev-20260102022857 → 0.0.0-dev-20260105194521
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/a2a/handlers.js +2 -1
- package/dist/agents/Agent.d.ts +47 -1
- package/dist/agents/Agent.js +558 -569
- package/dist/agents/generateTaskHandler.js +12 -3
- package/dist/constants/execution-limits/defaults.d.ts +4 -0
- package/dist/constants/execution-limits/defaults.js +5 -1
- package/dist/constants/execution-limits/index.d.ts +2 -2
- package/dist/constants/execution-limits/index.js +8 -3
- package/dist/create-app.d.ts +2 -2
- package/dist/data/conversations.d.ts +43 -3
- package/dist/data/conversations.js +317 -10
- package/dist/env.d.ts +2 -2
- package/dist/handlers/executionHandler.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/services/AgentSession.d.ts +1 -1
- package/dist/services/AgentSession.js +1 -1
- package/dist/services/ArtifactService.js +2 -1
- package/dist/services/BaseCompressor.d.ts +183 -0
- package/dist/services/BaseCompressor.js +504 -0
- package/dist/services/ConversationCompressor.d.ts +32 -0
- package/dist/services/ConversationCompressor.js +91 -0
- package/dist/services/MidGenerationCompressor.d.ts +35 -63
- package/dist/services/MidGenerationCompressor.js +40 -311
- package/dist/tools/distill-conversation-history-tool.d.ts +62 -0
- package/dist/tools/distill-conversation-history-tool.js +206 -0
- package/dist/tools/distill-conversation-tool.js +20 -35
- package/dist/utils/model-context-utils.d.ts +10 -2
- package/dist/utils/model-context-utils.js +79 -47
- package/package.json +2 -2
|
@@ -128,7 +128,7 @@ interface CompressionEventData {
|
|
|
128
128
|
artifactCount: number;
|
|
129
129
|
contextSizeBefore: number;
|
|
130
130
|
contextSizeAfter: number;
|
|
131
|
-
compressionType: 'mid_generation' | '
|
|
131
|
+
compressionType: 'mid_generation' | 'conversation_level';
|
|
132
132
|
}
|
|
133
133
|
interface ErrorEventData {
|
|
134
134
|
message: string;
|
|
@@ -2,10 +2,10 @@ import { getLogger } from "../logger.js";
|
|
|
2
2
|
import dbClient_default from "../data/db/dbClient.js";
|
|
3
3
|
import { ARTIFACT_GENERATION_BACKOFF_INITIAL_MS, ARTIFACT_GENERATION_BACKOFF_MAX_MS, ARTIFACT_GENERATION_MAX_RETRIES, ARTIFACT_SESSION_MAX_PENDING, ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES, STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS, STATUS_UPDATE_DEFAULT_NUM_EVENTS } from "../constants/execution-limits/index.js";
|
|
4
4
|
import { toolSessionManager } from "../agents/ToolSessionManager.js";
|
|
5
|
+
import { setSpanWithError as setSpanWithError$1, tracer } from "../utils/tracer.js";
|
|
5
6
|
import { getFormattedConversationHistory } from "../data/conversations.js";
|
|
6
7
|
import { defaultStatusSchemas } from "../utils/default-status-schemas.js";
|
|
7
8
|
import { getStreamHelper } from "../utils/stream-registry.js";
|
|
8
|
-
import { setSpanWithError as setSpanWithError$1, tracer } from "../utils/tracer.js";
|
|
9
9
|
import { ArtifactService } from "./ArtifactService.js";
|
|
10
10
|
import { ArtifactParser } from "./ArtifactParser.js";
|
|
11
11
|
import { z } from "@hono/zod-openapi";
|
|
@@ -529,7 +529,8 @@ var ArtifactService = class ArtifactService {
|
|
|
529
529
|
full: fullData
|
|
530
530
|
}
|
|
531
531
|
}],
|
|
532
|
-
metadata: artifact.metadata || {}
|
|
532
|
+
metadata: artifact.metadata || {},
|
|
533
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
533
534
|
};
|
|
534
535
|
const result = await upsertLedgerArtifact(dbClient_default)({
|
|
535
536
|
scopes: {
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { ConversationSummary } from "../tools/distill-conversation-tool.js";
|
|
2
|
+
import { ModelSettings } from "@inkeep/agents-core";
|
|
3
|
+
|
|
4
|
+
//#region src/services/BaseCompressor.d.ts
|
|
5
|
+
interface CompressionConfig {
|
|
6
|
+
hardLimit: number;
|
|
7
|
+
safetyBuffer: number;
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface CompressionResult {
|
|
11
|
+
artifactIds: string[];
|
|
12
|
+
summary: any;
|
|
13
|
+
}
|
|
14
|
+
interface CompressionEventData {
|
|
15
|
+
reason: 'manual' | 'automatic';
|
|
16
|
+
messageCount: number;
|
|
17
|
+
artifactCount: number;
|
|
18
|
+
contextSizeBefore: number;
|
|
19
|
+
contextSizeAfter: number;
|
|
20
|
+
compressionType: 'mid_generation' | 'conversation_level';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Base compressor class containing shared functionality for all compression types
|
|
24
|
+
*/
|
|
25
|
+
declare abstract class BaseCompressor {
|
|
26
|
+
protected sessionId: string;
|
|
27
|
+
protected conversationId: string;
|
|
28
|
+
protected tenantId: string;
|
|
29
|
+
protected projectId: string;
|
|
30
|
+
protected config: CompressionConfig;
|
|
31
|
+
protected summarizerModel?: ModelSettings | undefined;
|
|
32
|
+
protected baseModel?: ModelSettings | undefined;
|
|
33
|
+
protected processedToolCalls: Set<string>;
|
|
34
|
+
protected cumulativeSummary: ConversationSummary | null;
|
|
35
|
+
constructor(sessionId: string, conversationId: string, tenantId: string, projectId: string, config: CompressionConfig, summarizerModel?: ModelSettings | undefined, baseModel?: ModelSettings | undefined);
|
|
36
|
+
/**
|
|
37
|
+
* Get the hard limit for compression decisions
|
|
38
|
+
*/
|
|
39
|
+
getHardLimit(): number;
|
|
40
|
+
/**
|
|
41
|
+
* Estimate tokens (4 chars = 1 token)
|
|
42
|
+
*/
|
|
43
|
+
protected estimateTokens(content: any): number;
|
|
44
|
+
/**
|
|
45
|
+
* Calculate total context size for messages
|
|
46
|
+
*/
|
|
47
|
+
protected calculateContextSize(messages: any[]): number;
|
|
48
|
+
/**
|
|
49
|
+
* Save tool results as artifacts
|
|
50
|
+
*/
|
|
51
|
+
saveToolResultsAsArtifacts(messages: any[], startIndex?: number): Promise<Record<string, string>>;
|
|
52
|
+
/**
|
|
53
|
+
* Extract all tool call IDs from messages for batch lookup
|
|
54
|
+
*/
|
|
55
|
+
private extractToolCallIds;
|
|
56
|
+
/**
|
|
57
|
+
* Batch lookup existing artifacts for multiple tool call IDs (solves N+1 query problem)
|
|
58
|
+
*/
|
|
59
|
+
private batchFindExistingArtifacts;
|
|
60
|
+
/**
|
|
61
|
+
* Query database for existing artifacts using enhanced getLedgerArtifacts with batch support
|
|
62
|
+
*/
|
|
63
|
+
private queryExistingArtifactsBatch;
|
|
64
|
+
/**
|
|
65
|
+
* Convert database format tool-result messages to Vercel AI SDK format
|
|
66
|
+
*/
|
|
67
|
+
private convertDatabaseFormatMessage;
|
|
68
|
+
/**
|
|
69
|
+
* Process all tool results in a message
|
|
70
|
+
*/
|
|
71
|
+
private processMessageToolResults;
|
|
72
|
+
/**
|
|
73
|
+
* Process a single tool result block
|
|
74
|
+
*/
|
|
75
|
+
private processToolResult;
|
|
76
|
+
/**
|
|
77
|
+
* Check if a tool should be skipped
|
|
78
|
+
*/
|
|
79
|
+
private shouldSkipToolCall;
|
|
80
|
+
/**
|
|
81
|
+
* Create a new artifact for a tool call
|
|
82
|
+
*/
|
|
83
|
+
private createNewArtifact;
|
|
84
|
+
/**
|
|
85
|
+
* Find tool input for a given tool call ID
|
|
86
|
+
*/
|
|
87
|
+
private findToolInput;
|
|
88
|
+
/**
|
|
89
|
+
* Build artifact data structure
|
|
90
|
+
*/
|
|
91
|
+
private buildArtifactData;
|
|
92
|
+
/**
|
|
93
|
+
* Validate artifact data has meaningful content
|
|
94
|
+
*/
|
|
95
|
+
private validateArtifactData;
|
|
96
|
+
/**
|
|
97
|
+
* Create conversation summary using distillConversation
|
|
98
|
+
*/
|
|
99
|
+
protected createConversationSummary(messages: any[], toolCallToArtifactMap: Record<string, string>): Promise<any>;
|
|
100
|
+
/**
|
|
101
|
+
* Record compression event in session
|
|
102
|
+
*/
|
|
103
|
+
/**
|
|
104
|
+
* Generate a preview of the tool result for the artifact summary
|
|
105
|
+
*/
|
|
106
|
+
protected generateResultPreview(toolResult: any): string;
|
|
107
|
+
protected recordCompressionEvent(eventData: CompressionEventData): void;
|
|
108
|
+
/**
|
|
109
|
+
* Check if tool result data is effectively empty
|
|
110
|
+
*/
|
|
111
|
+
protected isEmpty(toolResultData: any): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Recursively remove _structureHints from an object
|
|
114
|
+
*/
|
|
115
|
+
protected removeStructureHints(obj: any): any;
|
|
116
|
+
/**
|
|
117
|
+
* Get current compression summary
|
|
118
|
+
*/
|
|
119
|
+
getCompressionSummary(): ConversationSummary | null;
|
|
120
|
+
/**
|
|
121
|
+
* Clean up memory by clearing processed tool calls and optionally resetting summary
|
|
122
|
+
* Call this at the end of agent generation or after compression cycles
|
|
123
|
+
*/
|
|
124
|
+
cleanup(options?: {
|
|
125
|
+
resetSummary?: boolean;
|
|
126
|
+
keepRecentToolCalls?: number;
|
|
127
|
+
}): void;
|
|
128
|
+
/**
|
|
129
|
+
* Partial cleanup that preserves recent state for ongoing conversations
|
|
130
|
+
*/
|
|
131
|
+
partialCleanup(): void;
|
|
132
|
+
/**
|
|
133
|
+
* Full cleanup that resets all state - use when conversation/session ends
|
|
134
|
+
*/
|
|
135
|
+
fullCleanup(): void;
|
|
136
|
+
/**
|
|
137
|
+
* Get current state for debugging
|
|
138
|
+
*/
|
|
139
|
+
getState(): {
|
|
140
|
+
config: CompressionConfig;
|
|
141
|
+
processedToolCalls: string[];
|
|
142
|
+
cumulativeSummary: {
|
|
143
|
+
type: "conversation_summary_v1";
|
|
144
|
+
high_level: string;
|
|
145
|
+
user_intent: string;
|
|
146
|
+
decisions: string[];
|
|
147
|
+
open_questions: string[];
|
|
148
|
+
next_steps: {
|
|
149
|
+
for_agent: string[];
|
|
150
|
+
for_user: string[];
|
|
151
|
+
};
|
|
152
|
+
session_id?: string | null | undefined;
|
|
153
|
+
related_artifacts?: {
|
|
154
|
+
id: string;
|
|
155
|
+
name: string;
|
|
156
|
+
tool_name: string;
|
|
157
|
+
tool_call_id: string;
|
|
158
|
+
content_type: string;
|
|
159
|
+
key_findings: string[];
|
|
160
|
+
}[] | undefined;
|
|
161
|
+
} | null;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Safe compression wrapper with fallback handling
|
|
165
|
+
*/
|
|
166
|
+
safeCompress(messages: any[], fullContextSize?: number): Promise<CompressionResult>;
|
|
167
|
+
/**
|
|
168
|
+
* Simple compression fallback using the same logic as Agent.simpleCompression
|
|
169
|
+
* Returns the compressed messages, not just a summary
|
|
170
|
+
*/
|
|
171
|
+
protected simpleCompressionFallback(messages: any[]): Promise<CompressionResult>;
|
|
172
|
+
abstract isCompressionNeeded(messages: any[]): boolean;
|
|
173
|
+
abstract compress(messages: any[]): Promise<CompressionResult>;
|
|
174
|
+
abstract getCompressionType(): string;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Get model-aware compression config for any model
|
|
178
|
+
* @param modelSettings - Model settings to get context window for
|
|
179
|
+
* @param targetPercentage - Target percentage of context window (e.g., 0.5 for conversation, undefined for aggressive)
|
|
180
|
+
*/
|
|
181
|
+
declare function getModelAwareCompressionConfig(modelSettings?: ModelSettings, targetPercentage?: number): CompressionConfig;
|
|
182
|
+
//#endregion
|
|
183
|
+
export { BaseCompressor, CompressionConfig, CompressionEventData, CompressionResult, getModelAwareCompressionConfig };
|