llmist 1.6.1 → 1.7.0

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
@@ -1,7 +1,7 @@
1
1
  import { ZodType, ZodTypeAny } from 'zod';
2
2
  export { z } from 'zod';
3
- import { A as AgentHooks, q as ModelRegistry, I as IConversationManager, b as LLMMessage, S as StreamEvent, T as TokenUsage, G as GadgetRegistry, a as LLMStreamChunk, C as CompactionStrategy, R as ResolvedCompactionConfig, r as CompactionContext, s as CompactionResult, t as LLMist, u as CompactionConfig, v as CompactionEvent, w as CompactionStats, H as HintTemplate, x as GadgetExample, B as BaseGadget, P as ParsedGadgetCall, y as GadgetExecutionResult, z as ProviderAdapter, D as ModelDescriptor, E as ModelSpec, F as LLMGenerationOptions, L as LLMStream } from './mock-stream-Cc47j12U.cjs';
4
- export { V as AfterGadgetExecutionAction, W as AfterGadgetExecutionControllerContext, X as AfterLLMCallAction, Y as AfterLLMCallControllerContext, Z as AfterLLMErrorAction, K as AgentBuilder, _ as AgentOptions, $ as BeforeGadgetExecutionAction, a0 as BeforeLLMCallAction, a1 as ChunkInterceptorContext, a2 as Controllers, ao as CostEstimate, aj as DEFAULT_COMPACTION_CONFIG, ay as DEFAULT_HINTS, az as DEFAULT_PROMPTS, ak as DEFAULT_SUMMARIZATION_PROMPT, N as EventHandlers, aG as GadgetClass, a3 as GadgetExecutionControllerContext, aH as GadgetOrClass, a4 as GadgetParameterInterceptorContext, a5 as GadgetResultInterceptorContext, au as HintContext, J as HistoryMessage, a6 as Interceptors, a7 as LLMCallControllerContext, a8 as LLMErrorControllerContext, an as LLMMessageBuilder, am as LLMRole, al as LLMistOptions, a9 as MessageInterceptorContext, ah as MessageTurn, d as MockBuilder, f as MockManager, j as MockMatcher, k as MockMatcherContext, l as MockOptions, M as MockProviderAdapter, n as MockRegistration, o as MockResponse, p as MockStats, ap as ModelFeatures, at as ModelIdentifierParser, aq as ModelLimits, ar as ModelPricing, aa as ObserveChunkContext, ai as ObserveCompactionContext, ab as ObserveGadgetCompleteContext, ac as ObserveGadgetStartContext, ad as ObserveLLMCallContext, ae as ObserveLLMCompleteContext, af as ObserveLLMErrorContext, ag as Observers, av as PromptConfig, aw as PromptContext, ax as PromptTemplate, as as ProviderIdentifier, aD as QuickOptions, aI as TextOnlyAction, aJ as TextOnlyContext, aK as TextOnlyCustomHandler, aL as TextOnlyGadgetConfig, aM as TextOnlyHandler, aN as TextOnlyStrategy, O as collectEvents, Q as collectText, aE as complete, c as createMockAdapter, e as createMockClient, h as createMockStream, i as createTextMockStream, g as getMockManager, m as mockLLM, aA as resolveHintTemplate, aB as resolvePromptTemplate, aC as resolveRulesTemplate, U as runWithHandlers, aF as stream } from './mock-stream-Cc47j12U.cjs';
3
+ import { A as AgentHooks, q as ModelRegistry, I as IConversationManager, b as LLMMessage, S as StreamEvent, T as TokenUsage, G as GadgetRegistry, a as LLMStreamChunk, C as CompactionStrategy, R as ResolvedCompactionConfig, r as CompactionContext, s as CompactionResult, t as LLMist, u as CompactionConfig, v as CompactionEvent, w as CompactionStats, H as HintTemplate, x as GadgetExample, B as BaseGadget, P as ParsedGadgetCall, y as GadgetExecutionResult, z as ProviderAdapter, D as ModelDescriptor, E as ModelSpec, F as LLMGenerationOptions, L as LLMStream } from './mock-stream-BMuFlQI1.cjs';
4
+ export { X as AfterGadgetExecutionAction, Y as AfterGadgetExecutionControllerContext, Z as AfterLLMCallAction, _ as AfterLLMCallControllerContext, $ as AfterLLMErrorAction, O as AgentBuilder, a0 as AgentOptions, a1 as BeforeGadgetExecutionAction, a2 as BeforeLLMCallAction, a3 as ChunkInterceptorContext, a4 as Controllers, aq as CostEstimate, al as DEFAULT_COMPACTION_CONFIG, aA as DEFAULT_HINTS, aB as DEFAULT_PROMPTS, am as DEFAULT_SUMMARIZATION_PROMPT, Q as EventHandlers, aI as GadgetClass, a5 as GadgetExecutionControllerContext, aJ as GadgetOrClass, a6 as GadgetParameterInterceptorContext, a7 as GadgetResultInterceptorContext, aw as HintContext, J as HistoryMessage, a8 as Interceptors, a9 as LLMCallControllerContext, aa as LLMErrorControllerContext, ap as LLMMessageBuilder, ao as LLMRole, an as LLMistOptions, ab as MessageInterceptorContext, aj as MessageTurn, d as MockBuilder, f as MockManager, j as MockMatcher, k as MockMatcherContext, l as MockOptions, M as MockProviderAdapter, n as MockRegistration, o as MockResponse, p as MockStats, ar as ModelFeatures, av as ModelIdentifierParser, as as ModelLimits, at as ModelPricing, ac as ObserveChunkContext, ak as ObserveCompactionContext, ad as ObserveGadgetCompleteContext, ae as ObserveGadgetStartContext, af as ObserveLLMCallContext, ag as ObserveLLMCompleteContext, ah as ObserveLLMErrorContext, ai as Observers, ax as PromptConfig, ay as PromptContext, az as PromptTemplate, au as ProviderIdentifier, aF as QuickOptions, aK as TextOnlyAction, aL as TextOnlyContext, aM as TextOnlyCustomHandler, aN as TextOnlyGadgetConfig, aO as TextOnlyHandler, aP as TextOnlyStrategy, K as TrailingMessage, N as TrailingMessageContext, U as collectEvents, V as collectText, aG as complete, c as createMockAdapter, e as createMockClient, h as createMockStream, i as createTextMockStream, g as getMockManager, m as mockLLM, aC as resolveHintTemplate, aD as resolvePromptTemplate, aE as resolveRulesTemplate, W as runWithHandlers, aH as stream } from './mock-stream-BMuFlQI1.cjs';
5
5
  import { Logger, ILogObj } from 'tslog';
