llmist 3.1.0 → 4.0.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/{chunk-LFI4WQVV.js → chunk-Q6NQRMYD.js} +2 -2
- package/dist/chunk-Q6NQRMYD.js.map +1 -0
- package/dist/{chunk-JCFPJMRQ.js → chunk-RHR2M6T6.js} +138 -35
- package/dist/chunk-RHR2M6T6.js.map +1 -0
- package/dist/cli.cjs +231 -78
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +96 -46
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +137 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +2 -2
- package/dist/{mock-stream-CTLm00_q.d.cts → mock-stream-BvNYtrlG.d.cts} +83 -23
- package/dist/{mock-stream-CTLm00_q.d.ts → mock-stream-BvNYtrlG.d.ts} +83 -23
- package/dist/testing/index.cjs +137 -34
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +2 -2
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-JCFPJMRQ.js.map +0 -1
- package/dist/chunk-LFI4WQVV.js.map +0 -1
|
@@ -1022,9 +1022,14 @@ type StreamEvent = {
|
|
|
1022
1022
|
} | {
|
|
1023
1023
|
type: "compaction";
|
|
1024
1024
|
event: CompactionEvent;
|
|
1025
|
-
} | StreamCompletionEvent;
|
|
1025
|
+
} | SubagentStreamEvent | StreamCompletionEvent;
|
|
1026
|
+
/** Event for forwarding subagent activity through the stream */
|
|
1027
|
+
interface SubagentStreamEvent {
|
|
1028
|
+
type: "subagent_event";
|
|
1029
|
+
subagentEvent: SubagentEvent;
|
|
1030
|
+
}
|
|
1026
1031
|
/**
|
|
1027
|
-
* Information about an LLM call within a
|
|
1032
|
+
* Information about an LLM call within a subagent.
|
|
1028
1033
|
* Used by parent agents to display real-time progress of subagent LLM calls.
|
|
1029
1034
|
*/
|
|
1030
1035
|
interface LLMCallInfo {
|
|
@@ -1043,13 +1048,13 @@ interface LLMCallInfo {
|
|
|
1043
1048
|
}
|
|
1044
1049
|
/**
|
|
1045
1050
|
* Event emitted by subagent gadgets to report internal agent activity.
|
|
1046
|
-
* Enables real-time display of
|
|
1051
|
+
* Enables real-time display of subagent LLM calls and gadget executions.
|
|
1047
1052
|
*
|
|
1048
1053
|
* @example
|
|
1049
1054
|
* ```typescript
|
|
1050
1055
|
* // Forwarding events from subagent to parent
|
|
1051
1056
|
* for await (const event of subagent.run()) {
|
|
1052
|
-
* ctx.
|
|
1057
|
+
* ctx.onSubagentEvent?.({
|
|
1053
1058
|
* type: event.type === "gadget_call" ? "gadget_call" : "gadget_result",
|
|
1054
1059
|
* gadgetInvocationId: parentInvocationId,
|
|
1055
1060
|
* depth: 1,
|
|
@@ -1058,10 +1063,10 @@ interface LLMCallInfo {
|
|
|
1058
1063
|
* }
|
|
1059
1064
|
* ```
|
|
1060
1065
|
*/
|
|
1061
|
-
interface
|
|
1062
|
-
/** Type of
|
|
1066
|
+
interface SubagentEvent {
|
|
1067
|
+
/** Type of subagent event */
|
|
1063
1068
|
type: "llm_call_start" | "llm_call_end" | "gadget_call" | "gadget_result";
|
|
1064
|
-
/** Invocation ID of the parent gadget this
|
|
1069
|
+
/** Invocation ID of the parent gadget this subagent event belongs to */
|
|
1065
1070
|
gadgetInvocationId: string;
|
|
1066
1071
|
/** Nesting depth (1 = direct child, 2 = grandchild, etc.) */
|
|
1067
1072
|
depth: number;
|
|
@@ -1389,7 +1394,7 @@ interface ExecutionContext {
|
|
|
1389
1394
|
*
|
|
1390
1395
|
* When provided, subagent gadgets (like BrowseWeb) can use this callback
|
|
1391
1396
|
* to report their internal LLM calls and gadget executions in real-time.
|
|
1392
|
-
* This enables the parent agent to display
|
|
1397
|
+
* This enables the parent agent to display subagent progress indicators.
|
|
1393
1398
|
*
|
|
1394
1399
|
* **Recommended:** Use `builder.withParentContext(ctx)` instead of calling
|
|
1395
1400
|
* this directly - it handles all the forwarding automatically.
|
|
@@ -1410,7 +1415,7 @@ interface ExecutionContext {
|
|
|
1410
1415
|
* }
|
|
1411
1416
|
* ```
|
|
1412
1417
|
*/
|
|
1413
|
-
|
|
1418
|
+
onSubagentEvent?: (event: SubagentEvent) => void;
|
|
1414
1419
|
}
|
|
1415
1420
|
/**
|
|
1416
1421
|
* Parent agent configuration passed to gadgets.
|
|
@@ -3037,6 +3042,34 @@ declare function collectText(agentGenerator: AsyncGenerator<StreamEvent>): Promi
|
|
|
3037
3042
|
* @module agent/hooks
|
|
3038
3043
|
*/
|
|
3039
3044
|
|
|
3045
|
+
/**
|
|
3046
|
+
* Metadata present when an event originates from a subagent.
|
|
3047
|
+
* Undefined for top-level agent events.
|
|
3048
|
+
*
|
|
3049
|
+
* When using subagent gadgets (like BrowseWeb), hook observers receive events
|
|
3050
|
+
* from both the main agent AND subagents. Check this context to distinguish.
|
|
3051
|
+
*
|
|
3052
|
+
* @example
|
|
3053
|
+
* ```typescript
|
|
3054
|
+
* observers: {
|
|
3055
|
+
* onLLMCallStart: (ctx) => {
|
|
3056
|
+
* if (ctx.subagentContext) {
|
|
3057
|
+
* // Event from a subagent
|
|
3058
|
+
* console.log(`↳ Subagent LLM (depth=${ctx.subagentContext.depth})`);
|
|
3059
|
+
* } else {
|
|
3060
|
+
* // Event from the main agent
|
|
3061
|
+
* console.log('Main agent LLM call');
|
|
3062
|
+
* }
|
|
3063
|
+
* }
|
|
3064
|
+
* }
|
|
3065
|
+
* ```
|
|
3066
|
+
*/
|
|
3067
|
+
interface SubagentContext {
|
|
3068
|
+
/** Invocation ID of the parent gadget that spawned this subagent */
|
|
3069
|
+
parentGadgetInvocationId: string;
|
|
3070
|
+
/** Nesting depth: 1 = direct child, 2 = grandchild, etc. */
|
|
3071
|
+
depth: number;
|
|
3072
|
+
}
|
|
3040
3073
|
/**
|
|
3041
3074
|
* Context provided when an LLM call starts.
|
|
3042
3075
|
* Read-only observation point.
|
|
@@ -3045,6 +3078,8 @@ interface ObserveLLMCallContext {
|
|
|
3045
3078
|
iteration: number;
|
|
3046
3079
|
options: Readonly<LLMGenerationOptions>;
|
|
3047
3080
|
logger: Logger<ILogObj>;
|
|
3081
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3082
|
+
subagentContext?: SubagentContext;
|
|
3048
3083
|
}
|
|
3049
3084
|
/**
|
|
3050
3085
|
* Context provided when an LLM call is ready to execute.
|
|
@@ -3057,6 +3092,8 @@ interface ObserveLLMCallReadyContext {
|
|
|
3057
3092
|
/** Final options after any controller modifications (e.g., trailing messages) */
|
|
3058
3093
|
options: Readonly<LLMGenerationOptions>;
|
|
3059
3094
|
logger: Logger<ILogObj>;
|
|
3095
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3096
|
+
subagentContext?: SubagentContext;
|
|
3060
3097
|
}
|
|
3061
3098
|
/**
|
|
3062
3099
|
* Context provided when an LLM call completes successfully.
|
|
@@ -3073,6 +3110,8 @@ interface ObserveLLMCompleteContext {
|
|
|
3073
3110
|
/** The final message that will be added to history (after interceptors) */
|
|
3074
3111
|
finalMessage: string;
|
|
3075
3112
|
logger: Logger<ILogObj>;
|
|
3113
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3114
|
+
subagentContext?: SubagentContext;
|
|
3076
3115
|
}
|
|
3077
3116
|
/**
|
|
3078
3117
|
* Context provided when an LLM call fails.
|
|
@@ -3085,6 +3124,8 @@ interface ObserveLLMErrorContext {
|
|
|
3085
3124
|
/** Whether the error was recovered by a controller */
|
|
3086
3125
|
recovered: boolean;
|
|
3087
3126
|
logger: Logger<ILogObj>;
|
|
3127
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3128
|
+
subagentContext?: SubagentContext;
|
|
3088
3129
|
}
|
|
3089
3130
|
/**
|
|
3090
3131
|
* Context provided when a gadget execution starts.
|
|
@@ -3097,6 +3138,8 @@ interface ObserveGadgetStartContext {
|
|
|
3097
3138
|
/** Parameters after controller modifications */
|
|
3098
3139
|
parameters: Readonly<Record<string, unknown>>;
|
|
3099
3140
|
logger: Logger<ILogObj>;
|
|
3141
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3142
|
+
subagentContext?: SubagentContext;
|
|
3100
3143
|
}
|
|
3101
3144
|
/**
|
|
3102
3145
|
* Context provided when a gadget execution completes.
|
|
@@ -3117,6 +3160,8 @@ interface ObserveGadgetCompleteContext {
|
|
|
3117
3160
|
/** Cost of gadget execution in USD. 0 if gadget didn't report cost. */
|
|
3118
3161
|
cost?: number;
|
|
3119
3162
|
logger: Logger<ILogObj>;
|
|
3163
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3164
|
+
subagentContext?: SubagentContext;
|
|
3120
3165
|
}
|
|
3121
3166
|
/**
|
|
3122
3167
|
* Context provided when a gadget is skipped due to a failed dependency.
|
|
@@ -3132,6 +3177,8 @@ interface ObserveGadgetSkippedContext {
|
|
|
3132
3177
|
/** The error message from the failed dependency */
|
|
3133
3178
|
failedDependencyError: string;
|
|
3134
3179
|
logger: Logger<ILogObj>;
|
|
3180
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3181
|
+
subagentContext?: SubagentContext;
|
|
3135
3182
|
}
|
|
3136
3183
|
/**
|
|
3137
3184
|
* Context provided for each stream chunk.
|
|
@@ -3146,6 +3193,8 @@ interface ObserveChunkContext {
|
|
|
3146
3193
|
/** Token usage if available (providers send usage at stream start/end) */
|
|
3147
3194
|
usage?: TokenUsage;
|
|
3148
3195
|
logger: Logger<ILogObj>;
|
|
3196
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3197
|
+
subagentContext?: SubagentContext;
|
|
3149
3198
|
}
|
|
3150
3199
|
/**
|
|
3151
3200
|
* Observers: Read-only hooks for side effects.
|
|
@@ -3188,6 +3237,8 @@ interface ObserveCompactionContext {
|
|
|
3188
3237
|
stats: CompactionStats;
|
|
3189
3238
|
/** Logger instance */
|
|
3190
3239
|
logger: Logger<ILogObj>;
|
|
3240
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3241
|
+
subagentContext?: SubagentContext;
|
|
3191
3242
|
}
|
|
3192
3243
|
/**
|
|
3193
3244
|
* Context provided when the agent is aborted via AbortSignal.
|
|
@@ -3200,6 +3251,8 @@ interface ObserveAbortContext {
|
|
|
3200
3251
|
reason?: unknown;
|
|
3201
3252
|
/** Logger instance */
|
|
3202
3253
|
logger: Logger<ILogObj>;
|
|
3254
|
+
/** Present when event is from a subagent (undefined for top-level agent) */
|
|
3255
|
+
subagentContext?: SubagentContext;
|
|
3203
3256
|
}
|
|
3204
3257
|
/**
|
|
3205
3258
|
* Context for chunk interception.
|
|
@@ -3572,8 +3625,8 @@ interface AgentOptions {
|
|
|
3572
3625
|
signal?: AbortSignal;
|
|
3573
3626
|
/** Subagent-specific configuration overrides (from CLI config) */
|
|
3574
3627
|
subagentConfig?: SubagentConfigMap;
|
|
3575
|
-
/** Callback for subagent gadgets to report
|
|
3576
|
-
|
|
3628
|
+
/** Callback for subagent gadgets to report subagent events to parent */
|
|
3629
|
+
onSubagentEvent?: (event: SubagentEvent) => void;
|
|
3577
3630
|
}
|
|
3578
3631
|
/**
|
|
3579
3632
|
* Agent: Lean orchestrator that delegates to StreamProcessor.
|
|
@@ -3618,12 +3671,19 @@ declare class Agent {
|
|
|
3618
3671
|
private readonly signal?;
|
|
3619
3672
|
private readonly agentContextConfig;
|
|
3620
3673
|
private readonly subagentConfig?;
|
|
3621
|
-
private readonly
|
|
3674
|
+
private readonly userSubagentEventCallback?;
|
|
3675
|
+
private readonly pendingSubagentEvents;
|
|
3676
|
+
private readonly onSubagentEvent;
|
|
3622
3677
|
/**
|
|
3623
3678
|
* Creates a new Agent instance.
|
|
3624
3679
|
* @internal This constructor is private. Use LLMist.createAgent() or AgentBuilder instead.
|
|
3625
3680
|
*/
|
|
3626
3681
|
constructor(key: typeof AGENT_INTERNAL_KEY, options: AgentOptions);
|
|
3682
|
+
/**
|
|
3683
|
+
* Flush pending subagent events as StreamEvents.
|
|
3684
|
+
* Called from run() to yield queued subagent events from subagent gadgets.
|
|
3685
|
+
*/
|
|
3686
|
+
private flushPendingSubagentEvents;
|
|
3627
3687
|
/**
|
|
3628
3688
|
* Get the gadget registry for this agent.
|
|
3629
3689
|
*
|
|
@@ -3829,7 +3889,7 @@ declare class AgentBuilder {
|
|
|
3829
3889
|
private signal?;
|
|
3830
3890
|
private trailingMessage?;
|
|
3831
3891
|
private subagentConfig?;
|
|
3832
|
-
private
|
|
3892
|
+
private subagentEventCallback?;
|
|
3833
3893
|
private parentContext?;
|
|
3834
3894
|
constructor(client?: LLMist);
|
|
3835
3895
|
/**
|
|
@@ -4247,35 +4307,35 @@ declare class AgentBuilder {
|
|
|
4247
4307
|
*/
|
|
4248
4308
|
withSubagentConfig(config: SubagentConfigMap): this;
|
|
4249
4309
|
/**
|
|
4250
|
-
* Set the callback for
|
|
4310
|
+
* Set the callback for subagent events.
|
|
4251
4311
|
*
|
|
4252
|
-
* Subagent gadgets (like BrowseWeb) can use ExecutionContext.
|
|
4312
|
+
* Subagent gadgets (like BrowseWeb) can use ExecutionContext.onSubagentEvent
|
|
4253
4313
|
* to report their internal LLM calls and gadget executions in real-time.
|
|
4254
4314
|
* This callback receives those events, enabling hierarchical progress display.
|
|
4255
4315
|
*
|
|
4256
|
-
* @param callback - Function to handle
|
|
4316
|
+
* @param callback - Function to handle subagent events
|
|
4257
4317
|
* @returns This builder for chaining
|
|
4258
4318
|
*
|
|
4259
4319
|
* @example
|
|
4260
4320
|
* ```typescript
|
|
4261
|
-
* .
|
|
4321
|
+
* .withSubagentEventCallback((event) => {
|
|
4262
4322
|
* if (event.type === "llm_call_start") {
|
|
4263
|
-
* console.log(`
|
|
4323
|
+
* console.log(` Subagent LLM #${event.event.iteration} starting...`);
|
|
4264
4324
|
* } else if (event.type === "gadget_call") {
|
|
4265
4325
|
* console.log(` ⏵ ${event.event.call.gadgetName}...`);
|
|
4266
4326
|
* }
|
|
4267
4327
|
* })
|
|
4268
4328
|
* ```
|
|
4269
4329
|
*/
|
|
4270
|
-
|
|
4330
|
+
withSubagentEventCallback(callback: (event: SubagentEvent) => void): this;
|
|
4271
4331
|
/**
|
|
4272
|
-
* Enable automatic
|
|
4332
|
+
* Enable automatic subagent event forwarding to parent agent.
|
|
4273
4333
|
*
|
|
4274
4334
|
* When building a subagent inside a gadget, call this method to automatically
|
|
4275
4335
|
* forward all LLM calls and gadget events to the parent agent. This enables
|
|
4276
4336
|
* hierarchical progress display without any manual event handling.
|
|
4277
4337
|
*
|
|
4278
|
-
* The method extracts `invocationId` and `
|
|
4338
|
+
* The method extracts `invocationId` and `onSubagentEvent` from the execution
|
|
4279
4339
|
* context and sets up automatic forwarding via hooks and event wrapping.
|
|
4280
4340
|
*
|
|
4281
4341
|
* @param ctx - ExecutionContext passed to the gadget's execute() method
|
|
@@ -4353,7 +4413,7 @@ declare class AgentBuilder {
|
|
|
4353
4413
|
/**
|
|
4354
4414
|
* Compose the final hooks, including:
|
|
4355
4415
|
* - Trailing message injection (if configured)
|
|
4356
|
-
* -
|
|
4416
|
+
* - Subagent event forwarding for LLM calls (if parentContext is set)
|
|
4357
4417
|
*/
|
|
4358
4418
|
private composeHooks;
|
|
4359
4419
|
/**
|
|
@@ -5261,4 +5321,4 @@ declare function createTextMockStream(text: string, options?: {
|
|
|
5261
5321
|
usage?: MockResponse["usage"];
|
|
5262
5322
|
}): LLMStream;
|
|
5263
5323
|
|
|
5264
|
-
export { type LLMGenerationOptions as $, AbstractGadget as A, type MessageContent as B, type CompactionConfig as C, GadgetRegistry as D, MediaStore as E, type AgentContextConfig as F, type GadgetMediaOutput as G, type HintTemplate as H, type IConversationManager as I, type SubagentConfigMap as J, type
|
|
5324
|
+
export { type LLMGenerationOptions as $, AbstractGadget as A, type MessageContent as B, type CompactionConfig as C, GadgetRegistry as D, MediaStore as E, type AgentContextConfig as F, type GadgetMediaOutput as G, type HintTemplate as H, type IConversationManager as I, type SubagentConfigMap as J, type SubagentEvent as K, type LLMMessage as L, MockProviderAdapter as M, type ExecutionContext as N, type GadgetExecuteReturn as O, type GadgetExample as P, type ParsedGadgetCall as Q, type ResolvedCompactionConfig as R, type StreamEvent as S, type TokenUsage as T, type GadgetExecutionResult as U, type MediaKind as V, type MediaMetadata as W, type GadgetExecuteResultWithMedia as X, type ProviderAdapter as Y, type ModelDescriptor as Z, type ModelSpec as _, type LLMStream as a, isImagePart as a$, type ImageModelSpec as a0, type ImageGenerationOptions as a1, type ImageGenerationResult as a2, type SpeechModelSpec as a3, type SpeechGenerationOptions as a4, type SpeechGenerationResult as a5, type HistoryMessage as a6, type TrailingMessage as a7, type TrailingMessageContext as a8, AgentBuilder as a9, type ObserveLLMCallContext as aA, type ObserveLLMCompleteContext as aB, type ObserveLLMErrorContext as aC, type Observers as aD, type SubagentContext as aE, DEFAULT_COMPACTION_CONFIG as aF, DEFAULT_SUMMARIZATION_PROMPT as aG, type LLMistOptions as aH, type AudioContentPart as aI, type AudioMimeType as aJ, type AudioSource as aK, type ContentPart as aL, type ImageBase64Source as aM, type ImageContentPart as aN, type ImageMimeType as aO, type ImageSource as aP, type ImageUrlSource as aQ, type TextContentPart as aR, audioFromBase64 as aS, audioFromBuffer as aT, detectAudioMimeType as aU, detectImageMimeType as aV, imageFromBase64 as aW, imageFromBuffer as aX, imageFromUrl as aY, isAudioPart as aZ, isDataUrl as a_, type EventHandlers as aa, collectEvents as ab, collectText as ac, runWithHandlers as ad, type AfterGadgetExecutionAction as ae, type AfterGadgetExecutionControllerContext as af, type AfterLLMCallAction as ag, type AfterLLMCallControllerContext as ah, type AfterLLMErrorAction as ai, type AgentOptions as aj, type BeforeGadgetExecutionAction as ak, type BeforeLLMCallAction as al, type ChunkInterceptorContext as am, type Controllers as an, type GadgetExecutionControllerContext as ao, type GadgetParameterInterceptorContext as ap, type GadgetResultInterceptorContext as aq, type Interceptors as ar, type LLMCallControllerContext as as, type LLMErrorControllerContext as at, type MessageInterceptorContext as au, type MessageTurn as av, type ObserveChunkContext as aw, type ObserveCompactionContext as ax, type ObserveGadgetCompleteContext as ay, type ObserveGadgetStartContext as az, type LLMStreamChunk as b, isTextPart as b0, parseDataUrl as b1, text as b2, toBase64 as b3, type MessageRole as b4, extractMessageText as b5, LLMMessageBuilder as b6, normalizeMessageContent as b7, type CostEstimate as b8, type ModelFeatures as b9, type TextOnlyContext as bA, type TextOnlyCustomHandler as bB, type TextOnlyGadgetConfig as bC, type TextOnlyHandler as bD, type TextOnlyStrategy as bE, type ModelLimits as ba, type ModelPricing as bb, type VisionAnalyzeOptions as bc, type VisionAnalyzeResult as bd, type ProviderIdentifier as be, ModelIdentifierParser as bf, type HintContext as bg, type PromptContext as bh, type PromptTemplate as bi, type PromptTemplateConfig as bj, DEFAULT_HINTS as bk, DEFAULT_PROMPTS as bl, resolveHintTemplate as bm, resolvePromptTemplate as bn, resolveRulesTemplate as bo, type TextGenerationOptions as bp, complete as bq, stream as br, type GadgetClass as bs, type GadgetOrClass as bt, type CostReportingLLMist as bu, type GadgetExecuteResult as bv, type GadgetSkippedEvent as bw, type StoredMedia as bx, type SubagentStreamEvent as by, type TextOnlyAction as bz, createMockAdapter as c, MockBuilder as d, createMockClient as e, MockManager as f, getMockManager as g, createMockStream as h, createTextMockStream as i, type MockAudioData as j, type MockImageData as k, type MockMatcher as l, mockLLM as m, type MockMatcherContext as n, type MockOptions as o, type MockRegistration as p, type MockResponse as q, type MockStats as r, type AgentHooks as s, ModelRegistry as t, LLMist as u, type CompactionEvent as v, type CompactionStats as w, type CompactionStrategy as x, type CompactionContext as y, type CompactionResult as z };
|
package/dist/testing/index.cjs
CHANGED
|
@@ -3485,7 +3485,7 @@ var init_executor = __esm({
|
|
|
3485
3485
|
init_exceptions();
|
|
3486
3486
|
init_parser();
|
|
3487
3487
|
GadgetExecutor = class {
|
|
3488
|
-
constructor(registry, requestHumanInput, logger, defaultGadgetTimeoutMs, errorFormatterOptions, client, mediaStore, agentConfig, subagentConfig,
|
|
3488
|
+
constructor(registry, requestHumanInput, logger, defaultGadgetTimeoutMs, errorFormatterOptions, client, mediaStore, agentConfig, subagentConfig, onSubagentEvent) {
|
|
3489
3489
|
this.registry = registry;
|
|
3490
3490
|
this.requestHumanInput = requestHumanInput;
|
|
3491
3491
|
this.defaultGadgetTimeoutMs = defaultGadgetTimeoutMs;
|
|
@@ -3493,7 +3493,7 @@ var init_executor = __esm({
|
|
|
3493
3493
|
this.mediaStore = mediaStore;
|
|
3494
3494
|
this.agentConfig = agentConfig;
|
|
3495
3495
|
this.subagentConfig = subagentConfig;
|
|
3496
|
-
this.
|
|
3496
|
+
this.onSubagentEvent = onSubagentEvent;
|
|
3497
3497
|
this.logger = logger ?? createLogger({ name: "llmist:executor" });
|
|
3498
3498
|
this.errorFormatter = new GadgetExecutionErrorFormatter(errorFormatterOptions);
|
|
3499
3499
|
this.argPrefix = errorFormatterOptions?.argPrefix ?? GADGET_ARG_PREFIX;
|
|
@@ -3641,7 +3641,7 @@ var init_executor = __esm({
|
|
|
3641
3641
|
agentConfig: this.agentConfig,
|
|
3642
3642
|
subagentConfig: this.subagentConfig,
|
|
3643
3643
|
invocationId: call.invocationId,
|
|
3644
|
-
|
|
3644
|
+
onSubagentEvent: this.onSubagentEvent
|
|
3645
3645
|
};
|
|
3646
3646
|
let rawResult;
|
|
3647
3647
|
if (timeoutMs && timeoutMs > 0) {
|
|
@@ -3881,7 +3881,7 @@ var init_stream_processor = __esm({
|
|
|
3881
3881
|
options.mediaStore,
|
|
3882
3882
|
options.agentConfig,
|
|
3883
3883
|
options.subagentConfig,
|
|
3884
|
-
options.
|
|
3884
|
+
options.onSubagentEvent
|
|
3885
3885
|
);
|
|
3886
3886
|
}
|
|
3887
3887
|
/**
|
|
@@ -4840,8 +4840,12 @@ var init_agent = __esm({
|
|
|
4840
4840
|
// Subagent configuration
|
|
4841
4841
|
agentContextConfig;
|
|
4842
4842
|
subagentConfig;
|
|
4843
|
-
//
|
|
4844
|
-
|
|
4843
|
+
// Subagent event callback for subagent gadgets
|
|
4844
|
+
userSubagentEventCallback;
|
|
4845
|
+
// Internal queue for yielding subagent events in run()
|
|
4846
|
+
pendingSubagentEvents = [];
|
|
4847
|
+
// Combined callback that queues events AND calls user callback
|
|
4848
|
+
onSubagentEvent;
|
|
4845
4849
|
/**
|
|
4846
4850
|
* Creates a new Agent instance.
|
|
4847
4851
|
* @internal This constructor is private. Use LLMist.createAgent() or AgentBuilder instead.
|
|
@@ -4919,7 +4923,71 @@ var init_agent = __esm({
|
|
|
4919
4923
|
temperature: this.temperature
|
|
4920
4924
|
};
|
|
4921
4925
|
this.subagentConfig = options.subagentConfig;
|
|
4922
|
-
this.
|
|
4926
|
+
this.userSubagentEventCallback = options.onSubagentEvent;
|
|
4927
|
+
this.onSubagentEvent = (event) => {
|
|
4928
|
+
this.pendingSubagentEvents.push(event);
|
|
4929
|
+
this.userSubagentEventCallback?.(event);
|
|
4930
|
+
const subagentContext = {
|
|
4931
|
+
parentGadgetInvocationId: event.gadgetInvocationId,
|
|
4932
|
+
depth: event.depth
|
|
4933
|
+
};
|
|
4934
|
+
if (event.type === "llm_call_start") {
|
|
4935
|
+
const info = event.event;
|
|
4936
|
+
void this.hooks?.observers?.onLLMCallStart?.({
|
|
4937
|
+
iteration: info.iteration,
|
|
4938
|
+
options: { model: info.model, messages: [] },
|
|
4939
|
+
logger: this.logger,
|
|
4940
|
+
subagentContext
|
|
4941
|
+
});
|
|
4942
|
+
} else if (event.type === "llm_call_end") {
|
|
4943
|
+
const info = event.event;
|
|
4944
|
+
void this.hooks?.observers?.onLLMCallComplete?.({
|
|
4945
|
+
iteration: info.iteration,
|
|
4946
|
+
options: { model: info.model, messages: [] },
|
|
4947
|
+
finishReason: info.finishReason ?? null,
|
|
4948
|
+
usage: info.outputTokens ? {
|
|
4949
|
+
inputTokens: info.inputTokens ?? 0,
|
|
4950
|
+
outputTokens: info.outputTokens,
|
|
4951
|
+
totalTokens: (info.inputTokens ?? 0) + info.outputTokens
|
|
4952
|
+
} : void 0,
|
|
4953
|
+
rawResponse: "",
|
|
4954
|
+
finalMessage: "",
|
|
4955
|
+
logger: this.logger,
|
|
4956
|
+
subagentContext
|
|
4957
|
+
});
|
|
4958
|
+
} else if (event.type === "gadget_call") {
|
|
4959
|
+
const gadgetEvent = event.event;
|
|
4960
|
+
void this.hooks?.observers?.onGadgetExecutionStart?.({
|
|
4961
|
+
iteration: 0,
|
|
4962
|
+
gadgetName: gadgetEvent.call.gadgetName,
|
|
4963
|
+
invocationId: gadgetEvent.call.invocationId,
|
|
4964
|
+
parameters: gadgetEvent.call.parameters ?? {},
|
|
4965
|
+
logger: this.logger,
|
|
4966
|
+
subagentContext
|
|
4967
|
+
});
|
|
4968
|
+
} else if (event.type === "gadget_result") {
|
|
4969
|
+
const resultEvent = event.event;
|
|
4970
|
+
void this.hooks?.observers?.onGadgetExecutionComplete?.({
|
|
4971
|
+
iteration: 0,
|
|
4972
|
+
gadgetName: resultEvent.result.gadgetName ?? "unknown",
|
|
4973
|
+
invocationId: resultEvent.result.invocationId,
|
|
4974
|
+
parameters: {},
|
|
4975
|
+
executionTimeMs: resultEvent.result.executionTimeMs ?? 0,
|
|
4976
|
+
logger: this.logger,
|
|
4977
|
+
subagentContext
|
|
4978
|
+
});
|
|
4979
|
+
}
|
|
4980
|
+
};
|
|
4981
|
+
}
|
|
4982
|
+
/**
|
|
4983
|
+
* Flush pending subagent events as StreamEvents.
|
|
4984
|
+
* Called from run() to yield queued subagent events from subagent gadgets.
|
|
4985
|
+
*/
|
|
4986
|
+
*flushPendingSubagentEvents() {
|
|
4987
|
+
while (this.pendingSubagentEvents.length > 0) {
|
|
4988
|
+
const event = this.pendingSubagentEvents.shift();
|
|
4989
|
+
yield { type: "subagent_event", subagentEvent: event };
|
|
4990
|
+
}
|
|
4923
4991
|
}
|
|
4924
4992
|
/**
|
|
4925
4993
|
* Get the gadget registry for this agent.
|
|
@@ -5151,7 +5219,7 @@ var init_agent = __esm({
|
|
|
5151
5219
|
mediaStore: this.mediaStore,
|
|
5152
5220
|
agentConfig: this.agentContextConfig,
|
|
5153
5221
|
subagentConfig: this.subagentConfig,
|
|
5154
|
-
|
|
5222
|
+
onSubagentEvent: this.onSubagentEvent
|
|
5155
5223
|
});
|
|
5156
5224
|
let streamMetadata = null;
|
|
5157
5225
|
let gadgetCallCount = 0;
|
|
@@ -5169,6 +5237,7 @@ var init_agent = __esm({
|
|
|
5169
5237
|
gadgetResults.push(event);
|
|
5170
5238
|
}
|
|
5171
5239
|
yield event;
|
|
5240
|
+
yield* this.flushPendingSubagentEvents();
|
|
5172
5241
|
}
|
|
5173
5242
|
if (!streamMetadata) {
|
|
5174
5243
|
throw new Error("Stream processing completed without metadata event");
|
|
@@ -5474,7 +5543,7 @@ var init_builder = __esm({
|
|
|
5474
5543
|
signal;
|
|
5475
5544
|
trailingMessage;
|
|
5476
5545
|
subagentConfig;
|
|
5477
|
-
|
|
5546
|
+
subagentEventCallback;
|
|
5478
5547
|
parentContext;
|
|
5479
5548
|
constructor(client) {
|
|
5480
5549
|
this.client = client;
|
|
@@ -5973,38 +6042,38 @@ var init_builder = __esm({
|
|
|
5973
6042
|
return this;
|
|
5974
6043
|
}
|
|
5975
6044
|
/**
|
|
5976
|
-
* Set the callback for
|
|
6045
|
+
* Set the callback for subagent events.
|
|
5977
6046
|
*
|
|
5978
|
-
* Subagent gadgets (like BrowseWeb) can use ExecutionContext.
|
|
6047
|
+
* Subagent gadgets (like BrowseWeb) can use ExecutionContext.onSubagentEvent
|
|
5979
6048
|
* to report their internal LLM calls and gadget executions in real-time.
|
|
5980
6049
|
* This callback receives those events, enabling hierarchical progress display.
|
|
5981
6050
|
*
|
|
5982
|
-
* @param callback - Function to handle
|
|
6051
|
+
* @param callback - Function to handle subagent events
|
|
5983
6052
|
* @returns This builder for chaining
|
|
5984
6053
|
*
|
|
5985
6054
|
* @example
|
|
5986
6055
|
* ```typescript
|
|
5987
|
-
* .
|
|
6056
|
+
* .withSubagentEventCallback((event) => {
|
|
5988
6057
|
* if (event.type === "llm_call_start") {
|
|
5989
|
-
* console.log(`
|
|
6058
|
+
* console.log(` Subagent LLM #${event.event.iteration} starting...`);
|
|
5990
6059
|
* } else if (event.type === "gadget_call") {
|
|
5991
6060
|
* console.log(` ⏵ ${event.event.call.gadgetName}...`);
|
|
5992
6061
|
* }
|
|
5993
6062
|
* })
|
|
5994
6063
|
* ```
|
|
5995
6064
|
*/
|
|
5996
|
-
|
|
5997
|
-
this.
|
|
6065
|
+
withSubagentEventCallback(callback) {
|
|
6066
|
+
this.subagentEventCallback = callback;
|
|
5998
6067
|
return this;
|
|
5999
6068
|
}
|
|
6000
6069
|
/**
|
|
6001
|
-
* Enable automatic
|
|
6070
|
+
* Enable automatic subagent event forwarding to parent agent.
|
|
6002
6071
|
*
|
|
6003
6072
|
* When building a subagent inside a gadget, call this method to automatically
|
|
6004
6073
|
* forward all LLM calls and gadget events to the parent agent. This enables
|
|
6005
6074
|
* hierarchical progress display without any manual event handling.
|
|
6006
6075
|
*
|
|
6007
|
-
* The method extracts `invocationId` and `
|
|
6076
|
+
* The method extracts `invocationId` and `onSubagentEvent` from the execution
|
|
6008
6077
|
* context and sets up automatic forwarding via hooks and event wrapping.
|
|
6009
6078
|
*
|
|
6010
6079
|
* @param ctx - ExecutionContext passed to the gadget's execute() method
|
|
@@ -6031,10 +6100,10 @@ var init_builder = __esm({
|
|
|
6031
6100
|
* ```
|
|
6032
6101
|
*/
|
|
6033
6102
|
withParentContext(ctx, depth = 1) {
|
|
6034
|
-
if (ctx.
|
|
6103
|
+
if (ctx.onSubagentEvent && ctx.invocationId) {
|
|
6035
6104
|
this.parentContext = {
|
|
6036
6105
|
invocationId: ctx.invocationId,
|
|
6037
|
-
|
|
6106
|
+
onSubagentEvent: ctx.onSubagentEvent,
|
|
6038
6107
|
depth
|
|
6039
6108
|
};
|
|
6040
6109
|
}
|
|
@@ -6109,20 +6178,22 @@ ${endPrefix}`
|
|
|
6109
6178
|
/**
|
|
6110
6179
|
* Compose the final hooks, including:
|
|
6111
6180
|
* - Trailing message injection (if configured)
|
|
6112
|
-
* -
|
|
6181
|
+
* - Subagent event forwarding for LLM calls (if parentContext is set)
|
|
6113
6182
|
*/
|
|
6114
6183
|
composeHooks() {
|
|
6115
6184
|
let hooks = this.hooks;
|
|
6116
6185
|
if (this.parentContext) {
|
|
6117
|
-
const { invocationId,
|
|
6186
|
+
const { invocationId, onSubagentEvent, depth } = this.parentContext;
|
|
6118
6187
|
const existingOnLLMCallStart = hooks?.observers?.onLLMCallStart;
|
|
6119
6188
|
const existingOnLLMCallComplete = hooks?.observers?.onLLMCallComplete;
|
|
6189
|
+
const existingOnGadgetExecutionStart = hooks?.observers?.onGadgetExecutionStart;
|
|
6190
|
+
const existingOnGadgetExecutionComplete = hooks?.observers?.onGadgetExecutionComplete;
|
|
6120
6191
|
hooks = {
|
|
6121
6192
|
...hooks,
|
|
6122
6193
|
observers: {
|
|
6123
6194
|
...hooks?.observers,
|
|
6124
6195
|
onLLMCallStart: async (context) => {
|
|
6125
|
-
|
|
6196
|
+
onSubagentEvent({
|
|
6126
6197
|
type: "llm_call_start",
|
|
6127
6198
|
gadgetInvocationId: invocationId,
|
|
6128
6199
|
depth,
|
|
@@ -6136,7 +6207,7 @@ ${endPrefix}`
|
|
|
6136
6207
|
}
|
|
6137
6208
|
},
|
|
6138
6209
|
onLLMCallComplete: async (context) => {
|
|
6139
|
-
|
|
6210
|
+
onSubagentEvent({
|
|
6140
6211
|
type: "llm_call_end",
|
|
6141
6212
|
gadgetInvocationId: invocationId,
|
|
6142
6213
|
depth,
|
|
@@ -6150,6 +6221,38 @@ ${endPrefix}`
|
|
|
6150
6221
|
if (existingOnLLMCallComplete) {
|
|
6151
6222
|
await existingOnLLMCallComplete(context);
|
|
6152
6223
|
}
|
|
6224
|
+
},
|
|
6225
|
+
onGadgetExecutionStart: async (context) => {
|
|
6226
|
+
onSubagentEvent({
|
|
6227
|
+
type: "gadget_call",
|
|
6228
|
+
gadgetInvocationId: invocationId,
|
|
6229
|
+
depth,
|
|
6230
|
+
event: {
|
|
6231
|
+
call: {
|
|
6232
|
+
invocationId: context.invocationId,
|
|
6233
|
+
gadgetName: context.gadgetName,
|
|
6234
|
+
parameters: context.parameters
|
|
6235
|
+
}
|
|
6236
|
+
}
|
|
6237
|
+
});
|
|
6238
|
+
if (existingOnGadgetExecutionStart) {
|
|
6239
|
+
await existingOnGadgetExecutionStart(context);
|
|
6240
|
+
}
|
|
6241
|
+
},
|
|
6242
|
+
onGadgetExecutionComplete: async (context) => {
|
|
6243
|
+
onSubagentEvent({
|
|
6244
|
+
type: "gadget_result",
|
|
6245
|
+
gadgetInvocationId: invocationId,
|
|
6246
|
+
depth,
|
|
6247
|
+
event: {
|
|
6248
|
+
result: {
|
|
6249
|
+
invocationId: context.invocationId
|
|
6250
|
+
}
|
|
6251
|
+
}
|
|
6252
|
+
});
|
|
6253
|
+
if (existingOnGadgetExecutionComplete) {
|
|
6254
|
+
await existingOnGadgetExecutionComplete(context);
|
|
6255
|
+
}
|
|
6153
6256
|
}
|
|
6154
6257
|
}
|
|
6155
6258
|
};
|
|
@@ -6236,11 +6339,11 @@ ${endPrefix}`
|
|
|
6236
6339
|
this.client = new LLMistClass();
|
|
6237
6340
|
}
|
|
6238
6341
|
const registry = GadgetRegistry.from(this.gadgets);
|
|
6239
|
-
let
|
|
6342
|
+
let onSubagentEvent = this.subagentEventCallback;
|
|
6240
6343
|
if (this.parentContext) {
|
|
6241
|
-
const { invocationId,
|
|
6242
|
-
const existingCallback = this.
|
|
6243
|
-
|
|
6344
|
+
const { invocationId, onSubagentEvent: parentCallback, depth } = this.parentContext;
|
|
6345
|
+
const existingCallback = this.subagentEventCallback;
|
|
6346
|
+
onSubagentEvent = (event) => {
|
|
6244
6347
|
parentCallback({
|
|
6245
6348
|
...event,
|
|
6246
6349
|
gadgetInvocationId: invocationId,
|
|
@@ -6275,7 +6378,7 @@ ${endPrefix}`
|
|
|
6275
6378
|
compactionConfig: this.compactionConfig,
|
|
6276
6379
|
signal: this.signal,
|
|
6277
6380
|
subagentConfig: this.subagentConfig,
|
|
6278
|
-
|
|
6381
|
+
onSubagentEvent
|
|
6279
6382
|
};
|
|
6280
6383
|
}
|
|
6281
6384
|
ask(userPrompt) {
|
|
@@ -6432,11 +6535,11 @@ ${endPrefix}`
|
|
|
6432
6535
|
this.client = new LLMistClass();
|
|
6433
6536
|
}
|
|
6434
6537
|
const registry = GadgetRegistry.from(this.gadgets);
|
|
6435
|
-
let
|
|
6538
|
+
let onSubagentEvent = this.subagentEventCallback;
|
|
6436
6539
|
if (this.parentContext) {
|
|
6437
|
-
const { invocationId,
|
|
6438
|
-
const existingCallback = this.
|
|
6439
|
-
|
|
6540
|
+
const { invocationId, onSubagentEvent: parentCallback, depth } = this.parentContext;
|
|
6541
|
+
const existingCallback = this.subagentEventCallback;
|
|
6542
|
+
onSubagentEvent = (event) => {
|
|
6440
6543
|
parentCallback({
|
|
6441
6544
|
...event,
|
|
6442
6545
|
gadgetInvocationId: invocationId,
|
|
@@ -6471,7 +6574,7 @@ ${endPrefix}`
|
|
|
6471
6574
|
compactionConfig: this.compactionConfig,
|
|
6472
6575
|
signal: this.signal,
|
|
6473
6576
|
subagentConfig: this.subagentConfig,
|
|
6474
|
-
|
|
6577
|
+
onSubagentEvent
|
|
6475
6578
|
};
|
|
6476
6579
|
return new Agent(AGENT_INTERNAL_KEY, options);
|
|
6477
6580
|
}
|