@oh-my-pi/pi-agent-core 18.2.11 → 18.3.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/src/types.ts CHANGED
@@ -24,6 +24,7 @@ import type { Dialect } from "@oh-my-pi/pi-ai/dialect";
24
24
  import type { HarmonyAuditEvent } from "@oh-my-pi/pi-ai/utils/harmony-leak";
25
25
  import type { AppendOnlyContextManager } from "./append-only-context";
26
26
  import type { AgentRunCoverage, AgentRunSummary } from "./run-collector";
27
+ import type { SentToolDefinitions } from "./sent-tool-definitions";
27
28
  import type { AgentTelemetryConfig } from "./telemetry";
28
29
 
29
30
  /** Stream function - can return sync or Promise for async config lookup */
@@ -68,6 +69,12 @@ export interface AgentTurnEndContext {
68
69
  message: AgentMessage;
69
70
  /** Tool results produced by this turn, already paired with `message` in the live context. */
70
71
  toolResults: ToolResultMessage[];
72
+ /**
73
+ * Passive model-visible messages appended after the tool results at this
74
+ * boundary. The agent loop always sends an array (possibly empty);
75
+ * absent is equivalent to empty for hosts that construct the context.
76
+ */
77
+ additionalMessages?: AgentMessage[];
71
78
  /** True when the current tool-loop batch is continuing without yielding to post-turn steering. */
72
79
  willContinue: boolean;
73
80
  }
@@ -163,8 +170,10 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
163
170
 
164
171
  /**
165
172
  * When to interrupt tool execution for steering messages.
166
- * - "immediate" = check after each tool call (default)
167
- * - "wait" = defer steering until the current turn completes
173
+ * - "immediate" = cut interruptible waits short and raise the cooperative
174
+ * `steeringSignal` for other running tools (default)
175
+ * - "wait" = let non-interruptible tools finish undisturbed; interruptible
176
+ * waits are still cut short, since they have no work to complete
168
177
  */
169
178
  interruptMode?: "immediate" | "wait";
170
179
 
@@ -238,6 +247,9 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
238
247
  */
239
248
  transformProviderContext?: (context: Context, model: Model) => Context | Promise<Context>;
240
249
 
250
+ /** Remembers sent tool definitions to fill {@link Context.inactiveTools}. */
251
+ sentToolDefinitions?: SentToolDefinitions;
252
+
241
253
  /**
242
254
  * Resolves the API key or resolver for the current model before each LLM call.
243
255
  *
@@ -259,8 +271,9 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
259
271
  /**
260
272
  * Peeks whether steering messages are queued, without consuming them.
261
273
  *
262
- * Polled while a tool batch runs (unless interruptMode is "wait") to decide
263
- * whether to abort in-flight and skip not-yet-started *interruptible* waits;
274
+ * Polled while a tool batch runs (in "wait" mode, only when the batch holds an
275
+ * interruptible tool) to decide whether to abort in-flight and skip
276
+ * not-yet-started *interruptible* waits;
264
277
  * every other already-emitted call still executes and the message injects
265
278
  * at the batch boundary. The queue keeps
266
279
  * owning its messages until the loop reaches the next injection boundary and
@@ -289,7 +302,8 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
289
302
  * Peeks whether IRC messages should interrupt an interruptible waiting tool.
290
303
  *
291
304
  * Uses the same delivery rules as steering: the poll is non-consuming, only
292
- * runs for interruptible tools, and is ignored when interruptMode is "wait".
305
+ * runs for interruptible tools, and cuts them short even when interruptMode
306
+ * is "wait".
293
307
  * The host owns message injection at the next boundary.
294
308
  */
295
309
  hasIrcInterrupts?: () => boolean | Promise<boolean>;
@@ -298,8 +312,8 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
298
312
  * process) is queued for aside injection at the next boundary.
299
313
  *
300
314
  * Same rules as {@link hasIrcInterrupts}: non-consuming, only cuts
301
- * *interruptible* waits short, ignored when interruptMode is "wait". Without
302
- * it a completion notice sits behind an hour-long `hub wait` that the agent
315
+ * *interruptible* waits short, in either interruptMode. Without
316
+ * it a completion notice sits behind an hour-long `wait` that the agent
303
317
  * would have abandoned had it seen the notice. Unlike a peer IRC it never
304
318
  * raises {@link ToolCallContext.steeringSignal}: a queued completion must
305
319
  * not push ordinary foreground work (auto-background bash/eval) into the
@@ -336,7 +350,11 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
336
350
 
337
351
  /**
338
352
  * Provides tool execution context, resolved per tool call.
339
- * Use for late-bound UI or session state access.
353
+ * Use for late-bound UI or session state access. The loop passes the tool
354
+ * call's {@link ToolCallContext}; hosts that support passive tool context
355
+ * surface its `addAdditionalContext` sink as
356
+ * {@link AgentToolContext.addAdditionalContext}. The returned object is
357
+ * handed to the tool as-is.
340
358
  */
