@cognipeer/agent-sdk 0.7.0 → 0.7.1

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
@@ -306,8 +306,16 @@ type AgentOptions = {
306
306
  */
307
307
  humanInTheLoop?: HumanInTheLoopOptions;
308
308
  };
309
- type ReasoningLevel = "low" | "medium" | "high";
310
- type ReflectionCadence = "off" | "every_turn" | "after_tool" | "on_branch";
309
+ type ReasoningLevel = "minimal" | "low" | "medium" | "high";
310
+ type ReflectionCadence = "off" | "every_turn" | "after_tool" | "on_branch" | "initial_then_after_tool";
311
+ /** Context passed to reflection lifecycle hooks. */
312
+ type ReflectionHookContext = {
313
+ state: SmartState;
314
+ /** The turn number (state.toolCallCount) at the time of the decision. */
315
+ turn: number;
316
+ trigger: ReflectionCadence;
317
+ ranToolsThisTurn: boolean;
318
+ };
311
319
  type ReflectionConfig = {
312
320
  enabled?: boolean;
313
321
  cadence?: ReflectionCadence;
@@ -337,6 +345,29 @@ type ReflectionConfig = {
337
345
  * turn, etc. Independent of `cadence`.
338
346
  */
339
347
  everyNTurns?: number;
348
+ /**
349
+ * Where to route the reflection text in addition to the reflection record:
350
+ * - "memory" — store as a low-confidence agent-scoped `MemoryFact`.
351
+ * - "plan" — append the note to the active plan's `lastReflection` field.
352
+ * - "none" — record only (default).
353
+ */
354
+ feedTo?: "memory" | "plan" | "none";
355
+ /**
356
+ * Custom predicate that overrides the built-in cadence decision. Return true
357
+ * to force a reflection on this turn, false to skip. `maxPerRun`/`everyNTurns`
358
+ * throttles still apply on top of this.
359
+ */
360
+ shouldReflect?: (ctx: ReflectionHookContext) => boolean;
361
+ /**
362
+ * Build the reflection prompt body. Receives the resolved default prompt and
363
+ * the char budget; return the prompt text to send. Overrides `promptTemplate`.
364
+ */
365
+ buildPrompt?: (ctx: ReflectionHookContext & {
366
+ defaultPrompt: string;
367
+ maxChars: number;
368
+ }) => string;
369
+ /** Side-effect hook invoked after a reflection record is produced. */
370
+ onReflection?: (record: ReflectionRecord, ctx: ReflectionHookContext) => void;
340
371
  };
341
372
  type NativeReasoningConfig = {
342
373
  effort?: "minimal" | "low" | "medium" | "high";
@@ -883,6 +914,7 @@ type SmartState = AgentState & {
883
914
  steps: PlanStepRecord[];
884
915
  lastUpdated?: string;
885
916
  adherenceScore?: number;
917
+ lastReflection?: string;
886
918
  } | null;
887
919
  planVersion?: number;
888
920
  /**
@@ -1729,6 +1761,39 @@ declare function createAskUserQuestionTool(stateRef: AskUserStateRef, config: Hu
1729
1761
 
1730
1762
  declare function fromLangchainTools<T extends ToolInterface = ToolInterface>(tools: any[]): T[];
1731
1763
 
1764
+ type ResolvedReflectionConfig = {
1765
+ enabled: boolean;
1766
+ cadence: ReflectionCadence;
1767
+ mode: "piggyback" | "separate";
1768
+ maxTokens: number;
1769
+ maxChars: number;
1770
+ keepLast: number;
1771
+ summarize: boolean;
1772
+ promptTemplate?: string;
1773
+ emitEvents: boolean;
1774
+ maxPerRun?: number;
1775
+ everyNTurns: number;
1776
+ feedTo: "memory" | "plan" | "none";
1777
+ shouldReflect?: (ctx: ReflectionHookContext) => boolean;
1778
+ buildPrompt?: (ctx: ReflectionHookContext & {
1779
+ defaultPrompt: string;
1780
+ maxChars: number;
1781
+ }) => string;
1782
+ onReflection?: (record: ReflectionRecord, ctx: ReflectionHookContext) => void;
1783
+ };
1784
+ type ResolvedReasoning = {
1785
+ enabled: boolean;
1786
+ level: ReasoningLevel;
1787
+ native?: NativeReasoningConfig;
1788
+ reflection: ResolvedReflectionConfig;
1789
+ };
1790
+ /**
1791
+ * Validates a user-supplied ReasoningConfig and throws a descriptive error for
1792
+ * obviously-wrong values. Pure; safe to call before resolveReasoning.
1793
+ */
1794
+ declare function validateReasoningConfig(input: ReasoningConfig | undefined): void;
1795
+ declare function resolveReasoning(input: ReasoningConfig | undefined): ResolvedReasoning | undefined;
1796
+
1732
1797
  declare function fileSink(path?: string): TraceSinkConfig;
1733
1798
  type CustomSinkArg = ((event: TraceEventRecord) => void | Promise<void>) | {
1734
1799
  onEvent?: (event: TraceEventRecord) => void | Promise<void>;
@@ -1781,12 +1846,35 @@ type ToolCall = {
1781
1846
  name: string;
1782
1847
  arguments: string;
1783
1848
  };
1849
+ /**
1850
+ * A provider-native reasoning/thinking block. Captured from the model response
1851
+ * and replayed verbatim on subsequent turns (required by Anthropic extended
1852
+ * thinking when tools are involved — the `signature` must round-trip intact).
1853
+ */
1854
+ type ReasoningBlock = {
1855
+ type: "thinking" | "redacted_thinking";
1856
+ /** Plain-text thinking content (absent for redacted blocks). */
1857
+ text?: string;
1858
+ /** Cryptographic signature Anthropic requires to be echoed back verbatim. */
1859
+ signature?: string;
1860
+ /** Opaque payload for redacted_thinking blocks. */
1861
+ data?: string;
1862
+ };
1863
+ /** Captured reasoning payload attached to assistant turns / responses. */
1864
+ type ReasoningPayload = {
1865
+ /** Verbatim provider blocks to replay on the next turn. */
1866
+ blocks?: ReasoningBlock[];
1867
+ /** Human-readable reasoning summary, when the provider exposes one. */
1868
+ summary?: string;
1869
+ };
1784
1870
  type UnifiedMessage = {
1785
1871
  role: MessageRole;
1786
1872
  content: string | ContentPart[];
1787
1873
  name?: string;
1788
1874
  toolCalls?: ToolCall[];
1789
1875
  toolCallId?: string;
1876
+ /** Native reasoning blocks to replay verbatim (Anthropic/Bedrock thinking). */
1877
+ reasoning?: ReasoningPayload;
1790
1878
  };
1791
1879
  type ToolDefinition = {
1792
1880
  name: string;
@@ -1853,6 +1941,8 @@ type ChatCompletionResponse = {
1853
1941
  toolCalls: ToolCall[];
1854
1942
  usage: TokenUsage;
1855
1943
  finishReason: FinishReason;
1944
+ /** Native reasoning blocks + summary captured from the response, if any. */
1945
+ reasoning?: ReasoningPayload;
1856
1946
  raw: any;
1857
1947
  };
1858
1948
  type ChatCompletionChunk = {
@@ -1861,6 +1951,8 @@ type ChatCompletionChunk = {
1861
1951
  delta: {
1862
1952
  content?: string;
1863
1953
  toolCalls?: Partial<ToolCall>[];
1954
+ /** Incremental reasoning text / signature deltas (Anthropic thinking). */
1955
+ reasoning?: ReasoningPayload;
1864
1956
  };
1865
1957
  usage?: TokenUsage;
1866
1958
  finishReason?: FinishReason;
@@ -1988,9 +2080,19 @@ declare class OpenAIProvider extends BaseProvider {
1988
2080
  protected readonly defaultModel: string;
1989
2081
  protected readonly defaultHeaders: Record<string, string>;
1990
2082
  constructor(config: OpenAIProviderConfig);
2083
+ /** True when the request targets a reasoning model (o-series / gpt-5) so we
2084
+ * should route through the Responses API, which exposes `reasoning.effort`
2085
+ * and reasoning summaries. Chat Completions silently drops these. */
2086
+ protected useResponsesApi(request: ChatCompletionRequest): boolean;
1991
2087
  complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
1992
2088
  completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
1993
2089
  protected buildRequestBody(request: ChatCompletionRequest, stream: boolean): Record<string, any>;
2090
+ protected completeResponses(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
2091
+ protected buildResponsesBody(request: ChatCompletionRequest): Record<string, any>;
2092
+ /** Maps a unified message to a Responses API `input` item. */
2093
+ protected toResponsesInput(m: UnifiedMessage): Record<string, any>;
2094
+ protected responsesFetch(body: Record<string, any>): Promise<Response>;
2095
+ protected parseResponsesResponse(json: any, modelId: string): ChatCompletionResponse;
1994
2096
  protected toOpenAIMessage(m: UnifiedMessage): Record<string, any>;
1995
2097
  protected toOpenAITool(t: ToolDefinition): Record<string, any>;
1996
2098
  protected doFetch(body: Record<string, any>): Promise<Response>;
@@ -2025,6 +2127,10 @@ declare class AzureProvider extends OpenAIProvider {
2025
2127
  private readonly azureApiKey;
2026
2128
  constructor(config: AzureProviderConfig);
2027
2129
  protected doFetch(body: Record<string, any>): Promise<Response>;
2130
+ /** Azure exposes the Responses API at /openai/responses with api-key auth.
2131
+ * Reasoning summaries require a preview api-version; callers can override via
2132
+ * the `apiVersion` config. */
2133
+ protected responsesFetch(body: Record<string, any>): Promise<Response>;
2028
2134
  }
2029
2135
 
2030
2136
  declare class OpenAICompatibleProvider extends OpenAIProvider {
@@ -2122,4 +2228,4 @@ declare function fromNativeProvider(provider: BaseProvider, options?: NativeMode
2122
2228
  */
2123
2229
  declare function createProvider(config: ProviderConfig): BaseProvider;
2124
2230
 
2125
- 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 TraceToolDetails, type TraceToolResponseSection, 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 };
2231
+ 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 ReflectionHookContext, 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 TraceToolDetails, type TraceToolResponseSection, 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, resolveReasoning, resolveStrategy, resolveToolApprovalState, resolveUserQuestionState, restoreSnapshot, runSmartAgentEvalHarness, setTokenCounter, startStreamingSession, traceSessionToOtlp, validateReasoningConfig, withTools, writeSummaryFactsToMemory };
package/dist/index.d.ts CHANGED
@@ -306,8 +306,16 @@ type AgentOptions = {
306
306
  */
307
307
  humanInTheLoop?: HumanInTheLoopOptions;
308
308
  };
309
- type ReasoningLevel = "low" | "medium" | "high";
310
- type ReflectionCadence = "off" | "every_turn" | "after_tool" | "on_branch";
309
+ type ReasoningLevel = "minimal" | "low" | "medium" | "high";
310
+ type ReflectionCadence = "off" | "every_turn" | "after_tool" | "on_branch" | "initial_then_after_tool";
311
+ /** Context passed to reflection lifecycle hooks. */
312
+ type ReflectionHookContext = {
313
+ state: SmartState;
314
+ /** The turn number (state.toolCallCount) at the time of the decision. */
315
+ turn: number;
316
+ trigger: ReflectionCadence;
317
+ ranToolsThisTurn: boolean;
318
+ };
311
319
  type ReflectionConfig = {
312
320
  enabled?: boolean;
313
321
  cadence?: ReflectionCadence;
@@ -337,6 +345,29 @@ type ReflectionConfig = {
337
345
  * turn, etc. Independent of `cadence`.
338
346
  */
339
347
  everyNTurns?: number;
348
+ /**
349
+ * Where to route the reflection text in addition to the reflection record:
350
+ * - "memory" — store as a low-confidence agent-scoped `MemoryFact`.
351
+ * - "plan" — append the note to the active plan's `lastReflection` field.
352
+ * - "none" — record only (default).
353
+ */
354
+ feedTo?: "memory" | "plan" | "none";
355
+ /**
356
+ * Custom predicate that overrides the built-in cadence decision. Return true
357
+ * to force a reflection on this turn, false to skip. `maxPerRun`/`everyNTurns`
358
+ * throttles still apply on top of this.
359
+ */
360
+ shouldReflect?: (ctx: ReflectionHookContext) => boolean;
361
+ /**
362
+ * Build the reflection prompt body. Receives the resolved default prompt and
363
+ * the char budget; return the prompt text to send. Overrides `promptTemplate`.
364
+ */
365
+ buildPrompt?: (ctx: ReflectionHookContext & {
366
+ defaultPrompt: string;
367
+ maxChars: number;
368
+ }) => string;
369
+ /** Side-effect hook invoked after a reflection record is produced. */
370
+ onReflection?: (record: ReflectionRecord, ctx: ReflectionHookContext) => void;
340
371
  };
341
372
  type NativeReasoningConfig = {
342
373
  effort?: "minimal" | "low" | "medium" | "high";
@@ -883,6 +914,7 @@ type SmartState = AgentState & {
883
914
  steps: PlanStepRecord[];
884
915
  lastUpdated?: string;
885
916
  adherenceScore?: number;
917
+ lastReflection?: string;
886
918
  } | null;
887
919
  planVersion?: number;
888
920
  /**
@@ -1729,6 +1761,39 @@ declare function createAskUserQuestionTool(stateRef: AskUserStateRef, config: Hu
1729
1761
 
1730
1762
  declare function fromLangchainTools<T extends ToolInterface = ToolInterface>(tools: any[]): T[];
1731
1763
 
1764
+ type ResolvedReflectionConfig = {
1765
+ enabled: boolean;
1766
+ cadence: ReflectionCadence;
1767
+ mode: "piggyback" | "separate";
1768
+ maxTokens: number;
1769
+ maxChars: number;
1770
+ keepLast: number;
1771
+ summarize: boolean;
1772
+ promptTemplate?: string;
1773
+ emitEvents: boolean;
1774
+ maxPerRun?: number;
1775
+ everyNTurns: number;
1776
+ feedTo: "memory" | "plan" | "none";
1777
+ shouldReflect?: (ctx: ReflectionHookContext) => boolean;
1778
+ buildPrompt?: (ctx: ReflectionHookContext & {
1779
+ defaultPrompt: string;
1780
+ maxChars: number;
1781
+ }) => string;
1782
+ onReflection?: (record: ReflectionRecord, ctx: ReflectionHookContext) => void;
1783
+ };
1784
+ type ResolvedReasoning = {
1785
+ enabled: boolean;
1786
+ level: ReasoningLevel;
1787
+ native?: NativeReasoningConfig;
1788
+ reflection: ResolvedReflectionConfig;
1789
+ };
1790
+ /**
1791
+ * Validates a user-supplied ReasoningConfig and throws a descriptive error for
1792
+ * obviously-wrong values. Pure; safe to call before resolveReasoning.
1793
+ */
1794
+ declare function validateReasoningConfig(input: ReasoningConfig | undefined): void;
1795
+ declare function resolveReasoning(input: ReasoningConfig | undefined): ResolvedReasoning | undefined;
1796
+
1732
1797
  declare function fileSink(path?: string): TraceSinkConfig;
1733
1798
  type CustomSinkArg = ((event: TraceEventRecord) => void | Promise<void>) | {
1734
1799
  onEvent?: (event: TraceEventRecord) => void | Promise<void>;
@@ -1781,12 +1846,35 @@ type ToolCall = {
1781
1846
  name: string;
1782
1847
  arguments: string;
1783
1848
  };
1849
+ /**
1850
+ * A provider-native reasoning/thinking block. Captured from the model response
1851
+ * and replayed verbatim on subsequent turns (required by Anthropic extended
1852
+ * thinking when tools are involved — the `signature` must round-trip intact).
1853
+ */
1854
+ type ReasoningBlock = {
1855
+ type: "thinking" | "redacted_thinking";
1856
+ /** Plain-text thinking content (absent for redacted blocks). */
1857
+ text?: string;
1858
+ /** Cryptographic signature Anthropic requires to be echoed back verbatim. */
1859
+ signature?: string;
1860
+ /** Opaque payload for redacted_thinking blocks. */
1861
+ data?: string;
1862
+ };
1863
+ /** Captured reasoning payload attached to assistant turns / responses. */
1864
+ type ReasoningPayload = {
1865
+ /** Verbatim provider blocks to replay on the next turn. */
1866
+ blocks?: ReasoningBlock[];
1867
+ /** Human-readable reasoning summary, when the provider exposes one. */
1868
+ summary?: string;
1869
+ };
1784
1870
  type UnifiedMessage = {
1785
1871
  role: MessageRole;
1786
1872
  content: string | ContentPart[];
1787
1873
  name?: string;
1788
1874
  toolCalls?: ToolCall[];
1789
1875
  toolCallId?: string;
1876
+ /** Native reasoning blocks to replay verbatim (Anthropic/Bedrock thinking). */
1877
+ reasoning?: ReasoningPayload;
1790
1878
  };
1791
1879
  type ToolDefinition = {
1792
1880
  name: string;
@@ -1853,6 +1941,8 @@ type ChatCompletionResponse = {
1853
1941
  toolCalls: ToolCall[];
1854
1942
  usage: TokenUsage;
1855
1943
  finishReason: FinishReason;
1944
+ /** Native reasoning blocks + summary captured from the response, if any. */
1945
+ reasoning?: ReasoningPayload;
1856
1946
  raw: any;
1857
1947
  };
1858
1948
  type ChatCompletionChunk = {
@@ -1861,6 +1951,8 @@ type ChatCompletionChunk = {
1861
1951
  delta: {
1862
1952
  content?: string;
1863
1953
  toolCalls?: Partial<ToolCall>[];
1954
+ /** Incremental reasoning text / signature deltas (Anthropic thinking). */
1955
+ reasoning?: ReasoningPayload;
1864
1956
  };
1865
1957
  usage?: TokenUsage;
1866
1958
  finishReason?: FinishReason;
@@ -1988,9 +2080,19 @@ declare class OpenAIProvider extends BaseProvider {
1988
2080
  protected readonly defaultModel: string;
1989
2081
  protected readonly defaultHeaders: Record<string, string>;
1990
2082
  constructor(config: OpenAIProviderConfig);
2083
+ /** True when the request targets a reasoning model (o-series / gpt-5) so we
2084
+ * should route through the Responses API, which exposes `reasoning.effort`
2085
+ * and reasoning summaries. Chat Completions silently drops these. */
2086
+ protected useResponsesApi(request: ChatCompletionRequest): boolean;
1991
2087
  complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
1992
2088
  completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
1993
2089
  protected buildRequestBody(request: ChatCompletionRequest, stream: boolean): Record<string, any>;
2090
+ protected completeResponses(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
2091
+ protected buildResponsesBody(request: ChatCompletionRequest): Record<string, any>;
2092
+ /** Maps a unified message to a Responses API `input` item. */
2093
+ protected toResponsesInput(m: UnifiedMessage): Record<string, any>;
2094
+ protected responsesFetch(body: Record<string, any>): Promise<Response>;
2095
+ protected parseResponsesResponse(json: any, modelId: string): ChatCompletionResponse;
1994
2096
  protected toOpenAIMessage(m: UnifiedMessage): Record<string, any>;
1995
2097
  protected toOpenAITool(t: ToolDefinition): Record<string, any>;
1996
2098
  protected doFetch(body: Record<string, any>): Promise<Response>;
@@ -2025,6 +2127,10 @@ declare class AzureProvider extends OpenAIProvider {
2025
2127
  private readonly azureApiKey;
2026
2128
  constructor(config: AzureProviderConfig);
2027
2129
  protected doFetch(body: Record<string, any>): Promise<Response>;
2130
+ /** Azure exposes the Responses API at /openai/responses with api-key auth.
2131
+ * Reasoning summaries require a preview api-version; callers can override via
2132
+ * the `apiVersion` config. */
2133
+ protected responsesFetch(body: Record<string, any>): Promise<Response>;
2028
2134
  }
2029
2135
 
2030
2136
  declare class OpenAICompatibleProvider extends OpenAIProvider {
@@ -2122,4 +2228,4 @@ declare function fromNativeProvider(provider: BaseProvider, options?: NativeMode
2122
2228
  */
2123
2229
  declare function createProvider(config: ProviderConfig): BaseProvider;
2124
2230
 
2125
- 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 TraceToolDetails, type TraceToolResponseSection, 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 };
2231
+ 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 ReflectionHookContext, 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 TraceToolDetails, type TraceToolResponseSection, 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, resolveReasoning, resolveStrategy, resolveToolApprovalState, resolveUserQuestionState, restoreSnapshot, runSmartAgentEvalHarness, setTokenCounter, startStreamingSession, traceSessionToOtlp, validateReasoningConfig, withTools, writeSummaryFactsToMemory };