@cognipeer/agent-sdk 0.6.5 → 0.6.6

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.d.cts CHANGED
@@ -299,6 +299,12 @@ type AgentOptions = {
299
299
  cachedInputTokens?: number;
300
300
  reasoningTokens?: number;
301
301
  }) => number;
302
+ /**
303
+ * Human-in-the-loop hooks. When `askUser` is enabled, the agent gains a
304
+ * built-in `ask_user_question` tool that pauses the run with structured
305
+ * questions for the host application to answer.
306
+ */
307
+ humanInTheLoop?: HumanInTheLoopOptions;
302
308
  };
303
309
  type ReasoningLevel = "low" | "medium" | "high";
304
310
  type ReflectionCadence = "off" | "every_turn" | "after_tool" | "on_branch";
@@ -538,6 +544,8 @@ type SmartAgentOptions = {
538
544
  tokenCounter?: (text: string) => number;
539
545
  /** See AgentOptions.costEstimator. */
540
546
  costEstimator?: AgentOptions["costEstimator"];
547
+ /** See AgentOptions.humanInTheLoop. */
548
+ humanInTheLoop?: HumanInTheLoopOptions;
541
549
  };
542
550
  type AgentRuntimeConfig = {
543
551
  name?: string;
@@ -554,6 +562,7 @@ type AgentRuntimeConfig = {
554
562
  tracing?: TracingConfig;
555
563
  runtimeProfile?: RuntimeProfile;
556
564
  smart?: ResolvedSmartAgentConfig;
565
+ humanInTheLoop?: HumanInTheLoopRuntimeConfig;
557
566
  };
558
567
  type TraceMessageSection = {
559
568
  id?: string;
@@ -786,6 +795,7 @@ type AgentState = {
786
795
  metadata?: Record<string, any>;
787
796
  ctx?: Record<string, any>;
788
797
  pendingApprovals?: PendingToolApproval[];
798
+ pendingUserQuestions?: PendingUserQuestion[];
789
799
  usage?: {
790
800
  perRequest: Array<{
791
801
  id: string;
@@ -1032,6 +1042,93 @@ type ToolApprovalEvent = {
1032
1042
  decidedBy?: string;
1033
1043
  comment?: string;
1034
1044
  };
1045
+ type UserQuestionOption = {
1046
+ /** Label shown to the user. */
1047
+ label: string;
1048
+ /** Value returned in the resolution. Defaults to `label` when omitted. */
1049
+ value?: string;
1050
+ /** Optional helper text rendered alongside the option. */
1051
+ description?: string;
1052
+ /** Optional code / ASCII preview rendered when the option is focused. */
1053
+ preview?: string;
1054
+ };
1055
+ type UserQuestionItem = {
1056
+ /** The full question text shown to the user. */
1057
+ question: string;
1058
+ /** Short label (chip / tag) displayed alongside the question. */
1059
+ header?: string;
1060
+ /** When true the user may pick multiple options. Default: false. */
1061
+ multiSelect?: boolean;
1062
+ /** Placeholder shown for the free-text input (when enabled globally). */
1063
+ placeholder?: string;
1064
+ /** Predefined options; omit for a pure free-text question. */
1065
+ options?: UserQuestionOption[];
1066
+ /** When true the user must answer this item. Default: true. */
1067
+ required?: boolean;
1068
+ };
1069
+ type UserQuestionStatus = "pending" | "answered" | "cancelled" | "executed";
1070
+ type UserQuestionAnswer = {
1071
+ /** Selected option values. Single-select questions report exactly one entry. */
1072
+ values: string[];
1073
+ /** Populated when the user typed a custom answer (only when free-text is enabled). */
1074
+ freeText?: string;
1075
+ /** Optional reviewer notes. */
1076
+ notes?: string;
1077
+ };
1078
+ /** Keyed by the question text (or `header`, if both questions share text). */
1079
+ type UserQuestionAnswerSet = Record<string, UserQuestionAnswer>;
1080
+ type PendingUserQuestion = {
1081
+ id: string;
1082
+ toolCallId: string;
1083
+ toolName: "ask_user_question";
1084
+ questions: UserQuestionItem[];
1085
+ status: UserQuestionStatus;
1086
+ requestedAt: string;
1087
+ answeredAt?: string;
1088
+ answeredBy?: string;
1089
+ answers?: UserQuestionAnswerSet;
1090
+ cancelled?: boolean;
1091
+ notes?: string;
1092
+ /** Snapshot of the global free-text flag at request time, for UI rendering. */
1093
+ allowFreeText?: boolean;
1094
+ metadata?: Record<string, any>;
1095
+ };
1096
+ type UserQuestionResolution = {
1097
+ id: string;
1098
+ answers?: UserQuestionAnswerSet;
1099
+ answeredBy?: string;
1100
+ notes?: string;
1101
+ /** When true the tool call is reported back as cancelled / unanswered. */
1102
+ cancelled?: boolean;
1103
+ };
1104
+ type UserQuestionEvent = {
1105
+ type: "user_question";
1106
+ status: "pending" | "answered" | "cancelled";
1107
+ id: string;
1108
+ toolCallId: string;
1109
+ questions?: UserQuestionItem[];
1110
+ answers?: UserQuestionAnswerSet;
1111
+ answeredBy?: string;
1112
+ allowFreeText?: boolean;
1113
+ };
1114
+ type HumanInTheLoopAskUserConfig = {
1115
+ enabled: boolean;
1116
+ allowFreeText: boolean;
1117
+ promptOverride?: string;
1118
+ };
1119
+ type HumanInTheLoopRuntimeConfig = {
1120
+ askUser?: HumanInTheLoopAskUserConfig;
1121
+ };
1122
+ type HumanInTheLoopOptions = {
1123
+ askUser?: boolean | {
1124
+ /** Allow the user to type a custom "Other" answer. Default: true. */
1125
+ allowFreeText?: boolean;
1126
+ /** Override the built-in tool description. */
1127
+ promptOverride?: string;
1128
+ /** Convenience: subscribe to user_question events without setting up onEvent. */
1129
+ onQuestion?: (event: UserQuestionEvent) => void;
1130
+ };
1131
+ };
1035
1132
  type GuardrailEvent = {
1036
1133
  type: "guardrail";
1037
1134
  phase: GuardrailPhase;
@@ -1043,7 +1140,7 @@ type GuardrailEvent = {
1043
1140
  reason?: string;
1044
1141
  details?: Record<string, any>;
1045
1142
  };
1046
- type SmartAgentEvent = ToolCallEvent | ToolApprovalEvent | PlanEvent | SummarizationEvent | FinalAnswerEvent | MetadataEvent | HandoffEvent | GuardrailEvent | ProgressEvent | StreamEvent | CancelledEvent | ReflectionEvent;
1143
+ type SmartAgentEvent = ToolCallEvent | ToolApprovalEvent | UserQuestionEvent | PlanEvent | SummarizationEvent | FinalAnswerEvent | MetadataEvent | HandoffEvent | GuardrailEvent | ProgressEvent | StreamEvent | CancelledEvent | ReflectionEvent;
1047
1144
  type ReflectionEvent = {
1048
1145
  type: "reflection";
1049
1146
  id: string;
@@ -1136,6 +1233,7 @@ type AgentInstance<TOutput = unknown> = {
1136
1233
  snapshot: (state: SmartState, options?: SnapshotOptions) => AgentSnapshot;
1137
1234
  resume: (snapshot: AgentSnapshot, config?: InvokeConfig, restoreOptions?: RestoreSnapshotOptions) => Promise<AgentInvokeResult<TOutput>>;
1138
1235
  resolveToolApproval: (state: SmartState, resolution: ToolApprovalResolution) => SmartState;
1236
+ resolveUserQuestion: (state: SmartState, resolution: UserQuestionResolution) => SmartState;
1139
1237
  asTool: (opts: {
1140
1238
  toolName: string;
1141
1239
  description?: string;
@@ -1580,6 +1678,16 @@ declare function restoreSnapshot(snapshot: AgentSnapshot, restoreOptions?: Resto
1580
1678
 
1581
1679
  declare function resolveToolApprovalState(state: SmartState, resolution: ToolApprovalResolution): SmartState;
1582
1680
 
1681
+ declare function resolveUserQuestionState(state: SmartState, resolution: UserQuestionResolution): SmartState;
1682
+
1683
+ type AskUserStateRef = {
1684
+ pendingUserQuestions?: PendingUserQuestion[];
1685
+ ctx?: Record<string, any>;
1686
+ __onEvent?: (event: any) => void;
1687
+ __currentToolCallId?: string;
1688
+ };
1689
+ declare function createAskUserQuestionTool(stateRef: AskUserStateRef, config: HumanInTheLoopAskUserConfig): ToolInterface<any, any, any>;
1690
+
1583
1691
  declare function fromLangchainTools<T extends ToolInterface = ToolInterface>(tools: any[]): T[];
1584
1692
 
1585
1693
  declare function fileSink(path?: string): TraceSinkConfig;
@@ -1975,4 +2083,4 @@ declare function fromNativeProvider(provider: BaseProvider, options?: NativeMode
1975
2083
  */
1976
2084
  declare function createProvider(config: ProviderConfig): BaseProvider;
1977
2085
 
1978
- 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 TokenCounter, type TokenUsage, type ToolApprovalEvent, type ToolApprovalResolution, type ToolApprovalStatus, ToolBasedStrategy, type ToolCachePolicy, type ToolCallEvent, type ToolInterface, type ToolResponseClassification, type ToolResponseRetentionPolicy, type ToolRetryPolicy, 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, defaultTokenCounter, emptyUsage, evaluateGuardrails, fileSink, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, getTokenCounter, hasToolResponseRecoveryReference, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, resolveMemoryStore, resolveStrategy, resolveToolApprovalState, restoreSnapshot, runSmartAgentEvalHarness, setTokenCounter, startStreamingSession, traceSessionToOtlp, withTools, writeSummaryFactsToMemory };
2086
+ 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, type HumanInTheLoopAskUserConfig, type HumanInTheLoopOptions, type HumanInTheLoopRuntimeConfig, 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 PendingUserQuestion, 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 TokenCounter, type TokenUsage, type ToolApprovalEvent, type ToolApprovalResolution, type ToolApprovalStatus, ToolBasedStrategy, type ToolCachePolicy, type ToolCallEvent, type ToolInterface, type ToolResponseClassification, type ToolResponseRetentionPolicy, type ToolRetryPolicy, 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, type UserQuestionAnswer, type UserQuestionAnswerSet, type UserQuestionEvent, type UserQuestionItem, type UserQuestionOption, type UserQuestionResolution, type UserQuestionStatus, VertexProvider, type VertexProviderConfig, agentVerdictRule, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createAskUserQuestionTool, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGetToolResponseTool, createGuardrail, createJsonGuardrail, createManageTodoTool, createProvider, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, defaultTokenCounter, emptyUsage, evaluateGuardrails, fileSink, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, getTokenCounter, hasToolResponseRecoveryReference, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, resolveMemoryStore, resolveStrategy, resolveToolApprovalState, resolveUserQuestionState, restoreSnapshot, runSmartAgentEvalHarness, setTokenCounter, startStreamingSession, traceSessionToOtlp, withTools, writeSummaryFactsToMemory };
package/dist/index.d.ts CHANGED
@@ -299,6 +299,12 @@ type AgentOptions = {
299
299
  cachedInputTokens?: number;
300
300
  reasoningTokens?: number;
301
301
  }) => number;
302
+ /**
303
+ * Human-in-the-loop hooks. When `askUser` is enabled, the agent gains a
304
+ * built-in `ask_user_question` tool that pauses the run with structured
305
+ * questions for the host application to answer.
306
+ */
307
+ humanInTheLoop?: HumanInTheLoopOptions;
302
308
  };
303
309
  type ReasoningLevel = "low" | "medium" | "high";
304
310
  type ReflectionCadence = "off" | "every_turn" | "after_tool" | "on_branch";
@@ -538,6 +544,8 @@ type SmartAgentOptions = {
538
544
  tokenCounter?: (text: string) => number;
539
545
  /** See AgentOptions.costEstimator. */
540
546
  costEstimator?: AgentOptions["costEstimator"];
547
+ /** See AgentOptions.humanInTheLoop. */
548
+ humanInTheLoop?: HumanInTheLoopOptions;
541
549
  };
542
550
  type AgentRuntimeConfig = {
543
551
  name?: string;
@@ -554,6 +562,7 @@ type AgentRuntimeConfig = {
554
562
  tracing?: TracingConfig;
555
563
  runtimeProfile?: RuntimeProfile;
556
564
  smart?: ResolvedSmartAgentConfig;
565
+ humanInTheLoop?: HumanInTheLoopRuntimeConfig;
557
566
  };
558
567
  type TraceMessageSection = {
559
568
  id?: string;
@@ -786,6 +795,7 @@ type AgentState = {
786
795
  metadata?: Record<string, any>;
787
796
  ctx?: Record<string, any>;
788
797
  pendingApprovals?: PendingToolApproval[];
798
+ pendingUserQuestions?: PendingUserQuestion[];
789
799
  usage?: {
790
800
  perRequest: Array<{
791
801
  id: string;
@@ -1032,6 +1042,93 @@ type ToolApprovalEvent = {
1032
1042
  decidedBy?: string;
1033
1043
  comment?: string;
1034
1044
  };
1045
+ type UserQuestionOption = {
1046
+ /** Label shown to the user. */
1047
+ label: string;
1048
+ /** Value returned in the resolution. Defaults to `label` when omitted. */
1049
+ value?: string;
1050
+ /** Optional helper text rendered alongside the option. */
1051
+ description?: string;
1052
+ /** Optional code / ASCII preview rendered when the option is focused. */
1053
+ preview?: string;
1054
+ };
1055
+ type UserQuestionItem = {
1056
+ /** The full question text shown to the user. */
1057
+ question: string;
1058
+ /** Short label (chip / tag) displayed alongside the question. */
1059
+ header?: string;
1060
+ /** When true the user may pick multiple options. Default: false. */
1061
+ multiSelect?: boolean;
1062
+ /** Placeholder shown for the free-text input (when enabled globally). */
1063
+ placeholder?: string;
1064
+ /** Predefined options; omit for a pure free-text question. */
1065
+ options?: UserQuestionOption[];
1066
+ /** When true the user must answer this item. Default: true. */
1067
+ required?: boolean;
1068
+ };
1069
+ type UserQuestionStatus = "pending" | "answered" | "cancelled" | "executed";
1070
+ type UserQuestionAnswer = {
1071
+ /** Selected option values. Single-select questions report exactly one entry. */
1072
+ values: string[];
1073
+ /** Populated when the user typed a custom answer (only when free-text is enabled). */
1074
+ freeText?: string;
1075
+ /** Optional reviewer notes. */
1076
+ notes?: string;
1077
+ };
1078
+ /** Keyed by the question text (or `header`, if both questions share text). */
1079
+ type UserQuestionAnswerSet = Record<string, UserQuestionAnswer>;
1080
+ type PendingUserQuestion = {
1081
+ id: string;
1082
+ toolCallId: string;
1083
+ toolName: "ask_user_question";
1084
+ questions: UserQuestionItem[];
1085
+ status: UserQuestionStatus;
1086
+ requestedAt: string;
1087
+ answeredAt?: string;
1088
+ answeredBy?: string;
1089
+ answers?: UserQuestionAnswerSet;
1090
+ cancelled?: boolean;
1091
+ notes?: string;
1092
+ /** Snapshot of the global free-text flag at request time, for UI rendering. */
1093
+ allowFreeText?: boolean;
1094
+ metadata?: Record<string, any>;
1095
+ };
1096
+ type UserQuestionResolution = {
1097
+ id: string;
1098
+ answers?: UserQuestionAnswerSet;
1099
+ answeredBy?: string;
1100
+ notes?: string;
1101
+ /** When true the tool call is reported back as cancelled / unanswered. */
1102
+ cancelled?: boolean;
1103
+ };
1104
+ type UserQuestionEvent = {
1105
+ type: "user_question";
1106
+ status: "pending" | "answered" | "cancelled";
1107
+ id: string;
1108
+ toolCallId: string;
1109
+ questions?: UserQuestionItem[];
1110
+ answers?: UserQuestionAnswerSet;
1111
+ answeredBy?: string;
1112
+ allowFreeText?: boolean;
1113
+ };
1114
+ type HumanInTheLoopAskUserConfig = {
1115
+ enabled: boolean;
1116
+ allowFreeText: boolean;
1117
+ promptOverride?: string;
1118
+ };
1119
+ type HumanInTheLoopRuntimeConfig = {
1120
+ askUser?: HumanInTheLoopAskUserConfig;
1121
+ };
1122
+ type HumanInTheLoopOptions = {
1123
+ askUser?: boolean | {
1124
+ /** Allow the user to type a custom "Other" answer. Default: true. */
1125
+ allowFreeText?: boolean;
1126
+ /** Override the built-in tool description. */
1127
+ promptOverride?: string;
1128
+ /** Convenience: subscribe to user_question events without setting up onEvent. */
1129
+ onQuestion?: (event: UserQuestionEvent) => void;
1130
+ };
1131
+ };
1035
1132
  type GuardrailEvent = {
1036
1133
  type: "guardrail";
1037
1134
  phase: GuardrailPhase;
@@ -1043,7 +1140,7 @@ type GuardrailEvent = {
1043
1140
  reason?: string;
1044
1141
  details?: Record<string, any>;
1045
1142
  };
1046
- type SmartAgentEvent = ToolCallEvent | ToolApprovalEvent | PlanEvent | SummarizationEvent | FinalAnswerEvent | MetadataEvent | HandoffEvent | GuardrailEvent | ProgressEvent | StreamEvent | CancelledEvent | ReflectionEvent;
1143
+ type SmartAgentEvent = ToolCallEvent | ToolApprovalEvent | UserQuestionEvent | PlanEvent | SummarizationEvent | FinalAnswerEvent | MetadataEvent | HandoffEvent | GuardrailEvent | ProgressEvent | StreamEvent | CancelledEvent | ReflectionEvent;
1047
1144
  type ReflectionEvent = {
1048
1145
  type: "reflection";
1049
1146
  id: string;
@@ -1136,6 +1233,7 @@ type AgentInstance<TOutput = unknown> = {
1136
1233
  snapshot: (state: SmartState, options?: SnapshotOptions) => AgentSnapshot;
1137
1234
  resume: (snapshot: AgentSnapshot, config?: InvokeConfig, restoreOptions?: RestoreSnapshotOptions) => Promise<AgentInvokeResult<TOutput>>;
1138
1235
  resolveToolApproval: (state: SmartState, resolution: ToolApprovalResolution) => SmartState;
1236
+ resolveUserQuestion: (state: SmartState, resolution: UserQuestionResolution) => SmartState;
1139
1237
  asTool: (opts: {
1140
1238
  toolName: string;
1141
1239
  description?: string;
@@ -1580,6 +1678,16 @@ declare function restoreSnapshot(snapshot: AgentSnapshot, restoreOptions?: Resto
1580
1678
 
1581
1679
  declare function resolveToolApprovalState(state: SmartState, resolution: ToolApprovalResolution): SmartState;
1582
1680
 
1681
+ declare function resolveUserQuestionState(state: SmartState, resolution: UserQuestionResolution): SmartState;
1682
+
1683
+ type AskUserStateRef = {
1684
+ pendingUserQuestions?: PendingUserQuestion[];
1685
+ ctx?: Record<string, any>;
1686
+ __onEvent?: (event: any) => void;
1687
+ __currentToolCallId?: string;
1688
+ };
1689
+ declare function createAskUserQuestionTool(stateRef: AskUserStateRef, config: HumanInTheLoopAskUserConfig): ToolInterface<any, any, any>;
1690
+
1583
1691
  declare function fromLangchainTools<T extends ToolInterface = ToolInterface>(tools: any[]): T[];
1584
1692
 
1585
1693
  declare function fileSink(path?: string): TraceSinkConfig;
@@ -1975,4 +2083,4 @@ declare function fromNativeProvider(provider: BaseProvider, options?: NativeMode
1975
2083
  */
1976
2084
  declare function createProvider(config: ProviderConfig): BaseProvider;
1977
2085
 
1978
- 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 TokenCounter, type TokenUsage, type ToolApprovalEvent, type ToolApprovalResolution, type ToolApprovalStatus, ToolBasedStrategy, type ToolCachePolicy, type ToolCallEvent, type ToolInterface, type ToolResponseClassification, type ToolResponseRetentionPolicy, type ToolRetryPolicy, 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, defaultTokenCounter, emptyUsage, evaluateGuardrails, fileSink, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, getTokenCounter, hasToolResponseRecoveryReference, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, resolveMemoryStore, resolveStrategy, resolveToolApprovalState, restoreSnapshot, runSmartAgentEvalHarness, setTokenCounter, startStreamingSession, traceSessionToOtlp, withTools, writeSummaryFactsToMemory };
2086
+ 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, type HumanInTheLoopAskUserConfig, type HumanInTheLoopOptions, type HumanInTheLoopRuntimeConfig, 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 PendingUserQuestion, 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 TokenCounter, type TokenUsage, type ToolApprovalEvent, type ToolApprovalResolution, type ToolApprovalStatus, ToolBasedStrategy, type ToolCachePolicy, type ToolCallEvent, type ToolInterface, type ToolResponseClassification, type ToolResponseRetentionPolicy, type ToolRetryPolicy, 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, type UserQuestionAnswer, type UserQuestionAnswerSet, type UserQuestionEvent, type UserQuestionItem, type UserQuestionOption, type UserQuestionResolution, type UserQuestionStatus, VertexProvider, type VertexProviderConfig, agentVerdictRule, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createAskUserQuestionTool, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGetToolResponseTool, createGuardrail, createJsonGuardrail, createManageTodoTool, createProvider, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, defaultTokenCounter, emptyUsage, evaluateGuardrails, fileSink, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, getTokenCounter, hasToolResponseRecoveryReference, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, resolveMemoryStore, resolveStrategy, resolveToolApprovalState, resolveUserQuestionState, restoreSnapshot, runSmartAgentEvalHarness, setTokenCounter, startStreamingSession, traceSessionToOtlp, withTools, writeSummaryFactsToMemory };