341
359
  getToolContext?: (toolCall?: ToolCallContext) => AgentToolContext | undefined;
342
360
 
@@ -414,6 +432,12 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
414
432
  * model's text output back into canonical `toolCall` blocks.
415
433
  */
416
434
  dialect?: Dialect;
435
+ /**
436
+ * Per-call owned-dialect resolver, read once per LLM call with the model
437
+ * being requested. Authoritative when set: its return value (including
438
+ * `undefined` = native tool calling) replaces the static {@link dialect}.
439
+ */
440
+ getDialect?: (model: Model) => Dialect | undefined;
417
441
  /**
418
442
  * When owned (in-band) tool calling is active and the model starts
419
443
  * fabricating a tool result inside its own turn, control how the loop reacts:
@@ -607,6 +631,13 @@ export interface ToolCallContext {
607
631
  * always safe (the message injects at the next batch boundary).
608
632
  */
609
633
  steeringSignal?: AbortSignal;
634
+ /**
635
+ * Loop-owned sink for passive context reported while this call executes.
636
+ * Values join the call's context at the batch boundary and are injected
637
+ * after the batch's tool results, in assistant tool-call order, before the
638
+ * next provider request. Blank values are ignored.
639
+ */
640
+ addAdditionalContext?: (context: string) => void;
610
641
  }
611
642
 
612
643
  /** A single tool-call content block emitted by an assistant message. */
@@ -809,11 +840,19 @@ export interface SpeculativeToolExecutionConfig {
809
840
  * written back to the tool-call block on the assistant message, and seen by
810
841
  * history, scheduling, execution events, and `tool.execute` alike. It is
811
842
  * ignored when `block` is true.
843
+ *
844
+ * Set `additionalContext` to attach passive model-visible context to this call.
845
+ * Non-empty values from a tool batch are injected in assistant tool-call order
846
+ * after every result settles and before the next provider request. It is
847
+ * dropped when the call is blocked or skipped, or when its final result is an
848
+ * error (including an approval denial raised by the tool's own gate). Within a
849
+ * call it follows any context the tool reported during execution.
812
850
  */
813
851
  export interface BeforeToolCallResult {
814
852
  block?: boolean;
815
853
  reason?: string;
816
854
  args?: Record<string, unknown>;
855
+ additionalContext?: string;
817
856
  }
818
857
 
819
858
  /**
@@ -981,6 +1020,16 @@ export type ToolApproval = ToolApprovalDecision | ((args: unknown) => ToolApprov
981
1020
  * Apps can extend via declaration merging.
982
1021
  */
983
1022
  export interface AgentToolContext {
1023
+ /**
1024
+ * Attach trusted, agent-authored instructions to the next provider request.
1025
+ * The host emits them after tool results with developer/system priority where
1026
+ * the selected transport supports it. Do not use this channel for raw tool
1027
+ * output, retrieved documents, web content, or other untrusted data; return
1028
+ * those through the ordinary tool result instead. Hosts populate it from
1029
+ * {@link ToolCallContext.addAdditionalContext} (or their own collector for
1030
+ * calls dispatched outside the loop); absent when the host has no sink.
1031
+ */
1032
+ addAdditionalContext?(context: string): void;
984
1033
  /** Present only while the matching outer tool owns its finalized stream session. */
985
1034
  [SPECULATIVE_STREAM_SESSION]?: ToolSpeculationStreamSession;
986
1035
  }
@@ -1034,6 +1083,12 @@ export interface AgentTool<
1034
1083
  loadMode?: ToolLoadMode;
1035
1084
  /** Short one-line summary used for tool discovery indexes. */
1036
1085
  summary?: string;
1086
+ /**
1087
+ * On-demand documentation topics (`topic → markdown`), readable as
1088
+ * `xd://<tool>/<topic>`. Lets a tool keep large sub-surfaces out of its
1089
+ * description and advertise only a one-line pointer per topic.
1090
+ */
1091
+ docTopics?(): Readonly<Record<string, string>>;
1037
1092
  /**
1038
1093
  * Concurrency mode for tool scheduling when multiple calls are in one turn.
1039
1094
  * - "shared": can run alongside other shared tools (default)
@@ -1058,7 +1113,7 @@ export interface AgentTool<
1058
1113
  * cleanly (e.g. `job` poll), so the abort surfaces the tool's current
1059
1114
  * snapshot rather than corrupting a side effect. Every other call runs to
1060
1115
  * completion even when steering is queued; the message lands at the next
1061
- * batch boundary. Honored only when `interruptMode` is "immediate".
1116
+ * batch boundary. Honored in both `interruptMode`s.
1062
1117
  */
1063
1118
  interruptible?: boolean | ((args: Partial<Static<TParameters>>) => boolean);
1064
1119
  /**