6
6
  import { MessageCreateParamsStreaming, MessageStreamEvent } from '@anthropic-ai/sdk/resources/messages';
7
7
  import OpenAI from 'openai';
@@ -1517,16 +1517,17 @@ declare function createGadget<TSchema extends ZodType>(config: CreateGadgetConfi
1517
1517
  * which is created per-agent-run.
1518
1518
  *
1519
1519
  * @param store - The GadgetOutputStore to read outputs from
1520
+ * @param maxOutputChars - Maximum characters to return (default: 76,800 = ~19k tokens)
1520
1521
  * @returns A GadgetOutputViewer gadget instance
1521
1522
  *
1522
1523
  * @example
1523
1524
  * ```typescript
1524
1525
  * const store = new GadgetOutputStore();
1525
- * const viewer = createGadgetOutputViewer(store);
1526
+ * const viewer = createGadgetOutputViewer(store, 76_800);
1526
1527
  * registry.register("GadgetOutputViewer", viewer);
1527
1528
  * ```
1528
1529
  */
1529
- declare function createGadgetOutputViewer(store: GadgetOutputStore): BaseGadget;
1530
+ declare function createGadgetOutputViewer(store: GadgetOutputStore, maxOutputChars?: number): BaseGadget;
1530
1531
 
1531
1532
  /**
1532
1533
  * Exception that gadgets can throw to signal the agent loop should terminate.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ZodType, ZodTypeAny } from 'zod';
2
2
  export { z } from 'zod';
3
- import { A as AgentHooks, q as ModelRegistry, I as IConversationManager, b as LLMMessage, S as StreamEvent, T as TokenUsage, G as GadgetRegistry, a as LLMStreamChunk, C as CompactionStrategy, R as ResolvedCompactionConfig, r as CompactionContext, s as CompactionResult, t as LLMist, u as CompactionConfig, v as CompactionEvent, w as CompactionStats, H as HintTemplate, x as GadgetExample, B as BaseGadget, P as ParsedGadgetCall, y as GadgetExecutionResult, z as ProviderAdapter, D as ModelDescriptor, E as ModelSpec, F as LLMGenerationOptions, L as LLMStream } from './mock-stream-Cc47j12U.js';
4
- export { V as AfterGadgetExecutionAction, W as AfterGadgetExecutionControllerContext, X as AfterLLMCallAction, Y as AfterLLMCallControllerContext, Z as AfterLLMErrorAction, K as AgentBuilder, _ as AgentOptions, $ as BeforeGadgetExecutionAction, a0 as BeforeLLMCallAction, a1 as ChunkInterceptorContext, a2 as Controllers, ao as CostEstimate, aj as DEFAULT_COMPACTION_CONFIG, ay as DEFAULT_HINTS, az as DEFAULT_PROMPTS, ak as DEFAULT_SUMMARIZATION_PROMPT, N as EventHandlers, aG as GadgetClass, a3 as GadgetExecutionControllerContext, aH as GadgetOrClass, a4 as GadgetParameterInterceptorContext, a5 as GadgetResultInterceptorContext, au as HintContext, J as HistoryMessage, a6 as Interceptors, a7 as LLMCallControllerContext, a8 as LLMErrorControllerContext, an as LLMMessageBuilder, am as LLMRole, al as LLMistOptions, a9 as MessageInterceptorContext, ah as MessageTurn, d as MockBuilder, f as MockManager, j as MockMatcher, k as MockMatcherContext, l as MockOptions, M as MockProviderAdapter, n as MockRegistration, o as MockResponse, p as MockStats, ap as ModelFeatures, at as ModelIdentifierParser, aq as ModelLimits, ar as ModelPricing, aa as ObserveChunkContext, ai as ObserveCompactionContext, ab as ObserveGadgetCompleteContext, ac as ObserveGadgetStartContext, ad as ObserveLLMCallContext, ae as ObserveLLMCompleteContext, af as ObserveLLMErrorContext, ag as Observers, av as PromptConfig, aw as PromptContext, ax as PromptTemplate, as as ProviderIdentifier, aD as QuickOptions, aI as TextOnlyAction, aJ as TextOnlyContext, aK as TextOnlyCustomHandler, aL as TextOnlyGadgetConfig, aM as TextOnlyHandler, aN as TextOnlyStrategy, O as collectEvents, Q as collectText, aE as complete, c as createMockAdapter, e as createMockClient, h as createMockStream, i as createTextMockStream, g as getMockManager, m as mockLLM, aA as resolveHintTemplate, aB as resolvePromptTemplate, aC as resolveRulesTemplate, U as runWithHandlers, aF as stream } from './mock-stream-Cc47j12U.js';
3
+ import { A as AgentHooks, q as ModelRegistry, I as IConversationManager, b as LLMMessage, S as StreamEvent, T as TokenUsage, G as GadgetRegistry, a as LLMStreamChunk, C as CompactionStrategy, R as ResolvedCompactionConfig, r as CompactionContext, s as CompactionResult, t as LLMist, u as CompactionConfig, v as CompactionEvent, w as CompactionStats, H as HintTemplate, x as GadgetExample, B as BaseGadget, P as ParsedGadgetCall, y as GadgetExecutionResult, z as ProviderAdapter, D as ModelDescriptor, E as ModelSpec, F as LLMGenerationOptions, L as LLMStream } from './mock-stream-BMuFlQI1.js';
4
+ export { X as AfterGadgetExecutionAction, Y as AfterGadgetExecutionControllerContext, Z as AfterLLMCallAction, _ as AfterLLMCallControllerContext, $ as AfterLLMErrorAction, O as AgentBuilder, a0 as AgentOptions, a1 as BeforeGadgetExecutionAction, a2 as BeforeLLMCallAction, a3 as ChunkInterceptorContext, a4 as Controllers, aq as CostEstimate, al as DEFAULT_COMPACTION_CONFIG, aA as DEFAULT_HINTS, aB as DEFAULT_PROMPTS, am as DEFAULT_SUMMARIZATION_PROMPT, Q as EventHandlers, aI as GadgetClass, a5 as GadgetExecutionControllerContext, aJ as GadgetOrClass, a6 as GadgetParameterInterceptorContext, a7 as GadgetResultInterceptorContext, aw as HintContext, J as HistoryMessage, a8 as Interceptors, a9 as LLMCallControllerContext, aa as LLMErrorControllerContext, ap as LLMMessageBuilder, ao as LLMRole, an as LLMistOptions, ab as MessageInterceptorContext, aj as MessageTurn, d as MockBuilder, f as MockManager, j as MockMatcher, k as MockMatcherContext, l as MockOptions, M as MockProviderAdapter, n as MockRegistration, o as MockResponse, p as MockStats, ar as ModelFeatures, av as ModelIdentifierParser, as as ModelLimits, at as ModelPricing, ac as ObserveChunkContext, ak as ObserveCompactionContext, ad as ObserveGadgetCompleteContext, ae as ObserveGadgetStartContext, af as ObserveLLMCallContext, ag as ObserveLLMCompleteContext, ah as ObserveLLMErrorContext, ai as Observers, ax as PromptConfig, ay as PromptContext, az as PromptTemplate, au as ProviderIdentifier, aF as QuickOptions, aK as TextOnlyAction, aL as TextOnlyContext, aM as TextOnlyCustomHandler, aN as TextOnlyGadgetConfig, aO as TextOnlyHandler, aP as TextOnlyStrategy, K as TrailingMessage, N as TrailingMessageContext, U as collectEvents, V as collectText, aG as complete, c as createMockAdapter, e as createMockClient, h as createMockStream, i as createTextMockStream, g as getMockManager, m as mockLLM, aC as resolveHintTemplate, aD as resolvePromptTemplate, aE as resolveRulesTemplate, W as runWithHandlers, aH as stream } from './mock-stream-BMuFlQI1.js';
5
5
  import { Logger, ILogObj } from 'tslog';
6
6
  import { MessageCreateParamsStreaming, MessageStreamEvent } from '@anthropic-ai/sdk/resources/messages';
7
7
  import OpenAI from 'openai';
@@ -1517,16 +1517,17 @@ declare function createGadget<TSchema extends ZodType>(config: CreateGadgetConfi
1517
1517
  * which is created per-agent-run.
1518
1518
  *
1519
1519
  * @param store - The GadgetOutputStore to read outputs from
1520
+ * @param maxOutputChars - Maximum characters to return (default: 76,800 = ~19k tokens)
1520
1521
  * @returns A GadgetOutputViewer gadget instance
1521
1522
  *
1522
1523
  * @example
1523
1524
  * ```typescript
1524
1525
  * const store = new GadgetOutputStore();
1525
- * const viewer = createGadgetOutputViewer(store);
1526
+ * const viewer = createGadgetOutputViewer(store, 76_800);
1526
1527
  * registry.register("GadgetOutputViewer", viewer);
1527
1528
  * ```
1528
1529
  */
1529
- declare function createGadgetOutputViewer(store: GadgetOutputStore): BaseGadget;
1530
+ declare function createGadgetOutputViewer(store: GadgetOutputStore, maxOutputChars?: number): BaseGadget;
1530
1531
 
1531
1532
  /**
1532
1533
  * Exception that gadgets can throw to signal the agent loop should terminate.
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  iterationProgressHint,
6
6
  parallelGadgetHint,
7
7
  z
8
- } from "./chunk-QR5IQXEM.js";
8
+ } from "./chunk-JGORHSHC.js";
9
9
  import {
10
10
  AgentBuilder,
11
11
  AnthropicMessagesProvider,
@@ -64,7 +64,7 @@ import {
64
64
  stream,
65
65
  validateAndApplyDefaults,
66
66
  validateGadgetParams
67
- } from "./chunk-X5XQ6M5P.js";
67
+ } from "./chunk-E52IO2NO.js";
68
68
  export {
69
69
  AgentBuilder,
70
70
  AnthropicMessagesProvider,
@@ -2071,6 +2071,16 @@ type HistoryMessage = {
2071
2071
  } | {
2072
2072
  system: string;
2073
2073
  };
2074
+ /**
2075
+ * Context available to trailing message functions.
2076
+ * Provides iteration information for dynamic message generation.
2077
+ */
2078
+ type TrailingMessageContext = Pick<LLMCallControllerContext, "iteration" | "maxIterations">;
2079
+ /**
2080
+ * Trailing message can be a static string or a function that generates the message.
2081
+ * The function receives context about the current iteration.
2082
+ */
2083
+ type TrailingMessage = string | ((ctx: TrailingMessageContext) => string);
2074
2084
  /**
2075
2085
  * Fluent builder for creating agents.
2076
2086
  *
@@ -2101,6 +2111,7 @@ declare class AgentBuilder {
2101
2111
  private gadgetOutputLimitPercent?;
2102
2112
  private compactionConfig?;
2103
2113
  private signal?;
2114
+ private trailingMessage?;
2104
2115
  constructor(client?: LLMist);
2105
2116
  /**
2106
2117
  * Set the model to use.
@@ -2498,6 +2509,28 @@ declare class AgentBuilder {
2498
2509
  * ```
2499
2510
  */
2500
2511
  withSignal(signal: AbortSignal): this;
2512
+ /**
2513
+ * Add an ephemeral trailing message that appears at the end of each LLM request.
2514
+ *
2515
+ * The message is NOT persisted to conversation history - it only appears in the
2516
+ * current LLM call. This is useful for injecting context-specific instructions
2517
+ * or reminders without polluting the conversation history.
2518
+ *
2519
+ * @param message - Static string or function that generates the message
2520
+ * @returns This builder for chaining
2521
+ *
2522
+ * @example
2523
+ * ```typescript
2524
+ * // Static message
2525
+ * .withTrailingMessage("Always respond in JSON format.")
2526
+ *
2527
+ * // Dynamic message based on iteration
2528
+ * .withTrailingMessage((ctx) =>
2529
+ * `[Iteration ${ctx.iteration}/${ctx.maxIterations}] Stay focused on the task.`
2530
+ * )
2531
+ * ```
2532
+ */
2533
+ withTrailingMessage(message: TrailingMessage): this;
2501
2534
  /**
2502
2535
  * Add a synthetic gadget call to the conversation history.
2503
2536
  *
@@ -2524,6 +2557,10 @@ declare class AgentBuilder {
2524
2557
  * ```
2525
2558
  */
2526
2559
  withSyntheticGadgetCall(gadgetName: string, parameters: Record<string, unknown>, result: string): this;
2560
+ /**
2561
+ * Compose the final hooks, including trailing message if configured.
2562
+ */
2563
+ private composeHooks;
2527
2564
  /**
2528
2565
  * Format parameters as block format with JSON Pointer paths.
2529
2566
  */
@@ -3227,4 +3264,4 @@ declare function createTextMockStream(text: string, options?: {
3227
3264
  usage?: MockResponse["usage"];
3228
3265
  }): LLMStream;
3229
3266
 
3230
- export { type BeforeGadgetExecutionAction as $, type AgentHooks as A, BaseGadget as B, type CompactionStrategy as C, type ModelDescriptor as D, type ModelSpec as E, type LLMGenerationOptions as F, GadgetRegistry as G, type HintTemplate as H, type IConversationManager as I, type HistoryMessage as J, AgentBuilder as K, type LLMStream as L, MockProviderAdapter as M, type EventHandlers as N, collectEvents as O, type ParsedGadgetCall as P, collectText as Q, type ResolvedCompactionConfig as R, type StreamEvent as S, type TokenUsage as T, runWithHandlers as U, type AfterGadgetExecutionAction as V, type AfterGadgetExecutionControllerContext as W, type AfterLLMCallAction as X, type AfterLLMCallControllerContext as Y, type AfterLLMErrorAction as Z, type AgentOptions as _, type LLMStreamChunk as a, type BeforeLLMCallAction as a0, type ChunkInterceptorContext as a1, type Controllers as a2, type GadgetExecutionControllerContext as a3, type GadgetParameterInterceptorContext as a4, type GadgetResultInterceptorContext as a5, type Interceptors as a6, type LLMCallControllerContext as a7, type LLMErrorControllerContext as a8, type MessageInterceptorContext as a9, resolveHintTemplate as aA, resolvePromptTemplate as aB, resolveRulesTemplate as aC, type QuickOptions as aD, complete as aE, stream as aF, type GadgetClass as aG, type GadgetOrClass as aH, type TextOnlyAction as aI, type TextOnlyContext as aJ, type TextOnlyCustomHandler as aK, type TextOnlyGadgetConfig as aL, type TextOnlyHandler as aM, type TextOnlyStrategy as aN, type ObserveChunkContext as aa, type ObserveGadgetCompleteContext as ab, type ObserveGadgetStartContext as ac, type ObserveLLMCallContext as ad, type ObserveLLMCompleteContext as ae, type ObserveLLMErrorContext as af, type Observers as ag, type MessageTurn as ah, type ObserveCompactionContext as ai, DEFAULT_COMPACTION_CONFIG as aj, DEFAULT_SUMMARIZATION_PROMPT as ak, type LLMistOptions as al, type LLMRole as am, LLMMessageBuilder as an, type CostEstimate as ao, type ModelFeatures as ap, type ModelLimits as aq, type ModelPricing as ar, type ProviderIdentifier as as, ModelIdentifierParser as at, type HintContext as au, type PromptConfig as av, type PromptContext as aw, type PromptTemplate as ax, DEFAULT_HINTS as ay, DEFAULT_PROMPTS as az, type LLMMessage as b, createMockAdapter as c, MockBuilder as d, createMockClient as e, MockManager as f, getMockManager as g, createMockStream as h, createTextMockStream as i, type MockMatcher as j, type MockMatcherContext as k, type MockOptions as l, mockLLM as m, type MockRegistration as n, type MockResponse as o, type MockStats as p, ModelRegistry as q, type CompactionContext as r, type CompactionResult as s, LLMist as t, type CompactionConfig as u, type CompactionEvent as v, type CompactionStats as w, type GadgetExample as x, type GadgetExecutionResult as y, type ProviderAdapter as z };
3267
+ export { type AfterLLMErrorAction as $, type AgentHooks as A, BaseGadget as B, type CompactionStrategy as C, type ModelDescriptor as D, type ModelSpec as E, type LLMGenerationOptions as F, GadgetRegistry as G, type HintTemplate as H, type IConversationManager as I, type HistoryMessage as J, type TrailingMessage as K, type LLMStream as L, MockProviderAdapter as M, type TrailingMessageContext as N, AgentBuilder as O, type ParsedGadgetCall as P, type EventHandlers as Q, type ResolvedCompactionConfig as R, type StreamEvent as S, type TokenUsage as T, collectEvents as U, collectText as V, runWithHandlers as W, type AfterGadgetExecutionAction as X, type AfterGadgetExecutionControllerContext as Y, type AfterLLMCallAction as Z, type AfterLLMCallControllerContext as _, type LLMStreamChunk as a, type AgentOptions as a0, type BeforeGadgetExecutionAction as a1, type BeforeLLMCallAction as a2, type ChunkInterceptorContext as a3, type Controllers as a4, type GadgetExecutionControllerContext as a5, type GadgetParameterInterceptorContext as a6, type GadgetResultInterceptorContext as a7, type Interceptors as a8, type LLMCallControllerContext as a9, DEFAULT_HINTS as aA, DEFAULT_PROMPTS as aB, resolveHintTemplate as aC, resolvePromptTemplate as aD, resolveRulesTemplate as aE, type QuickOptions as aF, complete as aG, stream as aH, type GadgetClass as aI, type GadgetOrClass as aJ, type TextOnlyAction as aK, type TextOnlyContext as aL, type TextOnlyCustomHandler as aM, type TextOnlyGadgetConfig as aN, type TextOnlyHandler as aO, type TextOnlyStrategy as aP, type LLMErrorControllerContext as aa, type MessageInterceptorContext as ab, type ObserveChunkContext as ac, type ObserveGadgetCompleteContext as ad, type ObserveGadgetStartContext as ae, type ObserveLLMCallContext as af, type ObserveLLMCompleteContext as ag, type ObserveLLMErrorContext as ah, type Observers as ai, type MessageTurn as aj, type ObserveCompactionContext as ak, DEFAULT_COMPACTION_CONFIG as al, DEFAULT_SUMMARIZATION_PROMPT as am, type LLMistOptions as an, type LLMRole as ao, LLMMessageBuilder as ap, type CostEstimate as aq, type ModelFeatures as ar, type ModelLimits as as, type ModelPricing as at, type ProviderIdentifier as au, ModelIdentifierParser as av, type HintContext as aw, type PromptConfig as ax, type PromptContext as ay, type PromptTemplate as az, type LLMMessage as b, createMockAdapter as c, MockBuilder as d, createMockClient as e, MockManager as f, getMockManager as g, createMockStream as h, createTextMockStream as i, type MockMatcher as j, type MockMatcherContext as k, type MockOptions as l, mockLLM as m, type MockRegistration as n, type MockResponse as o, type MockStats as p, ModelRegistry as q, type CompactionContext as r, type CompactionResult as s, LLMist as t, type CompactionConfig as u, type CompactionEvent as v, type CompactionStats as w, type GadgetExample as x, type GadgetExecutionResult as y, type ProviderAdapter as z };
@@ -2071,6 +2071,16 @@ type HistoryMessage = {
2071
2071
  } | {
2072
2072
  system: string;
2073
2073
  };
2074
+ /**
2075
+ * Context available to trailing message functions.
2076
+ * Provides iteration information for dynamic message generation.
2077
+ */
2078
+ type TrailingMessageContext = Pick<LLMCallControllerContext, "iteration" | "maxIterations">;
2079
+ /**
2080
+ * Trailing message can be a static string or a function that generates the message.
2081
+ * The function receives context about the current iteration.
2082
+ */
2083
+ type TrailingMessage = string | ((ctx: TrailingMessageContext) => string);
2074
2084
  /**
2075
2085
  * Fluent builder for creating agents.
2076
2086
  *
@@ -2101,6 +2111,7 @@ declare class AgentBuilder {
2101
2111
  private gadgetOutputLimitPercent?;
2102
2112
  private compactionConfig?;
2103
2113
  private signal?;
2114
+ private trailingMessage?;
2104
2115
  constructor(client?: LLMist);
2105
2116
  /**
2106
2117
  * Set the model to use.
@@ -2498,6 +2509,28 @@ declare class AgentBuilder {
2498
2509
  * ```
2499
2510
  */
2500
2511
  withSignal(signal: AbortSignal): this;
2512
+ /**
2513
+ * Add an ephemeral trailing message that appears at the end of each LLM request.
2514
+ *
2515
+ * The message is NOT persisted to conversation history - it only appears in the
2516
+ * current LLM call. This is useful for injecting context-specific instructions
2517
+ * or reminders without polluting the conversation history.
2518
+ *
2519
+ * @param message - Static string or function that generates the message
2520
+ * @returns This builder for chaining
2521
+ *
2522
+ * @example
2523
+ * ```typescript
2524
+ * // Static message
2525
+ * .withTrailingMessage("Always respond in JSON format.")
2526
+ *
2527
+ * // Dynamic message based on iteration
2528
+ * .withTrailingMessage((ctx) =>
2529
+ * `[Iteration ${ctx.iteration}/${ctx.maxIterations}] Stay focused on the task.`
2530
+ * )
2531
+ * ```
2532
+ */
2533
+ withTrailingMessage(message: TrailingMessage): this;
2501
2534
  /**
2502
2535
  * Add a synthetic gadget call to the conversation history.
2503
2536
  *
@@ -2524,6 +2557,10 @@ declare class AgentBuilder {
2524
2557
  * ```
2525
2558
  */
2526
2559
  withSyntheticGadgetCall(gadgetName: string, parameters: Record<string, unknown>, result: string): this;
2560
+ /**
2561
+ * Compose the final hooks, including trailing message if configured.
2562
+ */
2563
+ private composeHooks;
2527
2564
  /**
2528
2565
  * Format parameters as block format with JSON Pointer paths.
2529
2566
  */
@@ -3227,4 +3264,4 @@ declare function createTextMockStream(text: string, options?: {
3227
3264
  usage?: MockResponse["usage"];
3228
3265
  }): LLMStream;
3229
3266
 
3230
- export { type BeforeGadgetExecutionAction as $, type AgentHooks as A, BaseGadget as B, type CompactionStrategy as C, type ModelDescriptor as D, type ModelSpec as E, type LLMGenerationOptions as F, GadgetRegistry as G, type HintTemplate as H, type IConversationManager as I, type HistoryMessage as J, AgentBuilder as K, type LLMStream as L, MockProviderAdapter as M, type EventHandlers as N, collectEvents as O, type ParsedGadgetCall as P, collectText as Q, type ResolvedCompactionConfig as R, type StreamEvent as S, type TokenUsage as T, runWithHandlers as U, type AfterGadgetExecutionAction as V, type AfterGadgetExecutionControllerContext as W, type AfterLLMCallAction as X, type AfterLLMCallControllerContext as Y, type AfterLLMErrorAction as Z, type AgentOptions as _, type LLMStreamChunk as a, type BeforeLLMCallAction as a0, type ChunkInterceptorContext as a1, type Controllers as a2, type GadgetExecutionControllerContext as a3, type GadgetParameterInterceptorContext as a4, type GadgetResultInterceptorContext as a5, type Interceptors as a6, type LLMCallControllerContext as a7, type LLMErrorControllerContext as a8, type MessageInterceptorContext as a9, resolveHintTemplate as aA, resolvePromptTemplate as aB, resolveRulesTemplate as aC, type QuickOptions as aD, complete as aE, stream as aF, type GadgetClass as aG, type GadgetOrClass as aH, type TextOnlyAction as aI, type TextOnlyContext as aJ, type TextOnlyCustomHandler as aK, type TextOnlyGadgetConfig as aL, type TextOnlyHandler as aM, type TextOnlyStrategy as aN, type ObserveChunkContext as aa, type ObserveGadgetCompleteContext as ab, type ObserveGadgetStartContext as ac, type ObserveLLMCallContext as ad, type ObserveLLMCompleteContext as ae, type ObserveLLMErrorContext as af, type Observers as ag, type MessageTurn as ah, type ObserveCompactionContext as ai, DEFAULT_COMPACTION_CONFIG as aj, DEFAULT_SUMMARIZATION_PROMPT as ak, type LLMistOptions as al, type LLMRole as am, LLMMessageBuilder as an, type CostEstimate as ao, type ModelFeatures as ap, type ModelLimits as aq, type ModelPricing as ar, type ProviderIdentifier as as, ModelIdentifierParser as at, type HintContext as au, type PromptConfig as av, type PromptContext as aw, type PromptTemplate as ax, DEFAULT_HINTS as ay, DEFAULT_PROMPTS as az, type LLMMessage as b, createMockAdapter as c, MockBuilder as d, createMockClient as e, MockManager as f, getMockManager as g, createMockStream as h, createTextMockStream as i, type MockMatcher as j, type MockMatcherContext as k, type MockOptions as l, mockLLM as m, type MockRegistration as n, type MockResponse as o, type MockStats as p, ModelRegistry as q, type CompactionContext as r, type CompactionResult as s, LLMist as t, type CompactionConfig as u, type CompactionEvent as v, type CompactionStats as w, type GadgetExample as x, type GadgetExecutionResult as y, type ProviderAdapter as z };
3267
+ export { type AfterLLMErrorAction as $, type AgentHooks as A, BaseGadget as B, type CompactionStrategy as C, type ModelDescriptor as D, type ModelSpec as E, type LLMGenerationOptions as F, GadgetRegistry as G, type HintTemplate as H, type IConversationManager as I, type HistoryMessage as J, type TrailingMessage as K, type LLMStream as L, MockProviderAdapter as M, type TrailingMessageContext as N, AgentBuilder as O, type ParsedGadgetCall as P, type EventHandlers as Q, type ResolvedCompactionConfig as R, type StreamEvent as S, type TokenUsage as T, collectEvents as U, collectText as V, runWithHandlers as W, type AfterGadgetExecutionAction as X, type AfterGadgetExecutionControllerContext as Y, type AfterLLMCallAction as Z, type AfterLLMCallControllerContext as _, type LLMStreamChunk as a, type AgentOptions as a0, type BeforeGadgetExecutionAction as a1, type BeforeLLMCallAction as a2, type ChunkInterceptorContext as a3, type Controllers as a4, type GadgetExecutionControllerContext as a5, type GadgetParameterInterceptorContext as a6, type GadgetResultInterceptorContext as a7, type Interceptors as a8, type LLMCallControllerContext as a9, DEFAULT_HINTS as aA, DEFAULT_PROMPTS as aB, resolveHintTemplate as aC, resolvePromptTemplate as aD, resolveRulesTemplate as aE, type QuickOptions as aF, complete as aG, stream as aH, type GadgetClass as aI, type GadgetOrClass as aJ, type TextOnlyAction as aK, type TextOnlyContext as aL, type TextOnlyCustomHandler as aM, type TextOnlyGadgetConfig as aN, type TextOnlyHandler as aO, type TextOnlyStrategy as aP, type LLMErrorControllerContext as aa, type MessageInterceptorContext as ab, type ObserveChunkContext as ac, type ObserveGadgetCompleteContext as ad, type ObserveGadgetStartContext as ae, type ObserveLLMCallContext as af, type ObserveLLMCompleteContext as ag, type ObserveLLMErrorContext as ah, type Observers as ai, type MessageTurn as aj, type ObserveCompactionContext as ak, DEFAULT_COMPACTION_CONFIG as al, DEFAULT_SUMMARIZATION_PROMPT as am, type LLMistOptions as an, type LLMRole as ao, LLMMessageBuilder as ap, type CostEstimate as aq, type ModelFeatures as ar, type ModelLimits as as, type ModelPricing as at, type ProviderIdentifier as au, ModelIdentifierParser as av, type HintContext as aw, type PromptConfig as ax, type PromptContext as ay, type PromptTemplate as az, type LLMMessage as b, createMockAdapter as c, MockBuilder as d, createMockClient as e, MockManager as f, getMockManager as g, createMockStream as h, createTextMockStream as i, type MockMatcher as j, type MockMatcherContext as k, type MockOptions as l, mockLLM as m, type MockRegistration as n, type MockResponse as o, type MockStats as p, ModelRegistry as q, type CompactionContext as r, type CompactionResult as s, LLMist as t, type CompactionConfig as u, type CompactionEvent as v, type CompactionStats as w, type GadgetExample as x, type GadgetExecutionResult as y, type ProviderAdapter as z };
@@ -1073,7 +1073,7 @@ function applyLineLimit(lines, limit) {
1073
1073
  }
1074
1074
  return lines;
1075
1075
  }
