@cognipeer/agent-sdk 0.4.6 → 0.4.8
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/index.cjs +88 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -20
- package/dist/index.d.ts +5 -20
- package/dist/index.mjs +88 -93
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -315,14 +315,6 @@ type SmartAgentToolResponseConfig = {
|
|
|
315
315
|
retryOnSchemaError?: boolean;
|
|
316
316
|
fallbackPolicy?: ToolResponseRetentionPolicy;
|
|
317
317
|
};
|
|
318
|
-
type SmartAgentWatchdogConfig = {
|
|
319
|
-
enabled?: boolean;
|
|
320
|
-
tokenDriftThreshold?: number;
|
|
321
|
-
overToolingSpikeThreshold?: number;
|
|
322
|
-
contextRotThreshold?: number;
|
|
323
|
-
autoCompaction?: boolean;
|
|
324
|
-
autoReplanOnFailure?: boolean;
|
|
325
|
-
};
|
|
326
318
|
type SmartAgentCustomProfileConfig = {
|
|
327
319
|
extends?: BuiltInRuntimeProfile;
|
|
328
320
|
limits?: AgentLimits;
|
|
@@ -332,7 +324,6 @@ type SmartAgentCustomProfileConfig = {
|
|
|
332
324
|
memory?: SmartAgentMemoryConfig;
|
|
333
325
|
delegation?: SmartAgentDelegationConfig;
|
|
334
326
|
toolResponses?: SmartAgentToolResponseConfig;
|
|
335
|
-
watchdog?: SmartAgentWatchdogConfig;
|
|
336
327
|
};
|
|
337
328
|
type ProfileConfig = {
|
|
338
329
|
limits: Required<AgentLimits>;
|
|
@@ -346,7 +337,6 @@ type ProfileConfig = {
|
|
|
346
337
|
};
|
|
347
338
|
delegation: Required<SmartAgentDelegationConfig>;
|
|
348
339
|
toolResponses: Required<SmartAgentToolResponseConfig>;
|
|
349
|
-
watchdog: Required<SmartAgentWatchdogConfig>;
|
|
350
340
|
};
|
|
351
341
|
type ResolvedSmartAgentConfig = ProfileConfig & {
|
|
352
342
|
runtimeProfile: RuntimeProfile;
|
|
@@ -368,7 +358,6 @@ type SmartAgentOptions = {
|
|
|
368
358
|
planning?: SmartAgentPlanningConfig;
|
|
369
359
|
delegation?: SmartAgentDelegationConfig;
|
|
370
360
|
toolResponses?: SmartAgentToolResponseConfig;
|
|
371
|
-
watchdog?: SmartAgentWatchdogConfig;
|
|
372
361
|
systemPrompt?: string;
|
|
373
362
|
todoListPrompt?: string;
|
|
374
363
|
/** @deprecated Use planning.mode="todo" */
|
|
@@ -673,13 +662,6 @@ type SmartState = AgentState & {
|
|
|
673
662
|
adherenceScore?: number;
|
|
674
663
|
} | null;
|
|
675
664
|
planVersion?: number;
|
|
676
|
-
watchdog?: {
|
|
677
|
-
tokenDrift?: number;
|
|
678
|
-
contextRotScore?: number;
|
|
679
|
-
overToolingRate?: number;
|
|
680
|
-
compactions?: number;
|
|
681
|
-
lastAction?: string;
|
|
682
|
-
};
|
|
683
665
|
};
|
|
684
666
|
type ToolCallEvent = {
|
|
685
667
|
type: "tool_call";
|
|
@@ -866,6 +848,9 @@ type CancellationTokenLike = {
|
|
|
866
848
|
dispose(): void;
|
|
867
849
|
} | void;
|
|
868
850
|
};
|
|
851
|
+
type AbortSignalLike = {
|
|
852
|
+
readonly aborted: boolean;
|
|
853
|
+
};
|
|
869
854
|
type ProgressUpdate = {
|
|
870
855
|
stage?: string;
|
|
871
856
|
message?: string;
|
|
@@ -881,7 +866,7 @@ type InvokeConfig = RunnableConfig & {
|
|
|
881
866
|
onProgress?: (progress: ProgressUpdate) => void;
|
|
882
867
|
onStream?: (chunk: StreamChunk) => void;
|
|
883
868
|
stream?: boolean;
|
|
884
|
-
cancellationToken?: CancellationTokenLike |
|
|
869
|
+
cancellationToken?: CancellationTokenLike | AbortSignalLike;
|
|
885
870
|
timeoutMs?: number;
|
|
886
871
|
limits?: Partial<AgentLimits>;
|
|
887
872
|
onStateChange?: (state: SmartState) => boolean;
|
|
@@ -1228,4 +1213,4 @@ declare function generateSpanId(): string;
|
|
|
1228
1213
|
*/
|
|
1229
1214
|
declare function startStreamingSession(session: TraceSessionRuntime | undefined, agentRuntime?: AgentRuntimeConfig): Promise<void>;
|
|
1230
1215
|
|
|
1231
|
-
export { type AIMessage, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentRuleOptions, type AgentRuntimeConfig, type AgentSnapshot, type AgentSnapshotMetadata, type AgentState, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type BaseMessage, type BuiltInRuntimeProfile, type CancellationTokenLike, type CancelledEvent, type ChildContextPolicy, type CodeDetectionRuleOptions, type CodeGuardrailOptions, type ContextPolicy, type ConversationGuardrail, type CustomRuleCallback, type CustomRuleOptions, DEFAULT_PROFILE_CONFIGS, type DelegationMode, type EvalCase, type EvalCaseResult, type EvalFamily, type EvalHarnessMetrics, type EvalHarnessParams, type EvalHarnessResult, type EvalProfileDescriptor, type EvalProfileTarget, type FinalAnswerEvent, type GuardrailContext, type GuardrailDisposition, type GuardrailEvent, type GuardrailIncident, type GuardrailOutcome, GuardrailPhase, type GuardrailRule, type HandoffDescriptor, type HandoffEvent, InMemoryMemoryStore, type InvokeConfig, type JsonGuardrailOptions, type JsonSchemaRuleOptions, type MemoryFact, type MemoryProviderKind, type MemoryReadPolicy, type MemoryScope, type MemoryStore, type MemoryWritePolicy, type Message, type MetadataEvent, type PendingToolApproval, type PlanEvent, type PlanStepRecord, type PlanningMode, type ProfileConfig, type ProgressEvent, type ProgressUpdate, type RegexGuardrailOptions, type RegexRuleOptions, type ReplanPolicy, type ResolvedSmartAgentConfig, type ResolvedTraceConfig, type ResolvedTraceSink, type RestoreSnapshotOptions, type RuntimeProfile, type SerializableSmartState, type SmartAgentBudgetConfig, type SmartAgentContextConfig, type SmartAgentCustomProfileConfig, type SmartAgentDelegationConfig, type SmartAgentEvent, type SmartAgentInstance, type SmartAgentLimits, type SmartAgentMemoryConfig, type SmartAgentOptions, type SmartAgentPlanningConfig, type SmartAgentSummarizationConfig, type SmartAgentToolResponseConfig, type SmartAgentTracingConfig, type
|
|
1216
|
+
export { type AIMessage, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentRuleOptions, type AgentRuntimeConfig, type AgentSnapshot, type AgentSnapshotMetadata, type AgentState, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type BaseMessage, type BuiltInRuntimeProfile, type CancellationTokenLike, type CancelledEvent, type ChildContextPolicy, type CodeDetectionRuleOptions, type CodeGuardrailOptions, type ContextPolicy, type ConversationGuardrail, type CustomRuleCallback, type CustomRuleOptions, DEFAULT_PROFILE_CONFIGS, type DelegationMode, type EvalCase, type EvalCaseResult, type EvalFamily, type EvalHarnessMetrics, type EvalHarnessParams, type EvalHarnessResult, type EvalProfileDescriptor, type EvalProfileTarget, type FinalAnswerEvent, type GuardrailContext, type GuardrailDisposition, type GuardrailEvent, type GuardrailIncident, type GuardrailOutcome, GuardrailPhase, type GuardrailRule, type HandoffDescriptor, type HandoffEvent, InMemoryMemoryStore, type InvokeConfig, type JsonGuardrailOptions, type JsonSchemaRuleOptions, type MemoryFact, type MemoryProviderKind, type MemoryReadPolicy, type MemoryScope, type MemoryStore, type MemoryWritePolicy, type Message, type MetadataEvent, type PendingToolApproval, type PlanEvent, type PlanStepRecord, type PlanningMode, type ProfileConfig, type ProgressEvent, type ProgressUpdate, type RegexGuardrailOptions, type RegexRuleOptions, type ReplanPolicy, type ResolvedSmartAgentConfig, type ResolvedTraceConfig, type ResolvedTraceSink, type RestoreSnapshotOptions, type RuntimeProfile, type SerializableSmartState, type SmartAgentBudgetConfig, type SmartAgentContextConfig, type SmartAgentCustomProfileConfig, type SmartAgentDelegationConfig, type SmartAgentEvent, type SmartAgentInstance, type SmartAgentLimits, type SmartAgentMemoryConfig, type SmartAgentOptions, type SmartAgentPlanningConfig, type SmartAgentSummarizationConfig, type SmartAgentToolResponseConfig, type SmartAgentTracingConfig, type SmartModel, type SmartState, type SmartToolFn, type SnapshotOptions, type SnapshotRuntimeHint, type StreamChunk, type StreamEvent, type StructuredSummary, type SummarizationEvent, type SummarizationMode, type SummaryFactItem, type SummaryIntegrityCheck, type TokenLimits, type ToolApprovalEvent, type ToolApprovalResolution, type ToolApprovalStatus, type ToolCallEvent, type ToolInterface, type ToolResponseClassification, type ToolResponseRetentionPolicy, type TraceDataSection, type TraceErrorRecord, type TraceEventRecord, type TraceMessageSection, type TraceMetadataSection, type TraceSessionConfigSnapshot, type TraceSessionFile, type TraceSessionStatus, type TraceSessionSummary, type TraceSinkCognipeerConfig, type TraceSinkConfig, type TraceSinkCustomConfig, type TraceSinkFileConfig, type TraceSinkHttpConfig, type TraceSinkOtlpConfig, type TraceSinkSnapshot, type TraceSummarySection, type TraceToolCallSection, type TraceToolResultSection, type TracingConfig, type TracingMode, agentVerdictRule, applyTokenLimits, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGuardrail, createJsonGuardrail, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, evaluateGuardrails, fileSink, fromLangchainModel, fromLangchainTools, generateSpanId, generateTraceId, getResolvedSmartConfig, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, renderMemoryFacts, resolveMemoryStore, resolveToolApprovalState, restoreSnapshot, runSmartAgentEvalHarness, startStreamingSession, traceSessionToOtlp, withTools, writeSummaryFactsToMemory };
|
package/dist/index.d.ts
CHANGED
|
@@ -315,14 +315,6 @@ type SmartAgentToolResponseConfig = {
|
|
|
315
315
|
retryOnSchemaError?: boolean;
|
|
316
316
|
fallbackPolicy?: ToolResponseRetentionPolicy;
|
|
317
317
|
};
|
|
318
|
-
type SmartAgentWatchdogConfig = {
|
|
319
|
-
enabled?: boolean;
|
|
320
|
-
tokenDriftThreshold?: number;
|
|
321
|
-
overToolingSpikeThreshold?: number;
|
|
322
|
-
contextRotThreshold?: number;
|
|
323
|
-
autoCompaction?: boolean;
|
|
324
|
-
autoReplanOnFailure?: boolean;
|
|
325
|
-
};
|
|
326
318
|
type SmartAgentCustomProfileConfig = {
|
|
327
319
|
extends?: BuiltInRuntimeProfile;
|
|
328
320
|
limits?: AgentLimits;
|
|
@@ -332,7 +324,6 @@ type SmartAgentCustomProfileConfig = {
|
|
|
332
324
|
memory?: SmartAgentMemoryConfig;
|
|
333
325
|
delegation?: SmartAgentDelegationConfig;
|
|
334
326
|
toolResponses?: SmartAgentToolResponseConfig;
|
|
335
|
-
watchdog?: SmartAgentWatchdogConfig;
|
|
336
327
|
};
|
|
337
328
|
type ProfileConfig = {
|
|
338
329
|
limits: Required<AgentLimits>;
|
|
@@ -346,7 +337,6 @@ type ProfileConfig = {
|
|
|
346
337
|
};
|
|
347
338
|
delegation: Required<SmartAgentDelegationConfig>;
|
|
348
339
|
toolResponses: Required<SmartAgentToolResponseConfig>;
|
|
349
|
-
watchdog: Required<SmartAgentWatchdogConfig>;
|
|
350
340
|
};
|
|
351
341
|
type ResolvedSmartAgentConfig = ProfileConfig & {
|
|
352
342
|
runtimeProfile: RuntimeProfile;
|
|
@@ -368,7 +358,6 @@ type SmartAgentOptions = {
|
|
|
368
358
|
planning?: SmartAgentPlanningConfig;
|
|
369
359
|
delegation?: SmartAgentDelegationConfig;
|
|
370
360
|
toolResponses?: SmartAgentToolResponseConfig;
|
|
371
|
-
watchdog?: SmartAgentWatchdogConfig;
|
|
372
361
|
systemPrompt?: string;
|
|
373
362
|
todoListPrompt?: string;
|
|
374
363
|
/** @deprecated Use planning.mode="todo" */
|
|
@@ -673,13 +662,6 @@ type SmartState = AgentState & {
|
|
|
673
662
|
adherenceScore?: number;
|
|
674
663
|
} | null;
|
|
675
664
|
planVersion?: number;
|
|
676
|
-
watchdog?: {
|
|
677
|
-
tokenDrift?: number;
|
|
678
|
-
contextRotScore?: number;
|
|
679
|
-
overToolingRate?: number;
|
|
680
|
-
compactions?: number;
|
|
681
|
-
lastAction?: string;
|
|
682
|
-
};
|
|
683
665
|
};
|
|
684
666
|
type ToolCallEvent = {
|
|
685
667
|
type: "tool_call";
|
|
@@ -866,6 +848,9 @@ type CancellationTokenLike = {
|
|
|
866
848
|
dispose(): void;
|
|
867
849
|
} | void;
|
|
868
850
|
};
|
|
851
|
+
type AbortSignalLike = {
|
|
852
|
+
readonly aborted: boolean;
|
|
853
|
+
};
|
|
869
854
|
type ProgressUpdate = {
|
|
870
855
|
stage?: string;
|
|
871
856
|
message?: string;
|
|
@@ -881,7 +866,7 @@ type InvokeConfig = RunnableConfig & {
|
|
|
881
866
|
onProgress?: (progress: ProgressUpdate) => void;
|
|
882
867
|
onStream?: (chunk: StreamChunk) => void;
|
|
883
868
|
stream?: boolean;
|
|
884
|
-
cancellationToken?: CancellationTokenLike |
|
|
869
|
+
cancellationToken?: CancellationTokenLike | AbortSignalLike;
|
|
885
870
|
timeoutMs?: number;
|
|
886
871
|
limits?: Partial<AgentLimits>;
|
|
887
872
|
onStateChange?: (state: SmartState) => boolean;
|
|
@@ -1228,4 +1213,4 @@ declare function generateSpanId(): string;
|
|
|
1228
1213
|
*/
|
|
1229
1214
|
declare function startStreamingSession(session: TraceSessionRuntime | undefined, agentRuntime?: AgentRuntimeConfig): Promise<void>;
|
|
1230
1215
|
|
|
1231
|
-
export { type AIMessage, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentRuleOptions, type AgentRuntimeConfig, type AgentSnapshot, type AgentSnapshotMetadata, type AgentState, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type BaseMessage, type BuiltInRuntimeProfile, type CancellationTokenLike, type CancelledEvent, type ChildContextPolicy, type CodeDetectionRuleOptions, type CodeGuardrailOptions, type ContextPolicy, type ConversationGuardrail, type CustomRuleCallback, type CustomRuleOptions, DEFAULT_PROFILE_CONFIGS, type DelegationMode, type EvalCase, type EvalCaseResult, type EvalFamily, type EvalHarnessMetrics, type EvalHarnessParams, type EvalHarnessResult, type EvalProfileDescriptor, type EvalProfileTarget, type FinalAnswerEvent, type GuardrailContext, type GuardrailDisposition, type GuardrailEvent, type GuardrailIncident, type GuardrailOutcome, GuardrailPhase, type GuardrailRule, type HandoffDescriptor, type HandoffEvent, InMemoryMemoryStore, type InvokeConfig, type JsonGuardrailOptions, type JsonSchemaRuleOptions, type MemoryFact, type MemoryProviderKind, type MemoryReadPolicy, type MemoryScope, type MemoryStore, type MemoryWritePolicy, type Message, type MetadataEvent, type PendingToolApproval, type PlanEvent, type PlanStepRecord, type PlanningMode, type ProfileConfig, type ProgressEvent, type ProgressUpdate, type RegexGuardrailOptions, type RegexRuleOptions, type ReplanPolicy, type ResolvedSmartAgentConfig, type ResolvedTraceConfig, type ResolvedTraceSink, type RestoreSnapshotOptions, type RuntimeProfile, type SerializableSmartState, type SmartAgentBudgetConfig, type SmartAgentContextConfig, type SmartAgentCustomProfileConfig, type SmartAgentDelegationConfig, type SmartAgentEvent, type SmartAgentInstance, type SmartAgentLimits, type SmartAgentMemoryConfig, type SmartAgentOptions, type SmartAgentPlanningConfig, type SmartAgentSummarizationConfig, type SmartAgentToolResponseConfig, type SmartAgentTracingConfig, type
|
|
1216
|
+
export { type AIMessage, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentRuleOptions, type AgentRuntimeConfig, type AgentSnapshot, type AgentSnapshotMetadata, type AgentState, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type BaseMessage, type BuiltInRuntimeProfile, type CancellationTokenLike, type CancelledEvent, type ChildContextPolicy, type CodeDetectionRuleOptions, type CodeGuardrailOptions, type ContextPolicy, type ConversationGuardrail, type CustomRuleCallback, type CustomRuleOptions, DEFAULT_PROFILE_CONFIGS, type DelegationMode, type EvalCase, type EvalCaseResult, type EvalFamily, type EvalHarnessMetrics, type EvalHarnessParams, type EvalHarnessResult, type EvalProfileDescriptor, type EvalProfileTarget, type FinalAnswerEvent, type GuardrailContext, type GuardrailDisposition, type GuardrailEvent, type GuardrailIncident, type GuardrailOutcome, GuardrailPhase, type GuardrailRule, type HandoffDescriptor, type HandoffEvent, InMemoryMemoryStore, type InvokeConfig, type JsonGuardrailOptions, type JsonSchemaRuleOptions, type MemoryFact, type MemoryProviderKind, type MemoryReadPolicy, type MemoryScope, type MemoryStore, type MemoryWritePolicy, type Message, type MetadataEvent, type PendingToolApproval, type PlanEvent, type PlanStepRecord, type PlanningMode, type ProfileConfig, type ProgressEvent, type ProgressUpdate, type RegexGuardrailOptions, type RegexRuleOptions, type ReplanPolicy, type ResolvedSmartAgentConfig, type ResolvedTraceConfig, type ResolvedTraceSink, type RestoreSnapshotOptions, type RuntimeProfile, type SerializableSmartState, type SmartAgentBudgetConfig, type SmartAgentContextConfig, type SmartAgentCustomProfileConfig, type SmartAgentDelegationConfig, type SmartAgentEvent, type SmartAgentInstance, type SmartAgentLimits, type SmartAgentMemoryConfig, type SmartAgentOptions, type SmartAgentPlanningConfig, type SmartAgentSummarizationConfig, type SmartAgentToolResponseConfig, type SmartAgentTracingConfig, type SmartModel, type SmartState, type SmartToolFn, type SnapshotOptions, type SnapshotRuntimeHint, type StreamChunk, type StreamEvent, type StructuredSummary, type SummarizationEvent, type SummarizationMode, type SummaryFactItem, type SummaryIntegrityCheck, type TokenLimits, type ToolApprovalEvent, type ToolApprovalResolution, type ToolApprovalStatus, type ToolCallEvent, type ToolInterface, type ToolResponseClassification, type ToolResponseRetentionPolicy, type TraceDataSection, type TraceErrorRecord, type TraceEventRecord, type TraceMessageSection, type TraceMetadataSection, type TraceSessionConfigSnapshot, type TraceSessionFile, type TraceSessionStatus, type TraceSessionSummary, type TraceSinkCognipeerConfig, type TraceSinkConfig, type TraceSinkCustomConfig, type TraceSinkFileConfig, type TraceSinkHttpConfig, type TraceSinkOtlpConfig, type TraceSinkSnapshot, type TraceSummarySection, type TraceToolCallSection, type TraceToolResultSection, type TracingConfig, type TracingMode, agentVerdictRule, applyTokenLimits, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGuardrail, createJsonGuardrail, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, evaluateGuardrails, fileSink, fromLangchainModel, fromLangchainTools, generateSpanId, generateTraceId, getResolvedSmartConfig, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, renderMemoryFacts, resolveMemoryStore, resolveToolApprovalState, restoreSnapshot, runSmartAgentEvalHarness, startStreamingSession, traceSessionToOtlp, withTools, writeSummaryFactsToMemory };
|
package/dist/index.mjs
CHANGED
|
@@ -1783,14 +1783,6 @@ var DEFAULT_PROFILE_CONFIGS = {
|
|
|
1783
1783
|
schemaValidation: "strict",
|
|
1784
1784
|
retryOnSchemaError: true,
|
|
1785
1785
|
fallbackPolicy: "keep_structured"
|
|
1786
|
-
},
|
|
1787
|
-
watchdog: {
|
|
1788
|
-
enabled: true,
|
|
1789
|
-
tokenDriftThreshold: 1200,
|
|
1790
|
-
overToolingSpikeThreshold: 0.7,
|
|
1791
|
-
contextRotThreshold: 0.65,
|
|
1792
|
-
autoCompaction: true,
|
|
1793
|
-
autoReplanOnFailure: true
|
|
1794
1786
|
}
|
|
1795
1787
|
},
|
|
1796
1788
|
balanced: {
|
|
@@ -1848,14 +1840,6 @@ var DEFAULT_PROFILE_CONFIGS = {
|
|
|
1848
1840
|
schemaValidation: "strict",
|
|
1849
1841
|
retryOnSchemaError: true,
|
|
1850
1842
|
fallbackPolicy: "keep_structured"
|
|
1851
|
-
},
|
|
1852
|
-
watchdog: {
|
|
1853
|
-
enabled: true,
|
|
1854
|
-
tokenDriftThreshold: 1800,
|
|
1855
|
-
overToolingSpikeThreshold: 0.6,
|
|
1856
|
-
contextRotThreshold: 0.55,
|
|
1857
|
-
autoCompaction: true,
|
|
1858
|
-
autoReplanOnFailure: true
|
|
1859
1843
|
}
|
|
1860
1844
|
},
|
|
1861
1845
|
deep: {
|
|
@@ -1913,14 +1897,6 @@ var DEFAULT_PROFILE_CONFIGS = {
|
|
|
1913
1897
|
schemaValidation: "strict",
|
|
1914
1898
|
retryOnSchemaError: true,
|
|
1915
1899
|
fallbackPolicy: "keep_structured"
|
|
1916
|
-
},
|
|
1917
|
-
watchdog: {
|
|
1918
|
-
enabled: true,
|
|
1919
|
-
tokenDriftThreshold: 2200,
|
|
1920
|
-
overToolingSpikeThreshold: 0.55,
|
|
1921
|
-
contextRotThreshold: 0.5,
|
|
1922
|
-
autoCompaction: true,
|
|
1923
|
-
autoReplanOnFailure: true
|
|
1924
1900
|
}
|
|
1925
1901
|
},
|
|
1926
1902
|
research: {
|
|
@@ -1978,14 +1954,6 @@ var DEFAULT_PROFILE_CONFIGS = {
|
|
|
1978
1954
|
schemaValidation: "strict",
|
|
1979
1955
|
retryOnSchemaError: true,
|
|
1980
1956
|
fallbackPolicy: "keep_structured"
|
|
1981
|
-
},
|
|
1982
|
-
watchdog: {
|
|
1983
|
-
enabled: true,
|
|
1984
|
-
tokenDriftThreshold: 2600,
|
|
1985
|
-
overToolingSpikeThreshold: 0.5,
|
|
1986
|
-
contextRotThreshold: 0.45,
|
|
1987
|
-
autoCompaction: true,
|
|
1988
|
-
autoReplanOnFailure: true
|
|
1989
1957
|
}
|
|
1990
1958
|
}
|
|
1991
1959
|
};
|
|
@@ -2062,11 +2030,6 @@ function normalizeSmartAgentOptions(opts) {
|
|
|
2062
2030
|
...opts.toolResponses?.toolResponseRetentionByTool || {}
|
|
2063
2031
|
},
|
|
2064
2032
|
criticalTools: opts.toolResponses?.criticalTools ?? customProfile.toolResponses?.criticalTools ?? preset.toolResponses.criticalTools
|
|
2065
|
-
},
|
|
2066
|
-
watchdog: {
|
|
2067
|
-
...preset.watchdog,
|
|
2068
|
-
...customProfile.watchdog || {},
|
|
2069
|
-
...opts.watchdog || {}
|
|
2070
2033
|
}
|
|
2071
2034
|
};
|
|
2072
2035
|
}
|
|
@@ -2297,7 +2260,7 @@ function createToolsNode(initialTools, opts) {
|
|
|
2297
2260
|
if (toolCallId) {
|
|
2298
2261
|
ctx.__toolSchemaError = { toolName, toolCallId, message };
|
|
2299
2262
|
}
|
|
2300
|
-
if (resolved.
|
|
2263
|
+
if (resolved.planning.replanPolicy === "on_failure") {
|
|
2301
2264
|
ctx.__planNeedsReplan = true;
|
|
2302
2265
|
}
|
|
2303
2266
|
state.ctx = ctx;
|
|
@@ -2902,6 +2865,24 @@ function getLastAssistantMessage(messages) {
|
|
|
2902
2865
|
}
|
|
2903
2866
|
return void 0;
|
|
2904
2867
|
}
|
|
2868
|
+
function getActiveSummarizationThreshold(opts) {
|
|
2869
|
+
const summarization = opts.summarization;
|
|
2870
|
+
if (!summarization || typeof summarization !== "object" || summarization.enable === false) {
|
|
2871
|
+
return void 0;
|
|
2872
|
+
}
|
|
2873
|
+
return summarization.summaryTriggerTokens || summarization.maxTokens || opts.limits?.maxContextTokens || 5e4;
|
|
2874
|
+
}
|
|
2875
|
+
function clearNeedsSummarization(state) {
|
|
2876
|
+
if (!state.ctx?.__needsSummarization) {
|
|
2877
|
+
return state;
|
|
2878
|
+
}
|
|
2879
|
+
const nextCtx = { ...state.ctx || {} };
|
|
2880
|
+
delete nextCtx.__needsSummarization;
|
|
2881
|
+
return {
|
|
2882
|
+
...state,
|
|
2883
|
+
ctx: Object.keys(nextCtx).length > 0 ? nextCtx : void 0
|
|
2884
|
+
};
|
|
2885
|
+
}
|
|
2905
2886
|
function createAgent(opts) {
|
|
2906
2887
|
const resolver = createResolverNode();
|
|
2907
2888
|
const agentCore = createAgentCoreNode(opts);
|
|
@@ -2950,6 +2931,7 @@ function createAgent(opts) {
|
|
|
2950
2931
|
outputSchema: opts.outputSchema,
|
|
2951
2932
|
tracing: opts.tracing
|
|
2952
2933
|
};
|
|
2934
|
+
const summarizationThreshold = getActiveSummarizationThreshold(opts);
|
|
2953
2935
|
async function runLoop(initial, config, emit) {
|
|
2954
2936
|
let state = await resolver(initial);
|
|
2955
2937
|
if (state.ctx?.__paused) {
|
|
@@ -2966,6 +2948,9 @@ function createAgent(opts) {
|
|
|
2966
2948
|
delete nextCtx.__resumeStage;
|
|
2967
2949
|
state = { ...state, ctx: Object.keys(nextCtx).length > 0 ? nextCtx : void 0 };
|
|
2968
2950
|
}
|
|
2951
|
+
if (summarizationThreshold === void 0) {
|
|
2952
|
+
state = clearNeedsSummarization(state);
|
|
2953
|
+
}
|
|
2969
2954
|
const mergedLimits = {
|
|
2970
2955
|
...opts.limits || {},
|
|
2971
2956
|
...config?.limits || {}
|
|
@@ -3074,25 +3059,18 @@ function createAgent(opts) {
|
|
|
3074
3059
|
}
|
|
3075
3060
|
}
|
|
3076
3061
|
}
|
|
3077
|
-
|
|
3078
|
-
if (opts.summarization && typeof opts.summarization === "object") {
|
|
3079
|
-
maxTok = opts.summarization.summaryTriggerTokens || opts.summarization.maxTokens;
|
|
3080
|
-
}
|
|
3081
|
-
if (maxTok === void 0) {
|
|
3082
|
-
maxTok = 5e4;
|
|
3083
|
-
}
|
|
3084
|
-
if (maxTok) {
|
|
3062
|
+
if (summarizationThreshold !== void 0) {
|
|
3085
3063
|
const tokCountMessages = (state.messages || []).filter((message) => {
|
|
3086
3064
|
if (isSyntheticSummaryMessage(message)) return false;
|
|
3087
3065
|
if (message.role === "system" && (message.name === "context_summary" || message.name === "memory_context")) return false;
|
|
3088
3066
|
return true;
|
|
3089
3067
|
});
|
|
3090
3068
|
const tokenCount = countMessagesTokens(tokCountMessages);
|
|
3091
|
-
if (tokenCount >
|
|
3069
|
+
if (tokenCount > summarizationThreshold) {
|
|
3092
3070
|
const hasFreshSummary = (state.messages || []).some(
|
|
3093
3071
|
(m) => m.role === "tool" && typeof m.content === "string" && (m.content === "SUMMARIZED" || m.content.startsWith("SUMMARIZED_TOOL_RESPONSE"))
|
|
3094
3072
|
);
|
|
3095
|
-
if (hasFreshSummary && tokenCount <=
|
|
3073
|
+
if (hasFreshSummary && tokenCount <= summarizationThreshold * 1.15) ; else {
|
|
3096
3074
|
const ctx = { ...state.ctx || {}, __needsSummarization: true };
|
|
3097
3075
|
state = { ...state, ctx };
|
|
3098
3076
|
break;
|
|
@@ -3581,15 +3559,6 @@ function buildModelMessages(state, config) {
|
|
|
3581
3559
|
];
|
|
3582
3560
|
return clampToBudget(assembled, config.limits.maxContextTokens);
|
|
3583
3561
|
}
|
|
3584
|
-
function estimateContextRotScore(state) {
|
|
3585
|
-
const summaryCount = state.summaryRecords?.length || 0;
|
|
3586
|
-
const archivedCount = state.toolHistoryArchived?.length || 0;
|
|
3587
|
-
const messageCount = state.messages?.length || 0;
|
|
3588
|
-
const summarizedMessages = state.messages?.filter((message) => message.role === "tool" && typeof message.content === "string" && (message.content === "SUMMARIZED" || message.content.startsWith("SUMMARIZED_TOOL_RESPONSE"))).length || 0;
|
|
3589
|
-
const numerator = summaryCount * 2 + archivedCount + summarizedMessages;
|
|
3590
|
-
const denominator = Math.max(messageCount, 1);
|
|
3591
|
-
return Number((numerator / denominator).toFixed(3));
|
|
3592
|
-
}
|
|
3593
3562
|
|
|
3594
3563
|
// src/nodes/contextSummarize.ts
|
|
3595
3564
|
var systemMessage = (content) => ({ role: "system", content });
|
|
@@ -3734,6 +3703,9 @@ function findToolHistoryEntry(state, toolCallId, toolName) {
|
|
|
3734
3703
|
}
|
|
3735
3704
|
}
|
|
3736
3705
|
}
|
|
3706
|
+
if (!toolName) {
|
|
3707
|
+
return void 0;
|
|
3708
|
+
}
|
|
3737
3709
|
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
3738
3710
|
const entry = entries[index];
|
|
3739
3711
|
if (entry?.toolName === toolName) {
|
|
@@ -3822,8 +3794,20 @@ function createContextSummarizeNode(opts) {
|
|
|
3822
3794
|
const messages = state.messages || [];
|
|
3823
3795
|
const onEvent = state.ctx?.__onEvent;
|
|
3824
3796
|
const traceSession = state.ctx?.__traceSession;
|
|
3797
|
+
const toolResponsesConfigEarly = resolved.toolResponses;
|
|
3825
3798
|
const compressableMessages = messages.filter(
|
|
3826
|
-
(m) =>
|
|
3799
|
+
(m) => {
|
|
3800
|
+
if (m.role !== "tool") return false;
|
|
3801
|
+
if (isSummarizedToolPlaceholder(m.content)) return false;
|
|
3802
|
+
if (isSyntheticSummaryToolMessage(m)) return false;
|
|
3803
|
+
const histEntry = findToolHistoryEntry(state, m.tool_call_id, m.name);
|
|
3804
|
+
if (histEntry?.retentionPolicy === "keep_full") return false;
|
|
3805
|
+
if (!histEntry?.retentionPolicy) {
|
|
3806
|
+
const byTool = toolResponsesConfigEarly.toolResponseRetentionByTool?.[m.name || ""];
|
|
3807
|
+
if ((byTool || toolResponsesConfigEarly.defaultPolicy) === "keep_full") return false;
|
|
3808
|
+
}
|
|
3809
|
+
return true;
|
|
3810
|
+
}
|
|
3827
3811
|
);
|
|
3828
3812
|
if (compressableMessages.length === 0) {
|
|
3829
3813
|
return {};
|
|
@@ -3844,6 +3828,13 @@ function createContextSummarizeNode(opts) {
|
|
|
3844
3828
|
else if (Array.isArray(m.content)) {
|
|
3845
3829
|
content = m.content.map((c) => c.text || JSON.stringify(c)).join(" ");
|
|
3846
3830
|
}
|
|
3831
|
+
if (m.role === "tool" && isSummarizedToolPlaceholder(content)) {
|
|
3832
|
+
const historyEntry = findToolHistoryEntry(state, m.tool_call_id, m.name);
|
|
3833
|
+
if (historyEntry) {
|
|
3834
|
+
const original = historyEntry.rawOutput ?? historyEntry.output;
|
|
3835
|
+
content = typeof original === "string" ? original : JSON.stringify(original);
|
|
3836
|
+
}
|
|
3837
|
+
}
|
|
3847
3838
|
const maxContentLength = 2e3;
|
|
3848
3839
|
if (content.length > maxContentLength) {
|
|
3849
3840
|
content = content.substring(0, maxContentLength) + "... [TRUNCATED]";
|
|
@@ -3979,6 +3970,23 @@ ${canonicalFacts.length > 0 ? canonicalFacts.map((fact) => `- ${fact.key}: ${fac
|
|
|
3979
3970
|
});
|
|
3980
3971
|
}
|
|
3981
3972
|
});
|
|
3973
|
+
const protectedToolCallIds = /* @__PURE__ */ new Set();
|
|
3974
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
3975
|
+
const m = messages[i];
|
|
3976
|
+
if (m.role === "assistant" && Array.isArray(m.tool_calls) && m.tool_calls.length > 0) {
|
|
3977
|
+
const thisToolCallIds = new Set(m.tool_calls.map((tc) => tc.id).filter(Boolean));
|
|
3978
|
+
const otherCompressable = compressableMessages.filter(
|
|
3979
|
+
(cm) => !thisToolCallIds.has(cm.tool_call_id)
|
|
3980
|
+
);
|
|
3981
|
+
if (otherCompressable.length > 0) {
|
|
3982
|
+
for (const tc of m.tool_calls) {
|
|
3983
|
+
if (tc.id) protectedToolCallIds.add(tc.id);
|
|
3984
|
+
}
|
|
3985
|
+
}
|
|
3986
|
+
break;
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
const toolResponsesConfig = resolved.toolResponses;
|
|
3982
3990
|
const newMessages = messages.map((m) => {
|
|
3983
3991
|
if (m.role === "tool") {
|
|
3984
3992
|
if (isSyntheticSummaryToolMessage(m)) {
|
|
@@ -3989,6 +3997,16 @@ ${canonicalFacts.length > 0 ? canonicalFacts.map((fact) => `- ${fact.key}: ${fac
|
|
|
3989
3997
|
return null;
|
|
3990
3998
|
}
|
|
3991
3999
|
if (isSummarizedToolPlaceholder(m.content)) return m;
|
|
4000
|
+
if (toolCallId && protectedToolCallIds.has(toolCallId)) return m;
|
|
4001
|
+
const toolName = m.name || "";
|
|
4002
|
+
const historyEntry = findToolHistoryEntry(state, toolCallId, toolName);
|
|
4003
|
+
const entryRetention = historyEntry?.retentionPolicy;
|
|
4004
|
+
if (entryRetention === "keep_full") return m;
|
|
4005
|
+
if (!entryRetention) {
|
|
4006
|
+
const byTool = toolResponsesConfig.toolResponseRetentionByTool?.[toolName];
|
|
4007
|
+
const configPolicy = byTool || toolResponsesConfig.defaultPolicy;
|
|
4008
|
+
if (configPolicy === "keep_full") return m;
|
|
4009
|
+
}
|
|
3992
4010
|
return {
|
|
3993
4011
|
...m,
|
|
3994
4012
|
content: buildSummarizedToolMessage(m, state)
|
|
@@ -3996,6 +4014,12 @@ ${canonicalFacts.length > 0 ? canonicalFacts.map((fact) => `- ${fact.key}: ${fac
|
|
|
3996
4014
|
}
|
|
3997
4015
|
return m;
|
|
3998
4016
|
}).filter((m) => m !== null);
|
|
4017
|
+
const actuallyCompressed = newMessages.filter(
|
|
4018
|
+
(m) => m.role === "tool" && typeof m.content === "string" && m.content.startsWith("SUMMARIZED_TOOL_RESPONSE") && !messages.some((orig) => orig.tool_call_id === m.tool_call_id && isSummarizedToolPlaceholder(orig.content))
|
|
4019
|
+
);
|
|
4020
|
+
if (actuallyCompressed.length === 0) {
|
|
4021
|
+
return {};
|
|
4022
|
+
}
|
|
3999
4023
|
const validatedMessages = validateMessageSequence(newMessages);
|
|
4000
4024
|
const summaryToolCallId = `call_summary_${Date.now()}`;
|
|
4001
4025
|
const assistantSummaryCall = {
|
|
@@ -4071,12 +4095,7 @@ ${canonicalFacts.length > 0 ? canonicalFacts.map((fact) => `- ${fact.key}: ${fac
|
|
|
4071
4095
|
return {
|
|
4072
4096
|
messages: finalMessages,
|
|
4073
4097
|
summaries,
|
|
4074
|
-
summaryRecords
|
|
4075
|
-
watchdog: {
|
|
4076
|
-
...state.watchdog || {},
|
|
4077
|
-
compactions: (state.watchdog?.compactions || 0) + 1,
|
|
4078
|
-
lastAction: "summarized"
|
|
4079
|
-
}
|
|
4098
|
+
summaryRecords
|
|
4080
4099
|
};
|
|
4081
4100
|
};
|
|
4082
4101
|
}
|
|
@@ -4375,8 +4394,7 @@ function needsSummarization(state, opts, summarizationEnabled) {
|
|
|
4375
4394
|
return "";
|
|
4376
4395
|
}).join("\n");
|
|
4377
4396
|
const tokenCount = countApproxTokens(allText);
|
|
4378
|
-
const
|
|
4379
|
-
const needsSum = tokenCount > maxTok || resolved.watchdog.enabled && resolved.watchdog.autoCompaction && contextRotScore >= resolved.watchdog.contextRotThreshold;
|
|
4397
|
+
const needsSum = tokenCount > maxTok;
|
|
4380
4398
|
if (process.env.DEBUG_SUMMARIZATION) {
|
|
4381
4399
|
const msgCount = (state.messages || []).length;
|
|
4382
4400
|
const toolMsgs = (state.messages || []).filter((m) => m.role === "tool");
|
|
@@ -4386,7 +4404,7 @@ function needsSummarization(state, opts, summarizationEnabled) {
|
|
|
4386
4404
|
});
|
|
4387
4405
|
console.log(`[Summarization] Messages: ${msgCount}, Tool messages: ${toolMsgs.length}`);
|
|
4388
4406
|
toolDetails.forEach((d) => console.log(` ${d}`));
|
|
4389
|
-
console.log(`[Summarization] Token count: ${tokenCount}, Max: ${maxTok},
|
|
4407
|
+
console.log(`[Summarization] Token count: ${tokenCount}, Max: ${maxTok}, Needs summarization: ${needsSum}`);
|
|
4390
4408
|
}
|
|
4391
4409
|
return needsSum;
|
|
4392
4410
|
} catch {
|
|
@@ -4540,7 +4558,6 @@ function createSmartAgent(opts) {
|
|
|
4540
4558
|
delegation: resolved.delegation,
|
|
4541
4559
|
memory: { ...resolved.memory, store: memoryStore },
|
|
4542
4560
|
toolResponses: resolved.toolResponses,
|
|
4543
|
-
watchdog: resolved.watchdog,
|
|
4544
4561
|
useTodoList: planningEnabled
|
|
4545
4562
|
};
|
|
4546
4563
|
const stateRef = { toolHistory: void 0, toolHistoryArchived: void 0, todoList: void 0, planVersion: 0, adherenceScore: 0 };
|
|
@@ -4623,7 +4640,6 @@ function createSmartAgent(opts) {
|
|
|
4623
4640
|
let rawMessages = [...seedMessages];
|
|
4624
4641
|
const effectiveMaxToolCalls = config?.limits?.maxToolCalls ?? resolved.limits.maxToolCalls ?? 10;
|
|
4625
4642
|
const iterationLimit = Math.max(effectiveMaxToolCalls * 3 + 5, 30);
|
|
4626
|
-
let previousTokenCount = countApproxTokens(rawMessages.map((message) => typeof message.content === "string" ? message.content : JSON.stringify(message.content)).join("\n"));
|
|
4627
4643
|
for (let i = 0; i < iterationLimit; i++) {
|
|
4628
4644
|
state = { ...state, messages: rawMessages };
|
|
4629
4645
|
const next = summarizationEnabled ? decideBefore(state) : "agent";
|
|
@@ -4657,27 +4673,6 @@ function createSmartAgent(opts) {
|
|
|
4657
4673
|
state = syncPlanState(await syncMemory(state));
|
|
4658
4674
|
stateRef.toolHistory = state.toolHistory;
|
|
4659
4675
|
stateRef.toolHistoryArchived = state.toolHistoryArchived;
|
|
4660
|
-
const currentTokenCount = countApproxTokens(rawMessages.map((message) => typeof message.content === "string" ? message.content : JSON.stringify(message.content)).join("\n"));
|
|
4661
|
-
const tokenDrift = Math.max(0, currentTokenCount - previousTokenCount);
|
|
4662
|
-
const toolMessagesThisTurn = appendedMessages.filter((message) => message.role === "tool").length;
|
|
4663
|
-
const overToolingRate = appendedMessages.length === 0 ? 0 : Number((toolMessagesThisTurn / appendedMessages.length).toFixed(2));
|
|
4664
|
-
state = {
|
|
4665
|
-
...state,
|
|
4666
|
-
watchdog: {
|
|
4667
|
-
tokenDrift,
|
|
4668
|
-
contextRotScore: estimateContextRotScore(state),
|
|
4669
|
-
overToolingRate,
|
|
4670
|
-
compactions: state.watchdog?.compactions || 0,
|
|
4671
|
-
lastAction: appendedMessages.length > 0 ? "agent_turn" : state.watchdog?.lastAction
|
|
4672
|
-
}
|
|
4673
|
-
};
|
|
4674
|
-
previousTokenCount = currentTokenCount;
|
|
4675
|
-
if (resolved.watchdog.enabled && resolved.watchdog.autoCompaction) {
|
|
4676
|
-
const shouldCompact = tokenDrift >= resolved.watchdog.tokenDriftThreshold || (state.watchdog?.overToolingRate || 0) >= resolved.watchdog.overToolingSpikeThreshold || (state.watchdog?.contextRotScore || 0) >= resolved.watchdog.contextRotThreshold;
|
|
4677
|
-
if (shouldCompact) {
|
|
4678
|
-
state = { ...state, ctx: { ...state.ctx || {}, __needsSummarization: true } };
|
|
4679
|
-
}
|
|
4680
|
-
}
|
|
4681
4676
|
if (state.ctx?.__needsSummarization && summarizer) {
|
|
4682
4677
|
const ctx = { ...state.ctx || {} };
|
|
4683
4678
|
delete ctx.__needsSummarization;
|
|
@@ -4709,12 +4704,12 @@ function createSmartAgent(opts) {
|
|
|
4709
4704
|
}
|
|
4710
4705
|
if (state.summaries && state.summaries.length > 0) {
|
|
4711
4706
|
if (lastResult.state) {
|
|
4712
|
-
lastResult = { ...lastResult, state: { ...lastResult.state, summaries: state.summaries, summaryRecords: state.summaryRecords, memoryFacts: state.memoryFacts, plan: state.plan, planVersion: state.planVersion,
|
|
4707
|
+
lastResult = { ...lastResult, state: { ...lastResult.state, summaries: state.summaries, summaryRecords: state.summaryRecords, memoryFacts: state.memoryFacts, plan: state.plan, planVersion: state.planVersion, messages: rawMessages } };
|
|
4713
4708
|
} else {
|
|
4714
|
-
lastResult = { ...lastResult, state: { ...state, summaries: state.summaries, summaryRecords: state.summaryRecords, memoryFacts: state.memoryFacts, plan: state.plan, planVersion: state.planVersion,
|
|
4709
|
+
lastResult = { ...lastResult, state: { ...state, summaries: state.summaries, summaryRecords: state.summaryRecords, memoryFacts: state.memoryFacts, plan: state.plan, planVersion: state.planVersion, messages: rawMessages } };
|
|
4715
4710
|
}
|
|
4716
4711
|
} else if (lastResult.state) {
|
|
4717
|
-
lastResult = { ...lastResult, state: { ...lastResult.state, memoryFacts: state.memoryFacts, plan: state.plan, planVersion: state.planVersion,
|
|
4712
|
+
lastResult = { ...lastResult, state: { ...lastResult.state, memoryFacts: state.memoryFacts, plan: state.plan, planVersion: state.planVersion, messages: rawMessages } };
|
|
4718
4713
|
}
|
|
4719
4714
|
return lastResult;
|
|
4720
4715
|
},
|