@cognipeer/agent-sdk 0.6.2 → 0.6.3
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 +243 -151
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -3
- package/dist/index.d.ts +15 -3
- package/dist/index.mjs +241 -152
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1159,15 +1159,27 @@ declare function countApproxTokens(text: string): number;
|
|
|
1159
1159
|
*/
|
|
1160
1160
|
declare function countMessagesTokens(messages: any[]): number;
|
|
1161
1161
|
|
|
1162
|
-
|
|
1162
|
+
type ContextToolsStateRef = {
|
|
1163
1163
|
toolHistory?: any[];
|
|
1164
1164
|
toolHistoryArchived?: any[];
|
|
1165
1165
|
todoList?: any[];
|
|
1166
1166
|
planVersion?: number;
|
|
1167
1167
|
adherenceScore?: number;
|
|
1168
|
-
|
|
1168
|
+
messages?: Array<{
|
|
1169
|
+
role?: string;
|
|
1170
|
+
content?: unknown;
|
|
1171
|
+
}>;
|
|
1172
|
+
};
|
|
1173
|
+
declare function hasToolResponseRecoveryReference(messages: Array<{
|
|
1174
|
+
role?: string;
|
|
1175
|
+
content?: unknown;
|
|
1176
|
+
}> | undefined, executionId?: string): boolean;
|
|
1177
|
+
declare function createManageTodoTool(stateRef: ContextToolsStateRef): ToolInterface<any, any, any>;
|
|
1178
|
+
declare function createGetToolResponseTool(stateRef: ContextToolsStateRef): ToolInterface<any, any, any>;
|
|
1179
|
+
declare function createContextTools(stateRef: ContextToolsStateRef, opts?: {
|
|
1169
1180
|
planningEnabled?: boolean;
|
|
1170
1181
|
outputSchema?: any;
|
|
1182
|
+
includeGetToolResponse?: boolean;
|
|
1171
1183
|
}): any[];
|
|
1172
1184
|
|
|
1173
1185
|
declare function createSmartAgent<TOutput = unknown>(opts: SmartAgentOptions & {
|
|
@@ -1818,4 +1830,4 @@ declare function fromNativeProvider(provider: BaseProvider, options?: NativeMode
|
|
|
1818
1830
|
*/
|
|
1819
1831
|
declare function createProvider(config: ProviderConfig): BaseProvider;
|
|
1820
1832
|
|
|
1821
|
-
export { type AIMessage, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentRuleOptions, type AgentRuntimeConfig, type AgentSnapshot, type AgentSnapshotMetadata, type AgentState, AnthropicProvider, type AnthropicProviderConfig, AzureProvider, type AzureProviderConfig, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type BaseMessage, BaseProvider, BedrockProvider, type BedrockProviderConfig, type BuiltInRuntimeProfile, type CancellationTokenLike, type CancelledEvent, type ChatCompletionChunk, type ChatCompletionRequest, type ChatCompletionResponse, 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 FinishReason, 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 ModelCapabilities, NativeJsonSchemaStrategy, type NativeModelOptions, type NativeReasoningConfig, OpenAICompatibleProvider, type OpenAICompatibleProviderConfig, OpenAIProvider, type OpenAIProviderConfig, type PendingToolApproval, type PlanEvent, type PlanStepRecord, type PlanningMode, type ProfileConfig, type ProgressEvent, type ProgressUpdate, type ProviderConfig, ProviderError, type ToolCall as ProviderToolCall, type ToolDefinition as ProviderToolDefinition, type ProviderType, type ReasoningConfig, type ReasoningLevel, type ReflectionCadence, type ReflectionConfig, type ReflectionEvent, type ReflectionRecord, 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 StructuredOutputError, type StructuredOutputFieldError, StructuredOutputManager, type StructuredOutputManagerConfig, type StructuredOutputResult, type StructuredOutputStrategy, type StructuredSummary, type SummarizationEvent, type SummarizationMode, type SummaryFactItem, type SummaryIntegrityCheck, type TokenUsage, type ToolApprovalEvent, type ToolApprovalResolution, type ToolApprovalStatus, ToolBasedStrategy, 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, type UnifiedMessage, VertexProvider, type VertexProviderConfig, agentVerdictRule, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGuardrail, createJsonGuardrail, createProvider, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, emptyUsage, evaluateGuardrails, fileSink, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, resolveMemoryStore, resolveStrategy, resolveToolApprovalState, restoreSnapshot, runSmartAgentEvalHarness, startStreamingSession, traceSessionToOtlp, withTools, writeSummaryFactsToMemory };
|
|
1833
|
+
export { type AIMessage, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentRuleOptions, type AgentRuntimeConfig, type AgentSnapshot, type AgentSnapshotMetadata, type AgentState, AnthropicProvider, type AnthropicProviderConfig, AzureProvider, type AzureProviderConfig, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type BaseMessage, BaseProvider, BedrockProvider, type BedrockProviderConfig, type BuiltInRuntimeProfile, type CancellationTokenLike, type CancelledEvent, type ChatCompletionChunk, type ChatCompletionRequest, type ChatCompletionResponse, type ChildContextPolicy, type CodeDetectionRuleOptions, type CodeGuardrailOptions, type ContextPolicy, type ContextToolsStateRef, 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 FinishReason, 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 ModelCapabilities, NativeJsonSchemaStrategy, type NativeModelOptions, type NativeReasoningConfig, OpenAICompatibleProvider, type OpenAICompatibleProviderConfig, OpenAIProvider, type OpenAIProviderConfig, type PendingToolApproval, type PlanEvent, type PlanStepRecord, type PlanningMode, type ProfileConfig, type ProgressEvent, type ProgressUpdate, type ProviderConfig, ProviderError, type ToolCall as ProviderToolCall, type ToolDefinition as ProviderToolDefinition, type ProviderType, type ReasoningConfig, type ReasoningLevel, type ReflectionCadence, type ReflectionConfig, type ReflectionEvent, type ReflectionRecord, 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 StructuredOutputError, type StructuredOutputFieldError, StructuredOutputManager, type StructuredOutputManagerConfig, type StructuredOutputResult, type StructuredOutputStrategy, type StructuredSummary, type SummarizationEvent, type SummarizationMode, type SummaryFactItem, type SummaryIntegrityCheck, type TokenUsage, type ToolApprovalEvent, type ToolApprovalResolution, type ToolApprovalStatus, ToolBasedStrategy, 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, type UnifiedMessage, VertexProvider, type VertexProviderConfig, agentVerdictRule, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGetToolResponseTool, createGuardrail, createJsonGuardrail, createManageTodoTool, createProvider, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, emptyUsage, evaluateGuardrails, fileSink, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, hasToolResponseRecoveryReference, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, resolveMemoryStore, resolveStrategy, resolveToolApprovalState, restoreSnapshot, runSmartAgentEvalHarness, startStreamingSession, traceSessionToOtlp, withTools, writeSummaryFactsToMemory };
|
package/dist/index.d.ts
CHANGED
|
@@ -1159,15 +1159,27 @@ declare function countApproxTokens(text: string): number;
|
|
|
1159
1159
|
*/
|
|
1160
1160
|
declare function countMessagesTokens(messages: any[]): number;
|
|
1161
1161
|
|
|
1162
|
-
|
|
1162
|
+
type ContextToolsStateRef = {
|
|
1163
1163
|
toolHistory?: any[];
|
|
1164
1164
|
toolHistoryArchived?: any[];
|
|
1165
1165
|
todoList?: any[];
|
|
1166
1166
|
planVersion?: number;
|
|
1167
1167
|
adherenceScore?: number;
|
|
1168
|
-
|
|
1168
|
+
messages?: Array<{
|
|
1169
|
+
role?: string;
|
|
1170
|
+
content?: unknown;
|
|
1171
|
+
}>;
|
|
1172
|
+
};
|
|
1173
|
+
declare function hasToolResponseRecoveryReference(messages: Array<{
|
|
1174
|
+
role?: string;
|
|
1175
|
+
content?: unknown;
|
|
1176
|
+
}> | undefined, executionId?: string): boolean;
|
|
1177
|
+
declare function createManageTodoTool(stateRef: ContextToolsStateRef): ToolInterface<any, any, any>;
|
|
1178
|
+
declare function createGetToolResponseTool(stateRef: ContextToolsStateRef): ToolInterface<any, any, any>;
|
|
1179
|
+
declare function createContextTools(stateRef: ContextToolsStateRef, opts?: {
|
|
1169
1180
|
planningEnabled?: boolean;
|
|
1170
1181
|
outputSchema?: any;
|
|
1182
|
+
includeGetToolResponse?: boolean;
|
|
1171
1183
|
}): any[];
|
|
1172
1184
|
|
|
1173
1185
|
declare function createSmartAgent<TOutput = unknown>(opts: SmartAgentOptions & {
|
|
@@ -1818,4 +1830,4 @@ declare function fromNativeProvider(provider: BaseProvider, options?: NativeMode
|
|
|
1818
1830
|
*/
|
|
1819
1831
|
declare function createProvider(config: ProviderConfig): BaseProvider;
|
|
1820
1832
|
|
|
1821
|
-
export { type AIMessage, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentRuleOptions, type AgentRuntimeConfig, type AgentSnapshot, type AgentSnapshotMetadata, type AgentState, AnthropicProvider, type AnthropicProviderConfig, AzureProvider, type AzureProviderConfig, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type BaseMessage, BaseProvider, BedrockProvider, type BedrockProviderConfig, type BuiltInRuntimeProfile, type CancellationTokenLike, type CancelledEvent, type ChatCompletionChunk, type ChatCompletionRequest, type ChatCompletionResponse, 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 FinishReason, 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 ModelCapabilities, NativeJsonSchemaStrategy, type NativeModelOptions, type NativeReasoningConfig, OpenAICompatibleProvider, type OpenAICompatibleProviderConfig, OpenAIProvider, type OpenAIProviderConfig, type PendingToolApproval, type PlanEvent, type PlanStepRecord, type PlanningMode, type ProfileConfig, type ProgressEvent, type ProgressUpdate, type ProviderConfig, ProviderError, type ToolCall as ProviderToolCall, type ToolDefinition as ProviderToolDefinition, type ProviderType, type ReasoningConfig, type ReasoningLevel, type ReflectionCadence, type ReflectionConfig, type ReflectionEvent, type ReflectionRecord, 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 StructuredOutputError, type StructuredOutputFieldError, StructuredOutputManager, type StructuredOutputManagerConfig, type StructuredOutputResult, type StructuredOutputStrategy, type StructuredSummary, type SummarizationEvent, type SummarizationMode, type SummaryFactItem, type SummaryIntegrityCheck, type TokenUsage, type ToolApprovalEvent, type ToolApprovalResolution, type ToolApprovalStatus, ToolBasedStrategy, 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, type UnifiedMessage, VertexProvider, type VertexProviderConfig, agentVerdictRule, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGuardrail, createJsonGuardrail, createProvider, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, emptyUsage, evaluateGuardrails, fileSink, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, resolveMemoryStore, resolveStrategy, resolveToolApprovalState, restoreSnapshot, runSmartAgentEvalHarness, startStreamingSession, traceSessionToOtlp, withTools, writeSummaryFactsToMemory };
|
|
1833
|
+
export { type AIMessage, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentRuleOptions, type AgentRuntimeConfig, type AgentSnapshot, type AgentSnapshotMetadata, type AgentState, AnthropicProvider, type AnthropicProviderConfig, AzureProvider, type AzureProviderConfig, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type BaseMessage, BaseProvider, BedrockProvider, type BedrockProviderConfig, type BuiltInRuntimeProfile, type CancellationTokenLike, type CancelledEvent, type ChatCompletionChunk, type ChatCompletionRequest, type ChatCompletionResponse, type ChildContextPolicy, type CodeDetectionRuleOptions, type CodeGuardrailOptions, type ContextPolicy, type ContextToolsStateRef, 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 FinishReason, 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 ModelCapabilities, NativeJsonSchemaStrategy, type NativeModelOptions, type NativeReasoningConfig, OpenAICompatibleProvider, type OpenAICompatibleProviderConfig, OpenAIProvider, type OpenAIProviderConfig, type PendingToolApproval, type PlanEvent, type PlanStepRecord, type PlanningMode, type ProfileConfig, type ProgressEvent, type ProgressUpdate, type ProviderConfig, ProviderError, type ToolCall as ProviderToolCall, type ToolDefinition as ProviderToolDefinition, type ProviderType, type ReasoningConfig, type ReasoningLevel, type ReflectionCadence, type ReflectionConfig, type ReflectionEvent, type ReflectionRecord, 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 StructuredOutputError, type StructuredOutputFieldError, StructuredOutputManager, type StructuredOutputManagerConfig, type StructuredOutputResult, type StructuredOutputStrategy, type StructuredSummary, type SummarizationEvent, type SummarizationMode, type SummaryFactItem, type SummaryIntegrityCheck, type TokenUsage, type ToolApprovalEvent, type ToolApprovalResolution, type ToolApprovalStatus, ToolBasedStrategy, 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, type UnifiedMessage, VertexProvider, type VertexProviderConfig, agentVerdictRule, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGetToolResponseTool, createGuardrail, createJsonGuardrail, createManageTodoTool, createProvider, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, emptyUsage, evaluateGuardrails, fileSink, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, hasToolResponseRecoveryReference, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, resolveMemoryStore, resolveStrategy, resolveToolApprovalState, restoreSnapshot, runSmartAgentEvalHarness, startStreamingSession, traceSessionToOtlp, withTools, writeSummaryFactsToMemory };
|
package/dist/index.mjs
CHANGED
|
@@ -617,6 +617,7 @@ function buildSystemPrompt(extra, planning, name = "Agent", todoListPrompt) {
|
|
|
617
617
|
"- Keep privacy and safety: do not reveal secrets or sensitive data.",
|
|
618
618
|
"- If inputs are ambiguous or missing, ask one concise clarifying question.",
|
|
619
619
|
"- Reuse prior tool results already present in the conversation when sufficient.",
|
|
620
|
+
'- Use recovery tools such as "get_tool_response" only when the visible transcript explicitly shows a reduced tool-response marker (for example ARCHIVED_TOOL_RESPONSE, STRUCTURED_TOOL_RESPONSE, SUMMARIZED_TOOL_RESPONSE, DROPPED_TOOL_RESPONSE, or a truncation note with an executionId). Never use a recovery tool to re-fetch a normal tool result already visible in context.',
|
|
620
621
|
planningBlock,
|
|
621
622
|
extraTrimmed ? `Extra instructions: ${extraTrimmed}` : ""
|
|
622
623
|
].filter(Boolean).join("\n");
|
|
@@ -2542,6 +2543,7 @@ function createToolsNode(initialTools, opts) {
|
|
|
2542
2543
|
anyTool._stateRef.toolHistory = state.toolHistory;
|
|
2543
2544
|
anyTool._stateRef.toolHistoryArchived = state.toolHistoryArchived;
|
|
2544
2545
|
anyTool._stateRef.pendingApprovals = pendingApprovals;
|
|
2546
|
+
anyTool._stateRef.messages = state.messages;
|
|
2545
2547
|
anyTool._stateRef.ctx = state.ctx || (state.ctx = {});
|
|
2546
2548
|
anyTool._stateRef.__onEvent = onEvent;
|
|
2547
2549
|
}
|
|
@@ -4010,8 +4012,10 @@ function createAgent(opts) {
|
|
|
4010
4012
|
agentRuntime: res.agent || runtime,
|
|
4011
4013
|
status: "success"
|
|
4012
4014
|
});
|
|
4013
|
-
const
|
|
4014
|
-
const
|
|
4015
|
+
const isTransientSummarizationExit = !!res.ctx?.__needsSummarization;
|
|
4016
|
+
const finalAssistantMsg = isTransientSummarizationExit ? void 0 : getLastAssistantMessage(res.messages);
|
|
4017
|
+
const finalIsSyntheticSummary = !isTransientSummarizationExit && finalAssistantMsg && isSyntheticSummaryMessage(finalAssistantMsg);
|
|
4018
|
+
const content = isTransientSummarizationExit || finalIsSyntheticSummary ? "" : extractMessageText2(finalAssistantMsg);
|
|
4015
4019
|
let parsed = void 0;
|
|
4016
4020
|
let outputError = void 0;
|
|
4017
4021
|
if (soManager) {
|
|
@@ -4024,17 +4028,19 @@ function createAgent(opts) {
|
|
|
4024
4028
|
} else {
|
|
4025
4029
|
outputError = fallbackResult.error;
|
|
4026
4030
|
}
|
|
4027
|
-
} else {
|
|
4031
|
+
} else if (!isTransientSummarizationExit) {
|
|
4028
4032
|
const noResult = soManager.noOutputResult(1);
|
|
4029
4033
|
if (!noResult.success) {
|
|
4030
4034
|
outputError = noResult.error;
|
|
4031
4035
|
}
|
|
4032
4036
|
}
|
|
4033
4037
|
}
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
+
if (!isTransientSummarizationExit && !finalIsSyntheticSummary) {
|
|
4039
|
+
emit({ type: "finalAnswer", content });
|
|
4040
|
+
if (streamEnabled && content) {
|
|
4041
|
+
onStream?.({ text: content, isFinal: true });
|
|
4042
|
+
emit({ type: "stream", text: content, isFinal: true });
|
|
4043
|
+
}
|
|
4038
4044
|
}
|
|
4039
4045
|
return {
|
|
4040
4046
|
content,
|
|
@@ -4832,6 +4838,13 @@ ${canonicalFacts.length > 0 ? canonicalFacts.map((fact) => `- ${fact.key}: ${fac
|
|
|
4832
4838
|
};
|
|
4833
4839
|
};
|
|
4834
4840
|
}
|
|
4841
|
+
var TOOL_RESPONSE_RECOVERY_MARKERS = [
|
|
4842
|
+
/ARCHIVED_TOOL_RESPONSE\s*\[/,
|
|
4843
|
+
/STRUCTURED_TOOL_RESPONSE\s*\[/,
|
|
4844
|
+
/SUMMARIZED_TOOL_RESPONSE\b/,
|
|
4845
|
+
/DROPPED_TOOL_RESPONSE\s*\[/,
|
|
4846
|
+
/Use get_tool_response with executionId/i
|
|
4847
|
+
];
|
|
4835
4848
|
var todoStatusSchema = z.enum(["not-started", "in-progress", "completed", "blocked"]);
|
|
4836
4849
|
var todoWriteItemSchema = z.object({
|
|
4837
4850
|
id: z.number().int().min(1).describe("Sequential id starting from 1"),
|
|
@@ -4900,180 +4913,223 @@ function formatTodoListSummary(todoList) {
|
|
|
4900
4913
|
}
|
|
4901
4914
|
return todoList.map((item) => `${item.id}. ${item.title || item.step || item.description || `Step ${item.id}`} [${item.status}]`).join("\n");
|
|
4902
4915
|
}
|
|
4903
|
-
function
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4916
|
+
function flattenRecoveryContent(content) {
|
|
4917
|
+
if (typeof content === "string") {
|
|
4918
|
+
return content;
|
|
4919
|
+
}
|
|
4920
|
+
if (Array.isArray(content)) {
|
|
4921
|
+
return content.map((part) => {
|
|
4922
|
+
if (typeof part === "string") {
|
|
4923
|
+
return part;
|
|
4924
|
+
}
|
|
4925
|
+
if (part && typeof part === "object") {
|
|
4926
|
+
if (typeof part.text === "string") {
|
|
4927
|
+
return part.text;
|
|
4928
|
+
}
|
|
4929
|
+
if (typeof part.content === "string") {
|
|
4930
|
+
return part.content;
|
|
4931
|
+
}
|
|
4932
|
+
}
|
|
4933
|
+
return "";
|
|
4934
|
+
}).filter(Boolean).join("\n");
|
|
4935
|
+
}
|
|
4936
|
+
return "";
|
|
4937
|
+
}
|
|
4938
|
+
function hasToolResponseRecoveryReference(messages, executionId) {
|
|
4939
|
+
if (!Array.isArray(messages) || messages.length === 0) {
|
|
4940
|
+
return false;
|
|
4941
|
+
}
|
|
4942
|
+
return messages.some((message) => {
|
|
4943
|
+
if (message?.role === "system") {
|
|
4944
|
+
return false;
|
|
4945
|
+
}
|
|
4946
|
+
const content = flattenRecoveryContent(message?.content);
|
|
4947
|
+
if (!content) {
|
|
4948
|
+
return false;
|
|
4949
|
+
}
|
|
4950
|
+
const hasRecoveryMarker = TOOL_RESPONSE_RECOVERY_MARKERS.some((pattern) => pattern.test(content));
|
|
4951
|
+
if (!hasRecoveryMarker) {
|
|
4952
|
+
return false;
|
|
4953
|
+
}
|
|
4954
|
+
return executionId ? content.includes(executionId) : true;
|
|
4955
|
+
});
|
|
4956
|
+
}
|
|
4957
|
+
function createManageTodoTool(stateRef) {
|
|
4958
|
+
const manageTodo = createTool({
|
|
4959
|
+
name: "manage_todo_list",
|
|
4960
|
+
description: "Manage a structured todo list to track progress and plan tasks throughout your coding session.\n\nOperations:\n- read: return the current plan\n- write: replace the full plan with a complete ordered todoList\n- update: patch existing todo items by id without resending the whole plan\n\nRules:\n- Use write only when creating or fully rewriting the plan\n- After a plan exists, prefer update for status, evidence, or owner changes\n- Update payloads should contain only the changed items\n- When using update, pass expectedVersion to avoid overwriting a newer plan\n- Keep ids unique; write operations must keep ids sequential starting from 1\n- Keep at most ONE item in-progress at a time\n- If update fails due to version mismatch, read the latest plan and retry",
|
|
4961
|
+
schema: z.object({
|
|
4962
|
+
operation: z.enum(["write", "read", "update"]),
|
|
4963
|
+
expectedVersion: z.number().int().min(0).optional(),
|
|
4964
|
+
todoList: z.array(z.union([todoWriteItemSchema, todoUpdateItemSchema])).optional()
|
|
4965
|
+
}),
|
|
4966
|
+
func: async ({ operation, expectedVersion, todoList }) => {
|
|
4967
|
+
const toolStateRef = manageTodo._stateRef;
|
|
4968
|
+
const onEvent = toolStateRef?.__onEvent;
|
|
4969
|
+
const emitPlanEvent = (list) => {
|
|
4970
|
+
const version = stateRef.planVersion || 1;
|
|
4971
|
+
const adherenceScore = stateRef.adherenceScore || 0;
|
|
4972
|
+
const planData = {
|
|
4973
|
+
source: "manage_todo_list",
|
|
4974
|
+
operation,
|
|
4975
|
+
version,
|
|
4976
|
+
adherenceScore,
|
|
4977
|
+
count: Array.isArray(list) ? list.length : 0
|
|
4978
|
+
};
|
|
4979
|
+
onEvent?.({ type: "plan", todoList: list, ...planData });
|
|
4980
|
+
const traceSession = toolStateRef?.ctx?.__traceSession;
|
|
4981
|
+
recordTraceEvent(traceSession, {
|
|
4982
|
+
type: "plan",
|
|
4983
|
+
label: `Plan ${operation}`,
|
|
4984
|
+
actor: { scope: "agent", name: "manage_todo_list", role: "planner" },
|
|
4985
|
+
sections: [
|
|
4986
|
+
{
|
|
4987
|
+
kind: "summary",
|
|
4988
|
+
label: "Todo List",
|
|
4989
|
+
content: formatTodoListSummary(list)
|
|
4990
|
+
},
|
|
4991
|
+
{
|
|
4992
|
+
kind: "metadata",
|
|
4993
|
+
label: "Plan Metadata",
|
|
4994
|
+
data: planData
|
|
4995
|
+
}
|
|
4996
|
+
],
|
|
4997
|
+
debug: planData
|
|
4998
|
+
});
|
|
4999
|
+
};
|
|
5000
|
+
const currentVersion = stateRef.planVersion || 0;
|
|
5001
|
+
if (operation === "read") {
|
|
5002
|
+
const list = stateRef.todoList || [];
|
|
5003
|
+
emitPlanEvent(list);
|
|
5004
|
+
return list;
|
|
5005
|
+
}
|
|
5006
|
+
if (typeof expectedVersion === "number" && expectedVersion !== currentVersion) {
|
|
5007
|
+
return {
|
|
5008
|
+
status: "error",
|
|
5009
|
+
operation,
|
|
5010
|
+
error: "Plan version mismatch. Read the latest plan and retry.",
|
|
5011
|
+
version: currentVersion,
|
|
5012
|
+
adherenceScore: stateRef.adherenceScore || 0
|
|
5013
|
+
};
|
|
5014
|
+
}
|
|
5015
|
+
if (!Array.isArray(todoList)) {
|
|
5016
|
+
return {
|
|
5017
|
+
status: "error",
|
|
5018
|
+
operation,
|
|
5019
|
+
error: "todoList is required for write and update operations.",
|
|
5020
|
+
version: currentVersion,
|
|
5021
|
+
adherenceScore: stateRef.adherenceScore || 0
|
|
5022
|
+
};
|
|
5023
|
+
}
|
|
5024
|
+
if (operation === "write") {
|
|
5025
|
+
const parsed = z.array(todoWriteItemSchema).safeParse(todoList);
|
|
5026
|
+
if (!parsed.success) {
|
|
5027
|
+
return {
|
|
5028
|
+
status: "error",
|
|
4922
5029
|
operation,
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
5030
|
+
error: parsed.error.issues[0]?.message || "Invalid todoList for write.",
|
|
5031
|
+
version: currentVersion,
|
|
5032
|
+
adherenceScore: stateRef.adherenceScore || 0
|
|
4926
5033
|
};
|
|
4927
|
-
onEvent?.({ type: "plan", todoList: list, ...planData });
|
|
4928
|
-
const traceSession = toolStateRef?.ctx?.__traceSession;
|
|
4929
|
-
recordTraceEvent(traceSession, {
|
|
4930
|
-
type: "plan",
|
|
4931
|
-
label: `Plan ${operation}`,
|
|
4932
|
-
actor: { scope: "agent", name: "manage_todo_list", role: "planner" },
|
|
4933
|
-
sections: [
|
|
4934
|
-
{
|
|
4935
|
-
kind: "summary",
|
|
4936
|
-
label: "Todo List",
|
|
4937
|
-
content: formatTodoListSummary(list)
|
|
4938
|
-
},
|
|
4939
|
-
{
|
|
4940
|
-
kind: "metadata",
|
|
4941
|
-
label: "Plan Metadata",
|
|
4942
|
-
data: planData
|
|
4943
|
-
}
|
|
4944
|
-
],
|
|
4945
|
-
debug: planData
|
|
4946
|
-
});
|
|
4947
|
-
};
|
|
4948
|
-
const currentVersion = stateRef.planVersion || 0;
|
|
4949
|
-
if (operation === "read") {
|
|
4950
|
-
const list = stateRef.todoList || [];
|
|
4951
|
-
emitPlanEvent(list);
|
|
4952
|
-
return list;
|
|
4953
5034
|
}
|
|
4954
|
-
|
|
5035
|
+
const normalizedList = parsed.data.map((item) => normalizeTodoItem(item));
|
|
5036
|
+
const validation = validatePlanInvariants(normalizedList, true);
|
|
5037
|
+
if (!validation.ok) {
|
|
4955
5038
|
return {
|
|
4956
5039
|
status: "error",
|
|
4957
5040
|
operation,
|
|
4958
|
-
error:
|
|
5041
|
+
error: validation.error,
|
|
4959
5042
|
version: currentVersion,
|
|
4960
5043
|
adherenceScore: stateRef.adherenceScore || 0
|
|
4961
5044
|
};
|
|
4962
5045
|
}
|
|
4963
|
-
|
|
5046
|
+
stateRef.todoList = normalizedList;
|
|
5047
|
+
} else if (operation === "update") {
|
|
5048
|
+
const parsed = z.array(todoUpdateItemSchema).safeParse(todoList);
|
|
5049
|
+
if (!parsed.success) {
|
|
4964
5050
|
return {
|
|
4965
5051
|
status: "error",
|
|
4966
5052
|
operation,
|
|
4967
|
-
error: "todoList
|
|
5053
|
+
error: parsed.error.issues[0]?.message || "Invalid todoList for update.",
|
|
4968
5054
|
version: currentVersion,
|
|
4969
5055
|
adherenceScore: stateRef.adherenceScore || 0
|
|
4970
5056
|
};
|
|
4971
5057
|
}
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
if (
|
|
4986
|
-
return {
|
|
4987
|
-
status: "error",
|
|
4988
|
-
operation,
|
|
4989
|
-
error: validation.error,
|
|
4990
|
-
version: currentVersion,
|
|
4991
|
-
adherenceScore: stateRef.adherenceScore || 0
|
|
4992
|
-
};
|
|
4993
|
-
}
|
|
4994
|
-
stateRef.todoList = normalizedList;
|
|
4995
|
-
} else if (operation === "update") {
|
|
4996
|
-
const parsed = z.array(todoUpdateItemSchema).safeParse(todoList);
|
|
4997
|
-
if (!parsed.success) {
|
|
4998
|
-
return {
|
|
4999
|
-
status: "error",
|
|
5000
|
-
operation,
|
|
5001
|
-
error: parsed.error.issues[0]?.message || "Invalid todoList for update.",
|
|
5002
|
-
version: currentVersion,
|
|
5003
|
-
adherenceScore: stateRef.adherenceScore || 0
|
|
5004
|
-
};
|
|
5005
|
-
}
|
|
5006
|
-
const currentList = Array.isArray(stateRef.todoList) ? stateRef.todoList : [];
|
|
5007
|
-
if (currentList.length === 0) {
|
|
5058
|
+
const currentList = Array.isArray(stateRef.todoList) ? stateRef.todoList : [];
|
|
5059
|
+
if (currentList.length === 0) {
|
|
5060
|
+
return {
|
|
5061
|
+
status: "error",
|
|
5062
|
+
operation,
|
|
5063
|
+
error: "No existing plan to update. Use write first.",
|
|
5064
|
+
version: currentVersion,
|
|
5065
|
+
adherenceScore: stateRef.adherenceScore || 0
|
|
5066
|
+
};
|
|
5067
|
+
}
|
|
5068
|
+
const currentMap = new Map(currentList.map((item) => [item.id, item]));
|
|
5069
|
+
const patchMap = /* @__PURE__ */ new Map();
|
|
5070
|
+
for (const item of parsed.data) {
|
|
5071
|
+
if (patchMap.has(item.id)) {
|
|
5008
5072
|
return {
|
|
5009
5073
|
status: "error",
|
|
5010
5074
|
operation,
|
|
5011
|
-
error: "
|
|
5075
|
+
error: "Update payload contains duplicate todo ids.",
|
|
5012
5076
|
version: currentVersion,
|
|
5013
5077
|
adherenceScore: stateRef.adherenceScore || 0
|
|
5014
5078
|
};
|
|
5015
5079
|
}
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
for (const item of parsed.data) {
|
|
5019
|
-
if (patchMap.has(item.id)) {
|
|
5020
|
-
return {
|
|
5021
|
-
status: "error",
|
|
5022
|
-
operation,
|
|
5023
|
-
error: "Update payload contains duplicate todo ids.",
|
|
5024
|
-
version: currentVersion,
|
|
5025
|
-
adherenceScore: stateRef.adherenceScore || 0
|
|
5026
|
-
};
|
|
5027
|
-
}
|
|
5028
|
-
patchMap.set(item.id, item);
|
|
5029
|
-
if (!currentMap.has(item.id)) {
|
|
5030
|
-
return {
|
|
5031
|
-
status: "error",
|
|
5032
|
-
operation,
|
|
5033
|
-
error: `Cannot update missing todo id ${item.id}. Use write to replace the plan.`,
|
|
5034
|
-
version: currentVersion,
|
|
5035
|
-
adherenceScore: stateRef.adherenceScore || 0
|
|
5036
|
-
};
|
|
5037
|
-
}
|
|
5038
|
-
}
|
|
5039
|
-
const mergedList = currentList.map((item) => {
|
|
5040
|
-
const patch = patchMap.get(item.id);
|
|
5041
|
-
return patch ? normalizeTodoItem(patch, item) : item;
|
|
5042
|
-
});
|
|
5043
|
-
const validation = validatePlanInvariants(mergedList, false);
|
|
5044
|
-
if (!validation.ok) {
|
|
5080
|
+
patchMap.set(item.id, item);
|
|
5081
|
+
if (!currentMap.has(item.id)) {
|
|
5045
5082
|
return {
|
|
5046
5083
|
status: "error",
|
|
5047
5084
|
operation,
|
|
5048
|
-
error:
|
|
5085
|
+
error: `Cannot update missing todo id ${item.id}. Use write to replace the plan.`,
|
|
5049
5086
|
version: currentVersion,
|
|
5050
5087
|
adherenceScore: stateRef.adherenceScore || 0
|
|
5051
5088
|
};
|
|
5052
5089
|
}
|
|
5053
|
-
stateRef.todoList = mergedList;
|
|
5054
5090
|
}
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5091
|
+
const mergedList = currentList.map((item) => {
|
|
5092
|
+
const patch = patchMap.get(item.id);
|
|
5093
|
+
return patch ? normalizeTodoItem(patch, item) : item;
|
|
5094
|
+
});
|
|
5095
|
+
const validation = validatePlanInvariants(mergedList, false);
|
|
5096
|
+
if (!validation.ok) {
|
|
5097
|
+
return {
|
|
5098
|
+
status: "error",
|
|
5099
|
+
operation,
|
|
5100
|
+
error: validation.error,
|
|
5101
|
+
version: currentVersion,
|
|
5102
|
+
adherenceScore: stateRef.adherenceScore || 0
|
|
5103
|
+
};
|
|
5104
|
+
}
|
|
5105
|
+
stateRef.todoList = mergedList;
|
|
5106
|
+
}
|
|
5107
|
+
stateRef.planVersion = currentVersion + 1;
|
|
5108
|
+
stateRef.adherenceScore = calculateAdherenceScore(stateRef.todoList || []);
|
|
5109
|
+
const payload = {
|
|
5110
|
+
status: "ok",
|
|
5111
|
+
operation,
|
|
5112
|
+
count: Array.isArray(todoList) ? todoList.length : void 0,
|
|
5113
|
+
version: stateRef.planVersion || 1,
|
|
5114
|
+
adherenceScore: stateRef.adherenceScore || 0
|
|
5115
|
+
};
|
|
5116
|
+
emitPlanEvent(stateRef.todoList || []);
|
|
5117
|
+
return payload;
|
|
5118
|
+
}
|
|
5119
|
+
});
|
|
5120
|
+
manageTodo._stateRef = stateRef;
|
|
5121
|
+
return manageTodo;
|
|
5122
|
+
}
|
|
5123
|
+
function createGetToolResponseTool(stateRef) {
|
|
5071
5124
|
const getTool = createTool({
|
|
5072
5125
|
name: "get_tool_response",
|
|
5073
|
-
description: "RETRIEVE the full output of a tool execution whose response was archived, dropped, or later compacted in conversation history.
|
|
5126
|
+
description: "RETRIEVE the full output of a tool execution whose response was archived, dropped, truncated, or later compacted in conversation history. This tool is only useful when the visible transcript already shows a reduced tool-response marker for the referenced executionId or tool_call_id. Use it only when a marker such as 'ARCHIVED_TOOL_RESPONSE', 'STRUCTURED_TOOL_RESPONSE', 'SUMMARIZED_TOOL_RESPONSE', 'DROPPED_TOOL_RESPONSE', or an explicit truncation note points you to a missing field you still need. Do not call it to re-fetch a normal tool result that is already present in context.",
|
|
5074
5127
|
schema: z.object({ executionId: z.string().describe("Tool execution id or original tool_call_id") }),
|
|
5075
5128
|
maxExecutionsPerRun: 8,
|
|
5076
5129
|
func: async ({ executionId }) => {
|
|
5130
|
+
if (!hasToolResponseRecoveryReference(stateRef.messages, executionId)) {
|
|
5131
|
+
return "Execution not recoverable from the visible transcript. Use this only when the conversation already shows a reduced tool-response marker for that executionId.";
|
|
5132
|
+
}
|
|
5077
5133
|
const matchesExecution = (t) => t?.executionId === executionId || t?.tool_call_id === executionId;
|
|
5078
5134
|
let execution = stateRef.toolHistory?.find((t) => matchesExecution(t));
|
|
5079
5135
|
if (!execution) {
|
|
@@ -5086,7 +5142,16 @@ function createContextTools(stateRef, opts) {
|
|
|
5086
5142
|
}
|
|
5087
5143
|
});
|
|
5088
5144
|
getTool._stateRef = stateRef;
|
|
5089
|
-
|
|
5145
|
+
return getTool;
|
|
5146
|
+
}
|
|
5147
|
+
function createContextTools(stateRef, opts) {
|
|
5148
|
+
const tools = [];
|
|
5149
|
+
if (opts?.planningEnabled) {
|
|
5150
|
+
tools.push(createManageTodoTool(stateRef));
|
|
5151
|
+
}
|
|
5152
|
+
if (opts?.includeGetToolResponse ?? true) {
|
|
5153
|
+
tools.push(createGetToolResponseTool(stateRef));
|
|
5154
|
+
}
|
|
5090
5155
|
return tools;
|
|
5091
5156
|
}
|
|
5092
5157
|
|
|
@@ -5254,9 +5319,11 @@ function createSmartAgent(opts) {
|
|
|
5254
5319
|
useTodoList: planningEnabled
|
|
5255
5320
|
};
|
|
5256
5321
|
const stateRef = { toolHistory: void 0, toolHistoryArchived: void 0, todoList: void 0, planVersion: 0, adherenceScore: 0 };
|
|
5257
|
-
const contextTools = createContextTools(stateRef, { planningEnabled });
|
|
5258
|
-
const
|
|
5259
|
-
const
|
|
5322
|
+
const contextTools = createContextTools(stateRef, { planningEnabled, includeGetToolResponse: false });
|
|
5323
|
+
const getToolResponseTool = createGetToolResponseTool(stateRef);
|
|
5324
|
+
const toolsWithoutRecovery = [...opts.tools ?? [], ...contextTools];
|
|
5325
|
+
const toolsWithRecovery = [...toolsWithoutRecovery, getToolResponseTool];
|
|
5326
|
+
const base = createAgent({ ...runtimeOpts, tools: toolsWithoutRecovery });
|
|
5260
5327
|
base.__runtime.runtimeProfile = resolved.runtimeProfile;
|
|
5261
5328
|
base.__runtime.smart = resolved;
|
|
5262
5329
|
const summarizationEnabled = resolved.summarization.enable !== false;
|
|
@@ -5314,6 +5381,27 @@ function createSmartAgent(opts) {
|
|
|
5314
5381
|
);
|
|
5315
5382
|
return { role: "system", content: sys };
|
|
5316
5383
|
}
|
|
5384
|
+
function syncRuntimeTools(currentState, currentMessages) {
|
|
5385
|
+
const needsRecoveryTool = hasToolResponseRecoveryReference(currentMessages);
|
|
5386
|
+
const nextTools = needsRecoveryTool ? toolsWithRecovery : toolsWithoutRecovery;
|
|
5387
|
+
const currentRuntime = currentState.agent || base.__runtime;
|
|
5388
|
+
if (currentRuntime.tools === nextTools) {
|
|
5389
|
+
return currentState;
|
|
5390
|
+
}
|
|
5391
|
+
return {
|
|
5392
|
+
...currentState,
|
|
5393
|
+
agent: {
|
|
5394
|
+
...currentRuntime,
|
|
5395
|
+
tools: nextTools
|
|
5396
|
+
}
|
|
5397
|
+
};
|
|
5398
|
+
}
|
|
5399
|
+
function producedTerminalAssistantTurn(messages) {
|
|
5400
|
+
const lastAssistant = [...messages].reverse().find((message) => message?.role === "assistant");
|
|
5401
|
+
if (!lastAssistant) return false;
|
|
5402
|
+
const toolCalls = Array.isArray(lastAssistant.tool_calls) ? lastAssistant.tool_calls : [];
|
|
5403
|
+
return toolCalls.length === 0;
|
|
5404
|
+
}
|
|
5317
5405
|
async function trySummarize(currentState, currentRawMessages) {
|
|
5318
5406
|
if (!summarizer) return { state: currentState, rawMessages: currentRawMessages, compressed: false };
|
|
5319
5407
|
const delta = await summarizer(currentState);
|
|
@@ -5335,13 +5423,13 @@ function createSmartAgent(opts) {
|
|
|
5335
5423
|
stateRef.adherenceScore = input.plan?.adherenceScore || 0;
|
|
5336
5424
|
const alreadyHasSystem = Array.isArray(input.messages) && input.messages[0]?.role === "system";
|
|
5337
5425
|
const seedMessages = alreadyHasSystem ? [...input.messages || []] : [systemMessage2(), ...input.messages || []];
|
|
5338
|
-
let state = await syncMemory({ ...input, messages: seedMessages });
|
|
5426
|
+
let state = syncRuntimeTools(await syncMemory({ ...input, messages: seedMessages }), seedMessages);
|
|
5339
5427
|
let lastResult = null;
|
|
5340
5428
|
let rawMessages = [...seedMessages];
|
|
5341
5429
|
const effectiveMaxToolCalls = config?.limits?.maxToolCalls ?? resolved.limits.maxToolCalls ?? 10;
|
|
5342
5430
|
const iterationLimit = Math.max(effectiveMaxToolCalls * 3 + 5, 30);
|
|
5343
5431
|
for (let i = 0; i < iterationLimit; i++) {
|
|
5344
|
-
state = { ...state, messages: rawMessages };
|
|
5432
|
+
state = syncRuntimeTools({ ...state, messages: rawMessages }, rawMessages);
|
|
5345
5433
|
const next = summarizationEnabled ? decideBefore(state) : "agent";
|
|
5346
5434
|
if (next === "contextSummarize" && summarizer) {
|
|
5347
5435
|
const result = await trySummarize(state, rawMessages);
|
|
@@ -5368,7 +5456,7 @@ function createSmartAgent(opts) {
|
|
|
5368
5456
|
if (currentPlan && !state.plan) {
|
|
5369
5457
|
state = { ...state, plan: currentPlan };
|
|
5370
5458
|
}
|
|
5371
|
-
state = syncPlanState(await syncMemory(state));
|
|
5459
|
+
state = syncRuntimeTools(syncPlanState(await syncMemory(state)), rawMessages);
|
|
5372
5460
|
stateRef.toolHistory = state.toolHistory;
|
|
5373
5461
|
stateRef.toolHistoryArchived = state.toolHistoryArchived;
|
|
5374
5462
|
if (state.ctx?.__needsSummarization && summarizer) {
|
|
@@ -5382,6 +5470,7 @@ function createSmartAgent(opts) {
|
|
|
5382
5470
|
}
|
|
5383
5471
|
if (state.ctx?.__finalizedDueToStructuredOutput) break;
|
|
5384
5472
|
if (opts.outputSchema && lastResult?.output != null) break;
|
|
5473
|
+
if (producedTerminalAssistantTurn(appendedMessages)) break;
|
|
5385
5474
|
if (summarizationEnabled) {
|
|
5386
5475
|
const after = decideAfter(state);
|
|
5387
5476
|
if (after === "contextSummarize" && summarizer) {
|
|
@@ -7655,6 +7744,6 @@ function createProvider(config) {
|
|
|
7655
7744
|
}
|
|
7656
7745
|
}
|
|
7657
7746
|
|
|
7658
|
-
export { AnthropicProvider, AzureProvider, BaseProvider, BedrockProvider, DEFAULT_PROFILE_CONFIGS, GuardrailPhase, InMemoryMemoryStore, NativeJsonSchemaStrategy, OpenAICompatibleProvider, OpenAIProvider, ProviderError, StructuredOutputManager, ToolBasedStrategy, VertexProvider, agentVerdictRule, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGuardrail, createJsonGuardrail, createProvider, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, emptyUsage, evaluateGuardrails, fileSink, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, resolveMemoryStore, resolveStrategy, resolveToolApprovalState, restoreSnapshot, runSmartAgentEvalHarness, startStreamingSession, traceSessionToOtlp, withTools, writeSummaryFactsToMemory };
|
|
7747
|
+
export { AnthropicProvider, AzureProvider, BaseProvider, BedrockProvider, DEFAULT_PROFILE_CONFIGS, GuardrailPhase, InMemoryMemoryStore, NativeJsonSchemaStrategy, OpenAICompatibleProvider, OpenAIProvider, ProviderError, StructuredOutputManager, ToolBasedStrategy, VertexProvider, agentVerdictRule, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGetToolResponseTool, createGuardrail, createJsonGuardrail, createManageTodoTool, createProvider, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, emptyUsage, evaluateGuardrails, fileSink, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, hasToolResponseRecoveryReference, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, resolveMemoryStore, resolveStrategy, resolveToolApprovalState, restoreSnapshot, runSmartAgentEvalHarness, startStreamingSession, traceSessionToOtlp, withTools, writeSummaryFactsToMemory };
|
|
7659
7748
|
//# sourceMappingURL=index.mjs.map
|
|
7660
7749
|
//# sourceMappingURL=index.mjs.map
|