1076
- function createGadgetOutputViewer(store) {
1076
+ function createGadgetOutputViewer(store, maxOutputChars = DEFAULT_MAX_OUTPUT_CHARS) {
1077
1077
  return createGadget({
1078
1078
  name: "GadgetOutputViewer",
1079
1079
  description: "View stored output from gadgets that returned too much data. Use patterns to filter lines (like grep) and limit to control output size. Patterns are applied first in order, then the limit is applied to the result.",
@@ -1138,19 +1138,43 @@ function createGadgetOutputViewer(store) {
1138
1138
  if (limit) {
1139
1139
  lines = applyLineLimit(lines, limit);
1140
1140
  }
1141
+ let output = lines.join("\n");
1141
1142
  const totalLines = stored.lineCount;
1142
1143
  const returnedLines = lines.length;
1143
1144
  if (returnedLines === 0) {
1144
1145
  return `No lines matched the filters. Original output had ${totalLines} lines.`;
1145
1146
  }
1146
- const header = returnedLines < totalLines ? `[Showing ${returnedLines} of ${totalLines} lines]
1147
- ` : `[Showing all ${totalLines} lines]
1147
+ let truncatedBySize = false;
1148
+ let linesIncluded = returnedLines;
1149
+ if (output.length > maxOutputChars) {
1150
+ truncatedBySize = true;
1151
+ let truncatedOutput = "";
1152
+ linesIncluded = 0;
1153
+ for (const line of lines) {
1154
+ if (truncatedOutput.length + line.length + 1 > maxOutputChars) break;
1155
+ truncatedOutput += line + "\n";
1156
+ linesIncluded++;
1157
+ }
1158
+ output = truncatedOutput;
1159
+ }
1160
+ let header;
1161
+ if (truncatedBySize) {
1162
+ const remainingLines = returnedLines - linesIncluded;
1163
+ header = `[Showing ${linesIncluded} of ${totalLines} lines (truncated due to size limit)]
1164
+ [... ${remainingLines.toLocaleString()} more lines. Use limit parameter to paginate, e.g., limit: "${linesIncluded + 1}-${linesIncluded + 200}"]
1148
1165
  `;
1149
- return header + lines.join("\n");
1166
+ } else if (returnedLines < totalLines) {
1167
+ header = `[Showing ${returnedLines} of ${totalLines} lines]
1168
+ `;
1169
+ } else {
1170
+ header = `[Showing all ${totalLines} lines]
1171
+ `;
1172
+ }
1173
+ return header + output;
1150
1174
  }
1151
1175
  });
1152
1176
  }
1153
- var import_zod, patternSchema;
1177
+ var import_zod, patternSchema, DEFAULT_MAX_OUTPUT_CHARS;
1154
1178
  var init_output_viewer = __esm({
1155
1179
  "src/gadgets/output-viewer.ts"() {
1156
1180
  "use strict";
@@ -1162,6 +1186,7 @@ var init_output_viewer = __esm({
1162
1186
  before: import_zod.z.number().int().min(0).default(0).describe("Context lines before each match (like grep -B)"),
1163
1187
  after: import_zod.z.number().int().min(0).default(0).describe("Context lines after each match (like grep -A)")
1164
1188
  });
1189
+ DEFAULT_MAX_OUTPUT_CHARS = 76800;
1165
1190
  }
1166
1191
  });
1167
1192
 
@@ -3337,7 +3362,10 @@ var init_agent = __esm({
3337
3362
  const contextWindow = limits?.contextWindow ?? FALLBACK_CONTEXT_WINDOW;
3338
3363
  this.outputLimitCharLimit = Math.floor(contextWindow * (limitPercent / 100) * CHARS_PER_TOKEN);
3339
3364
  if (this.outputLimitEnabled) {
3340
- this.registry.register("GadgetOutputViewer", createGadgetOutputViewer(this.outputStore));
3365
+ this.registry.register(
3366
+ "GadgetOutputViewer",
3367
+ createGadgetOutputViewer(this.outputStore, this.outputLimitCharLimit)
3368
+ );
3341
3369
  }
3342
3370
  this.hooks = this.mergeOutputLimiterHook(options.hooks);
3343
3371
  const baseBuilder = new LLMMessageBuilder(options.promptConfig);
@@ -3844,6 +3872,7 @@ var init_builder = __esm({
3844
3872
  gadgetOutputLimitPercent;
3845
3873
  compactionConfig;
3846
3874
  signal;
3875
+ trailingMessage;
3847
3876
  constructor(client) {
3848
3877
  this.client = client;
3849
3878
  }
@@ -4319,6 +4348,31 @@ var init_builder = __esm({
4319
4348
  this.signal = signal;
4320
4349
  return this;
4321
4350
  }
4351
+ /**
4352
+ * Add an ephemeral trailing message that appears at the end of each LLM request.
4353
+ *
4354
+ * The message is NOT persisted to conversation history - it only appears in the
4355
+ * current LLM call. This is useful for injecting context-specific instructions
4356
+ * or reminders without polluting the conversation history.
4357
+ *
4358
+ * @param message - Static string or function that generates the message
4359
+ * @returns This builder for chaining
4360
+ *
4361
+ * @example
4362
+ * ```typescript
4363
+ * // Static message
4364
+ * .withTrailingMessage("Always respond in JSON format.")
4365
+ *
4366
+ * // Dynamic message based on iteration
4367
+ * .withTrailingMessage((ctx) =>
4368
+ * `[Iteration ${ctx.iteration}/${ctx.maxIterations}] Stay focused on the task.`
4369
+ * )
4370
+ * ```
4371
+ */
4372
+ withTrailingMessage(message) {
4373
+ this.trailingMessage = message;
4374
+ return this;
4375
+ }
4322
4376
  /**
4323
4377
  * Add a synthetic gadget call to the conversation history.
4324
4378
  *
@@ -4360,6 +4414,36 @@ ${endPrefix}`
4360
4414
  });
4361
4415
  return this;
4362
4416
  }
4417
+ /**
4418
+ * Compose the final hooks, including trailing message if configured.
4419
+ */
4420
+ composeHooks() {
4421
+ if (!this.trailingMessage) {
4422
+ return this.hooks;
4423
+ }
4424
+ const trailingMsg = this.trailingMessage;
4425
+ const existingBeforeLLMCall = this.hooks?.controllers?.beforeLLMCall;
4426
+ const trailingMessageController = async (ctx) => {
4427
+ const result = existingBeforeLLMCall ? await existingBeforeLLMCall(ctx) : { action: "proceed" };
4428
+ if (result.action === "skip") {
4429
+ return result;
4430
+ }
4431
+ const messages = [...result.modifiedOptions?.messages || ctx.options.messages];
4432
+ const content = typeof trailingMsg === "function" ? trailingMsg({ iteration: ctx.iteration, maxIterations: ctx.maxIterations }) : trailingMsg;
4433
+ messages.push({ role: "user", content });
4434
+ return {
4435
+ action: "proceed",
4436
+ modifiedOptions: { ...result.modifiedOptions, messages }
4437
+ };
4438
+ };
4439
+ return {
4440
+ ...this.hooks,
4441
+ controllers: {
4442
+ ...this.hooks?.controllers,
4443
+ beforeLLMCall: trailingMessageController
4444
+ }
4445
+ };
4446
+ }
4363
4447
  /**
4364
4448
  * Format parameters as block format with JSON Pointer paths.
4365
4449
  */
@@ -4421,7 +4505,7 @@ ${endPrefix}`
4421
4505
  maxIterations: this.maxIterations,
4422
4506
  temperature: this.temperature,
4423
4507
  logger: this.logger,
4424
- hooks: this.hooks,
4508
+ hooks: this.composeHooks(),
4425
4509
  promptConfig: this.promptConfig,
4426
4510
  initialMessages: this.initialMessages,
4427
4511
  onHumanInputRequired: this.onHumanInputRequired,
@@ -4525,7 +4609,7 @@ ${endPrefix}`
4525
4609
  maxIterations: this.maxIterations,
4526
4610
  temperature: this.temperature,
4527
4611
  logger: this.logger,
4528
- hooks: this.hooks,
4612
+ hooks: this.composeHooks(),
4529
4613
  promptConfig: this.promptConfig,
4530
4614
  initialMessages: this.initialMessages,
4531
4615
  onHumanInputRequired: this.onHumanInputRequired,