@oh-my-pi/pi-agent-core 19.0.1 → 19.1.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/CHANGELOG.md +6 -0
- package/dist/types/agent-loop.d.ts +5 -0
- package/dist/types/agent.d.ts +6 -4
- package/dist/types/sent-tool-definitions.d.ts +6 -3
- package/dist/types/tool-arguments.d.ts +2 -1
- package/dist/types/types.d.ts +17 -16
- package/package.json +8 -8
- package/src/agent-loop.ts +40 -28
- package/src/agent.ts +22 -13
- package/src/compaction/compaction-v2-streaming.ts +0 -1
- package/src/sent-tool-definitions.ts +20 -10
- package/src/tokenizer.ts +10 -2
- package/src/tool-arguments.ts +2 -1
- package/src/types.ts +17 -16
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [19.1.0] - 2026-11-21
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Added standby tools support through `Agent.setStandbyTools()` and `AgentContext.standbyTools`, allowing tools to remain inactive until a request explicitly enables tool use.
|
|
10
|
+
|
|
5
11
|
## [19.0.0] - 2026-11-18
|
|
6
12
|
|
|
7
13
|
### Added
|
|
@@ -123,6 +123,11 @@ export interface NormalizeToolsOptions {
|
|
|
123
123
|
pruneDescriptions?: boolean;
|
|
124
124
|
}
|
|
125
125
|
export declare function normalizeTools(tools: AgentContext["tools"], options: NormalizeToolsOptions): Context["tools"];
|
|
126
|
+
/** Split a traced call's intent (`i`, trimmed, trailing periods dropped) from the arguments its tool reads. */
|
|
127
|
+
export declare function extractIntent(args: Record<string, unknown>): {
|
|
128
|
+
intent?: string;
|
|
129
|
+
strippedArgs: Record<string, unknown>;
|
|
130
|
+
};
|
|
126
131
|
/**
|
|
127
132
|
* Classify the first `count` steering messages for a tool-batch interrupt:
|
|
128
133
|
* any user-authored message wins, then agent-attributed user messages, else
|
package/dist/types/agent.d.ts
CHANGED
|
@@ -145,14 +145,14 @@ export interface AgentOptions {
|
|
|
145
145
|
speculativeToolExecution?: SpeculativeToolExecutionConfig;
|
|
146
146
|
/**
|
|
147
147
|
* Resolve a tool call whose name matched no advertised tool. Lets hosts
|
|
148
|
-
* route calls to tools
|
|
149
|
-
*
|
|
148
|
+
* route calls to tools reached through a side transport (e.g. mounted
|
|
149
|
+
* tool commands run through `bash`) instead of failing with "Tool not found".
|
|
150
150
|
*/
|
|
151
151
|
resolveFallbackTool?: (name: string, advertised: readonly AgentTool<any>[]) => AgentTool<any> | undefined;
|
|
152
152
|
/**
|
|
153
153
|
* Names routable by {@link resolveFallbackTool} that the advertised set
|
|
154
|
-
* omits (e.g.
|
|
155
|
-
* call misses.
|
|
154
|
+
* omits (e.g. mounted tool commands run through `bash`), used only to
|
|
155
|
+
* suggest a target when a call misses.
|
|
156
156
|
*/
|
|
157
157
|
suggestFallbackToolNames?: () => Iterable<string>;
|
|
158
158
|
/** Enable intent tracing schema injection/stripping in the harness. */
|
|
@@ -525,6 +525,8 @@ export declare class Agent {
|
|
|
525
525
|
setInterruptMode(mode: "immediate" | "wait"): void;
|
|
526
526
|
getInterruptMode(): "immediate" | "wait";
|
|
527
527
|
setTools(t: AgentTool<any>[]): void;
|
|
528
|
+
/** Set the inactive tools that may become active later ({@link AgentContext.standbyTools}). */
|
|
529
|
+
setStandbyTools(tools: AgentTool[]): void;
|
|
528
530
|
replaceMessages(ms: AgentMessage[]): void;
|
|
529
531
|
replaceQueues(steering: AgentMessage[], followUp: AgentMessage[]): void;
|
|
530
532
|
/**
|
|
@@ -16,8 +16,11 @@ export declare class SentToolDefinitions {
|
|
|
16
16
|
/**
|
|
17
17
|
* `context` with {@link Context.inactiveTools} set to the definitions for names the latest
|
|
18
18
|
* `requestControls.tools.declared` in its messages holds that are not in its `tools`; cleared when
|
|
19
|
-
* there are none or the request declares no tools.
|
|
20
|
-
*
|
|
19
|
+
* there are none or the request declares no tools. A declared name this Agent never sent takes its
|
|
20
|
+
* `standby` definition (a resumed transcript declares standby tools a fresh process has not sent);
|
|
21
|
+
* names with neither are skipped, and the provider drops them from the declaration. Before any
|
|
22
|
+
* request declared tools, `standby` (minus active names) stands in, so the first declaration
|
|
23
|
+
* already holds tools that may activate later.
|
|
21
24
|
*/
|
|
22
|
-
withInactiveTools(context: Context): Context;
|
|
25
|
+
withInactiveTools(context: Context, standby?: readonly Tool[]): Context;
|
|
23
26
|
}
|
|
@@ -5,7 +5,8 @@ import type { AgentTool } from "./types.js";
|
|
|
5
5
|
* - `"parsed"`: a provider stream parsed the arguments, so `__parseError` is a
|
|
6
6
|
* genuine parse-failure sentinel and is never handed to a tool.
|
|
7
7
|
* - `"payload"`: the arguments are a payload the model wrote (eval tool bridge,
|
|
8
|
-
*
|
|
8
|
+
* a tool command line parsed into arguments), so those keys are forged and
|
|
9
|
+
* only stripped.
|
|
9
10
|
*/
|
|
10
11
|
export type ToolArgumentSource = "parsed" | "payload";
|
|
11
12
|
/**
|
package/dist/types/types.d.ts
CHANGED
|
@@ -101,8 +101,8 @@ export interface SoftToolRequirement {
|
|
|
101
101
|
/**
|
|
102
102
|
* Per-call compliance check: a turn satisfies the requirement only when every
|
|
103
103
|
* tool call passes. Defaults to `name === toolName`. Lets a host demand a
|
|
104
|
-
* specific invocation shape (e.g. `
|
|
105
|
-
* instead of any call to `toolName`. Escalation still forces `toolName`.
|
|
104
|
+
* specific invocation shape (e.g. a `bash` call running a particular tool
|
|
105
|
+
* command) instead of any call to `toolName`. Escalation still forces `toolName`.
|
|
106
106
|
*/
|
|
107
107
|
satisfies?(toolCall: {
|
|
108
108
|
name: string;
|
|
@@ -384,8 +384,8 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
|
|
|
384
384
|
/**
|
|
385
385
|
* Resolve a tool call whose name matched no advertised tool (including
|
|
386
386
|
* `customWireName` aliases). Lets hosts route calls to tools they expose
|
|
387
|
-
* through side
|
|
388
|
-
* with "Tool not found". Returning `undefined` keeps the failure.
|
|
387
|
+
* through a side transport (e.g. mounted tool commands run through `bash`)
|
|
388
|
+
* instead of failing with "Tool not found". Returning `undefined` keeps the failure.
|
|
389
389
|
*
|
|
390
390
|
* `advertised` is the very snapshot exact-name dispatch just searched — the
|
|
391
391
|
* set offered to THIS request. A host must resolve against it rather than
|
|
@@ -397,9 +397,9 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
|
|
|
397
397
|
resolveFallbackTool?: (name: string, advertised: readonly AgentTool<any>[]) => AgentTool<any> | undefined;
|
|
398
398
|
/**
|
|
399
399
|
* Names reachable through {@link resolveFallbackTool} but absent from the
|
|
400
|
-
* advertised set (e.g.
|
|
401
|
-
* plausible target when a call misses, so a mis-transcribed
|
|
402
|
-
* recoverable; never a dispatch source.
|
|
400
|
+
* advertised set (e.g. mounted tool commands run through `bash`). Consulted
|
|
401
|
+
* only to name a plausible target when a call misses, so a mis-transcribed
|
|
402
|
+
* command name is recoverable; never a dispatch source.
|
|
403
403
|
*/
|
|
404
404
|
suggestFallbackToolNames?: () => Iterable<string>;
|
|
405
405
|
/**
|
|
@@ -969,9 +969,9 @@ export type ToolTier = "read" | "write" | "exec";
|
|
|
969
969
|
/**
|
|
970
970
|
* How an enabled tool is presented to the model. `"essential"` tools are exposed
|
|
971
971
|
* as normal top-level tools. `"discoverable"` tools are removed from the top-level
|
|
972
|
-
* schema and either mounted
|
|
973
|
-
* active) or surfaced through BM25 tool search — keeping their schemas
|
|
974
|
-
* request. Selection (settings, `hidden`, `defaultInactive`, explicit `--tools`,
|
|
972
|
+
* schema and either mounted as a tool command in the `bash` tool (when that
|
|
973
|
+
* tool is active) or surfaced through BM25 tool search — keeping their schemas
|
|
974
|
+
* off every request. Selection (settings, `hidden`, `defaultInactive`, explicit `--tools`,
|
|
975
975
|
* provider availability) decides whether a tool is enabled; `loadMode` only
|
|
976
976
|
* decides how an enabled tool is presented.
|
|
977
977
|
*/
|
|
@@ -991,11 +991,6 @@ export type ToolApprovalDecision = ToolTier | {
|
|
|
991
991
|
reason?: string;
|
|
992
992
|
override?: boolean;
|
|
993
993
|
policy?: "allow" | "deny" | "prompt";
|
|
994
|
-
/** User-policy key for this decision. When set, `tools.approval.<policyKey>`
|
|
995
|
-
* is consulted instead of `tools.approval.<tool.name>`. Lets a dispatcher
|
|
996
|
-
* tool (e.g. `write` for an `xd://` device call) scope user allow/deny/
|
|
997
|
-
* prompt policies to the tool it dispatches into. */
|
|
998
|
-
policyKey?: string;
|
|
999
994
|
};
|
|
1000
995
|
export type ToolApproval = ToolApprovalDecision | ((args: unknown, context?: AgentToolContext) => ToolApprovalDecision);
|
|
1001
996
|
/**
|
|
@@ -1056,7 +1051,7 @@ export interface AgentTool<TParameters extends TSchema = TSchema, TDetails = any
|
|
|
1056
1051
|
readonly delegationGuidance?: string;
|
|
1057
1052
|
/**
|
|
1058
1053
|
* On-demand documentation topics (`topic → markdown`), readable as
|
|
1059
|
-
* `
|
|
1054
|
+
* `help://<tool>/<topic>`. Lets a tool keep large sub-surfaces out of its
|
|
1060
1055
|
* description and advertise only a one-line pointer per topic.
|
|
1061
1056
|
*/
|
|
1062
1057
|
docTopics?(): Readonly<Record<string, string>>;
|
|
@@ -1164,6 +1159,12 @@ export interface AgentContext {
|
|
|
1164
1159
|
systemPrompt: string[];
|
|
1165
1160
|
messages: AgentMessage[];
|
|
1166
1161
|
tools?: AgentTool<any>[];
|
|
1162
|
+
/**
|
|
1163
|
+
* Inactive tools that may become active later in the conversation. A provider that announces tool changes
|
|
1164
|
+
* in-band (Anthropic `tool_addition`) declares them from the first request, so activating one leaves the
|
|
1165
|
+
* cached prefix intact. See {@link SentToolDefinitions.withInactiveTools}.
|
|
1166
|
+
*/
|
|
1167
|
+
standbyTools?: AgentTool<any>[];
|
|
1167
1168
|
}
|
|
1168
1169
|
/**
|
|
1169
1170
|
* Events emitted by the Agent for UI updates.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@oh-my-pi/pi-agent-core",
|
|
4
|
-
"version": "19.0
|
|
4
|
+
"version": "19.1.0",
|
|
5
5
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
6
6
|
"homepage": "https://omp.sh",
|
|
7
7
|
"author": {
|
|
@@ -38,16 +38,16 @@
|
|
|
38
38
|
"fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@oh-my-pi/pi-ai": "19.0
|
|
42
|
-
"@oh-my-pi/pi-catalog": "19.0
|
|
43
|
-
"@oh-my-pi/pi-natives": "19.0
|
|
44
|
-
"@oh-my-pi/pi-utils": "19.0
|
|
45
|
-
"@oh-my-pi/pi-wire": "19.0
|
|
46
|
-
"@oh-my-pi/snapcompact": "19.0
|
|
41
|
+
"@oh-my-pi/pi-ai": "19.1.0",
|
|
42
|
+
"@oh-my-pi/pi-catalog": "19.1.0",
|
|
43
|
+
"@oh-my-pi/pi-natives": "19.1.0",
|
|
44
|
+
"@oh-my-pi/pi-utils": "19.1.0",
|
|
45
|
+
"@oh-my-pi/pi-wire": "19.1.0",
|
|
46
|
+
"@oh-my-pi/snapcompact": "19.1.0",
|
|
47
47
|
"@opentelemetry/api": "^1.9.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@oh-my-pi/omptype": "19.0
|
|
50
|
+
"@oh-my-pi/omptype": "19.1.0",
|
|
51
51
|
"@opentelemetry/context-async-hooks": "2.9.0",
|
|
52
52
|
"@opentelemetry/sdk-trace-base": "2.9.0",
|
|
53
53
|
"@types/bun": "^1.3.14"
|
package/src/agent-loop.ts
CHANGED
|
@@ -1117,7 +1117,11 @@ function resolveIntentMode(intent: AgentTool["intent"]): "require" | "optional"
|
|
|
1117
1117
|
return "require";
|
|
1118
1118
|
}
|
|
1119
1119
|
|
|
1120
|
-
|
|
1120
|
+
/** Split a traced call's intent (`i`, trimmed, trailing periods dropped) from the arguments its tool reads. */
|
|
1121
|
+
export function extractIntent(args: Record<string, unknown>): {
|
|
1122
|
+
intent?: string;
|
|
1123
|
+
strippedArgs: Record<string, unknown>;
|
|
1124
|
+
} {
|
|
1121
1125
|
const { [INTENT_FIELD]: intent, ...strippedArgs } = args;
|
|
1122
1126
|
if (typeof intent !== "string") {
|
|
1123
1127
|
return { strippedArgs };
|
|
@@ -2039,29 +2043,33 @@ async function prepareProviderCall(
|
|
|
2039
2043
|
const normalizedMessages = normalizeMessagesForProvider(llmMessages, model);
|
|
2040
2044
|
const ownedDialect: Dialect | undefined =
|
|
2041
2045
|
(config.getDialect ? config.getDialect(model) : config.dialect) ?? resolveOwnedDialectFromEnv(Bun.env.PI_DIALECT);
|
|
2042
|
-
const
|
|
2046
|
+
const toolOptions: NormalizeToolsOptions = {
|
|
2047
|
+
injectIntent: !!config.intentTracing,
|
|
2048
|
+
intentDescription: config.intentDescription,
|
|
2049
|
+
pruneDescriptions: !!config.pruneToolDescriptions && !ownedDialect,
|
|
2050
|
+
};
|
|
2043
2051
|
let llmContext: Context;
|
|
2044
2052
|
if (config.appendOnlyContext) {
|
|
2045
2053
|
config.appendOnlyContext.syncMessages(normalizedMessages);
|
|
2046
2054
|
llmContext = config.appendOnlyContext.build(context, {
|
|
2047
|
-
intentTracing:
|
|
2048
|
-
intentDescription:
|
|
2049
|
-
pruneToolDescriptions,
|
|
2055
|
+
intentTracing: toolOptions.injectIntent,
|
|
2056
|
+
intentDescription: toolOptions.intentDescription,
|
|
2057
|
+
pruneToolDescriptions: toolOptions.pruneDescriptions,
|
|
2050
2058
|
});
|
|
2051
2059
|
} else {
|
|
2052
2060
|
llmContext = {
|
|
2053
2061
|
systemPrompt: context.systemPrompt,
|
|
2054
2062
|
messages: normalizedMessages,
|
|
2055
|
-
tools: normalizeTools(context.tools,
|
|
2056
|
-
injectIntent: !!config.intentTracing,
|
|
2057
|
-
intentDescription: config.intentDescription,
|
|
2058
|
-
pruneDescriptions: pruneToolDescriptions,
|
|
2059
|
-
}),
|
|
2063
|
+
tools: normalizeTools(context.tools, toolOptions),
|
|
2060
2064
|
};
|
|
2061
2065
|
}
|
|
2062
2066
|
// Before the transform too, so a request-size clamp in it measures the withdrawn definitions the provider
|
|
2063
|
-
// re-declares; recomputed below against what the transform returns.
|
|
2064
|
-
|
|
2067
|
+
// re-declares; recomputed below against what the transform returns. Standby tools are normalized like
|
|
2068
|
+
// `tools`, so a standby tool's definition matches the one it is sent with once active.
|
|
2069
|
+
if (config.sentToolDefinitions) {
|
|
2070
|
+
const standbyTools = normalizeTools(context.standbyTools, toolOptions);
|
|
2071
|
+
llmContext = config.sentToolDefinitions.withInactiveTools(llmContext, standbyTools);
|
|
2072
|
+
}
|
|
2065
2073
|
if (config.transformProviderContext) {
|
|
2066
2074
|
llmContext = await config.transformProviderContext(llmContext, model);
|
|
2067
2075
|
}
|
|
@@ -2079,7 +2087,9 @@ async function prepareProviderCall(
|
|
|
2079
2087
|
// After `transformProviderContext`, so the recorded definitions are exactly what the provider receives.
|
|
2080
2088
|
if (config.sentToolDefinitions) {
|
|
2081
2089
|
if (llmContext.tools) config.sentToolDefinitions.record(llmContext.tools);
|
|
2082
|
-
llmContext
|
|
2090
|
+
if (llmContext.inactiveTools) config.sentToolDefinitions.record(llmContext.inactiveTools);
|
|
2091
|
+
// The transformed standby definitions, when no request has declared tools yet.
|
|
2092
|
+
llmContext = config.sentToolDefinitions.withInactiveTools(llmContext, llmContext.inactiveTools);
|
|
2083
2093
|
}
|
|
2084
2094
|
return { model, context: llmContext, promptToolWireTools, ownedDialect };
|
|
2085
2095
|
}
|
|
@@ -2973,10 +2983,11 @@ function resolveToolForCall(
|
|
|
2973
2983
|
return (
|
|
2974
2984
|
tools?.find(t => t.name === toolCall.name) ??
|
|
2975
2985
|
tools?.find(t => t.customWireName !== undefined && t.customWireName === toolCall.name) ??
|
|
2976
|
-
// Not in the advertised set: let the host route
|
|
2977
|
-
// (e.g.
|
|
2978
|
-
//
|
|
2979
|
-
// mid-stream roster change cannot widen what
|
|
2986
|
+
// Not in the advertised set: let the host route tools reached through a
|
|
2987
|
+
// side transport (e.g. mounted tool commands run through `bash`) called
|
|
2988
|
+
// by their top-level name. It receives the snapshot searched above, never
|
|
2989
|
+
// the agent's live tools, so a mid-stream roster change cannot widen what
|
|
2990
|
+
// this request can reach.
|
|
2980
2991
|
resolveFallbackTool?.(toolCall.name, tools ?? [])
|
|
2981
2992
|
);
|
|
2982
2993
|
}
|
|
@@ -2997,9 +3008,10 @@ const MAX_TOOL_NAME_SUGGESTIONS = 3;
|
|
|
2997
3008
|
* Both the last `__` and last `_` boundary are tried, so a name that lost only
|
|
2998
3009
|
* its separator (`…__resolve_library_id`) and one that lost a whole id segment
|
|
2999
3010
|
* (`…__read`) both recover. `fallbackNames` adds targets the host can route but
|
|
3000
|
-
* never advertises (
|
|
3001
|
-
*
|
|
3002
|
-
* in the session yet appears in no
|
|
3011
|
+
* never advertises (tools reached only as mounted tool commands through
|
|
3012
|
+
* `bash`); without them a corrupted command name is the one miss with nothing
|
|
3013
|
+
* to suggest, because the capability exists in the session yet appears in no
|
|
3014
|
+
* advertised name. Purely advisory: this only
|
|
3003
3015
|
* builds an error string and never selects a tool, so dispatch semantics are
|
|
3004
3016
|
* unchanged.
|
|
3005
3017
|
*/
|
|
@@ -3175,8 +3187,8 @@ async function prepareToolCallDispatch(
|
|
|
3175
3187
|
if (toolCall.type !== "toolCall") continue;
|
|
3176
3188
|
if ((toolCall as CursorExecResolvedCarrier)[kCursorExecResolved] === true) continue;
|
|
3177
3189
|
const tool = resolveToolForCall(context.tools, toolCall, resolveFallbackTool);
|
|
3178
|
-
// A host fallback accepts aliases (`
|
|
3179
|
-
//
|
|
3190
|
+
// A host fallback accepts aliases (`recal`, a mis-separated MCP name)
|
|
3191
|
+
// that providers reject when replayed as a function-call name.
|
|
3180
3192
|
// Record the call under the resolved tool's canonical name so history,
|
|
3181
3193
|
// persistence, and replay agree; custom-wire calls keep their wire name.
|
|
3182
3194
|
if (tool && toolCall.name !== tool.name && toolCall.name !== tool.customWireName) {
|
|
@@ -3721,9 +3733,9 @@ async function executeToolCalls(
|
|
|
3721
3733
|
// ride the loop-owned ToolCallContext (surfacing as
|
|
3722
3734
|
// `ctx.toolCall.*`); the host surfaces the sink on the context it
|
|
3723
3735
|
// builds, and the loop hands that object to the tool untouched.
|
|
3724
|
-
// Wrapper-dispatched nested calls (for example `
|
|
3725
|
-
// inherit the context, so their
|
|
3726
|
-
// root call at the batch boundary.
|
|
3736
|
+
// Wrapper-dispatched nested calls (for example a `bash` call
|
|
3737
|
+
// running a mounted tool command) inherit the context, so their
|
|
3738
|
+
// passive hook context joins this root call at the batch boundary.
|
|
3727
3739
|
const toolContext = getToolContext?.({
|
|
3728
3740
|
batchId,
|
|
3729
3741
|
index,
|
|
@@ -4016,9 +4028,9 @@ async function executeToolCalls(
|
|
|
4016
4028
|
|
|
4017
4029
|
// Skipped calls never ran. Hook-prepared context also requires a non-error
|
|
4018
4030
|
// final result; context the tool itself reported during execution stands.
|
|
4019
|
-
// Within a call, tool-reported context (including nested
|
|
4020
|
-
// precedes the hook's: wrappers release hook context only after
|
|
4021
|
-
// succeeds, so this is the one order every dispatch path can produce.
|
|
4031
|
+
// Within a call, tool-reported context (including nested tool command
|
|
4032
|
+
// dispatch) precedes the hook's: wrappers release hook context only after
|
|
4033
|
+
// the call succeeds, so this is the one order every dispatch path can produce.
|
|
4022
4034
|
const additionalContext = joinAdditionalContext(
|
|
4023
4035
|
records
|
|
4024
4036
|
.filter(record => !record.skipped)
|
package/src/agent.ts
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
agentLoopContinue,
|
|
34
34
|
createSyntheticToolResultMessage,
|
|
35
35
|
lastContextMessage,
|
|
36
|
+
type NormalizeToolsOptions,
|
|
36
37
|
normalizeMessagesForProvider,
|
|
37
38
|
normalizeTools,
|
|
38
39
|
resolveOwnedDialectFromEnv,
|
|
@@ -269,15 +270,15 @@ export interface AgentOptions {
|
|
|
269
270
|
|
|
270
271
|
/**
|
|
271
272
|
* Resolve a tool call whose name matched no advertised tool. Lets hosts
|
|
272
|
-
* route calls to tools
|
|
273
|
-
*
|
|
273
|
+
* route calls to tools reached through a side transport (e.g. mounted
|
|
274
|
+
* tool commands run through `bash`) instead of failing with "Tool not found".
|
|
274
275
|
*/
|
|
275
276
|
resolveFallbackTool?: (name: string, advertised: readonly AgentTool<any>[]) => AgentTool<any> | undefined;
|
|
276
277
|
|
|
277
278
|
/**
|
|
278
279
|
* Names routable by {@link resolveFallbackTool} that the advertised set
|
|
279
|
-
* omits (e.g.
|
|
280
|
-
* call misses.
|
|
280
|
+
* omits (e.g. mounted tool commands run through `bash`), used only to
|
|
281
|
+
* suggest a target when a call misses.
|
|
281
282
|
*/
|
|
282
283
|
suggestFallbackToolNames?: () => Iterable<string>;
|
|
283
284
|
|
|
@@ -432,6 +433,7 @@ export class Agent {
|
|
|
432
433
|
#transformContext?: (messages: AgentMessage[], signal?: AbortSignal) => Promise<AgentMessage[]>;
|
|
433
434
|
#transformProviderContext?: (context: Context, model: Model) => Context | Promise<Context>;
|
|
434
435
|
#sentToolDefinitions = new SentToolDefinitions();
|
|
436
|
+
#standbyTools: AgentTool[] = [];
|
|
435
437
|
#steeringQueue: AgentMessage[] = [];
|
|
436
438
|
#followUpQueue: AgentMessage[] = [];
|
|
437
439
|
#queuedMessageClaims: Partial<Record<QueuedMessageQueue, QueuedMessageClaim>> = {};
|
|
@@ -986,19 +988,19 @@ export class Agent {
|
|
|
986
988
|
if (!model) throw new Error("No active model on agent");
|
|
987
989
|
const ownedDialect = this.#ownedDialect(model);
|
|
988
990
|
const messages = normalizeMessagesForProvider(llmMessages, model);
|
|
989
|
-
const
|
|
990
|
-
|
|
991
|
-
:
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
991
|
+
const toolOptions: NormalizeToolsOptions = {
|
|
992
|
+
injectIntent: this.#intentTracing,
|
|
993
|
+
intentDescription: this.#intentDescription,
|
|
994
|
+
pruneDescriptions: this.#pruneToolDescriptions,
|
|
995
|
+
};
|
|
996
|
+
const tools = ownedDialect ? [] : (normalizeTools(this.#toolsForModel(model), toolOptions) ?? []);
|
|
997
|
+
const standby = ownedDialect ? undefined : normalizeTools(this.#standbyTools, toolOptions);
|
|
996
998
|
let context: Context = { systemPrompt, messages, tools };
|
|
997
999
|
// Side requests reuse the main loop's sent definitions without recording their own; attached before the
|
|
998
1000
|
// transform too, so a request-size clamp in it measures them.
|
|
999
|
-
context = this.#sentToolDefinitions.withInactiveTools(context);
|
|
1001
|
+
context = this.#sentToolDefinitions.withInactiveTools(context, standby);
|
|
1000
1002
|
if (this.#transformProviderContext) context = await this.#transformProviderContext(context, model);
|
|
1001
|
-
context = this.#sentToolDefinitions.withInactiveTools(context);
|
|
1003
|
+
context = this.#sentToolDefinitions.withInactiveTools(context, context.inactiveTools);
|
|
1002
1004
|
return context;
|
|
1003
1005
|
}
|
|
1004
1006
|
|
|
@@ -1367,6 +1369,11 @@ export class Agent {
|
|
|
1367
1369
|
this.#state.tools = t;
|
|
1368
1370
|
}
|
|
1369
1371
|
|
|
1372
|
+
/** Set the inactive tools that may become active later ({@link AgentContext.standbyTools}). */
|
|
1373
|
+
setStandbyTools(tools: AgentTool[]) {
|
|
1374
|
+
this.#standbyTools = tools;
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1370
1377
|
replaceMessages(ms: AgentMessage[]) {
|
|
1371
1378
|
// New array assignment is intentional: caller-owned `ms` may be mutated
|
|
1372
1379
|
// after handoff; snapshot it so external mutations cannot leak in.
|
|
@@ -1928,6 +1935,7 @@ export class Agent {
|
|
|
1928
1935
|
systemPrompt: this.#state.systemPrompt,
|
|
1929
1936
|
messages: this.#state.messages.slice(),
|
|
1930
1937
|
tools: this.#state.tools,
|
|
1938
|
+
standbyTools: this.#standbyTools,
|
|
1931
1939
|
};
|
|
1932
1940
|
|
|
1933
1941
|
// Installed unconditionally. Both `cursorExecHandlers` and
|
|
@@ -2058,6 +2066,7 @@ export class Agent {
|
|
|
2058
2066
|
context.systemPrompt = this.#state.systemPrompt;
|
|
2059
2067
|
this.#onModelCallSystemPrompt?.(context.systemPrompt);
|
|
2060
2068
|
context.tools = this.#toolsForModel(this.#state.model ?? model);
|
|
2069
|
+
context.standbyTools = this.#standbyTools;
|
|
2061
2070
|
},
|
|
2062
2071
|
beforeModelCall:
|
|
2063
2072
|
this.#beforeModelCall || this.#additionalBeforeModelCalls.size > 0
|
|
@@ -478,7 +478,6 @@ function buildCompactionV2Headers(
|
|
|
478
478
|
}
|
|
479
479
|
applyCodexResidencyHeader(headers, apiKey);
|
|
480
480
|
if (routingSessionId) {
|
|
481
|
-
headers[OPENAI_HEADERS.CONVERSATION_ID] = routingSessionId;
|
|
482
481
|
headers[OPENAI_HEADERS.SESSION_ID] = routingSessionId;
|
|
483
482
|
headers["x-client-request-id"] = routingSessionId;
|
|
484
483
|
}
|
|
@@ -26,16 +26,21 @@ export class SentToolDefinitions {
|
|
|
26
26
|
/**
|
|
27
27
|
* `context` with {@link Context.inactiveTools} set to the definitions for names the latest
|
|
28
28
|
* `requestControls.tools.declared` in its messages holds that are not in its `tools`; cleared when
|
|
29
|
-
* there are none or the request declares no tools.
|
|
30
|
-
*
|
|
29
|
+
* there are none or the request declares no tools. A declared name this Agent never sent takes its
|
|
30
|
+
* `standby` definition (a resumed transcript declares standby tools a fresh process has not sent);
|
|
31
|
+
* names with neither are skipped, and the provider drops them from the declaration. Before any
|
|
32
|
+
* request declared tools, `standby` (minus active names) stands in, so the first declaration
|
|
33
|
+
* already holds tools that may activate later.
|
|
31
34
|
*/
|
|
32
|
-
withInactiveTools(context: Context): Context {
|
|
33
|
-
const inactiveTools = context.tools?.length
|
|
35
|
+
withInactiveTools(context: Context, standby?: readonly Tool[]): Context {
|
|
36
|
+
const inactiveTools = context.tools?.length
|
|
37
|
+
? this.#inactiveFor(context.messages, context.tools, standby)
|
|
38
|
+
: undefined;
|
|
34
39
|
if (!inactiveTools && !context.inactiveTools) return context;
|
|
35
40
|
return { ...context, inactiveTools };
|
|
36
41
|
}
|
|
37
42
|
|
|
38
|
-
#inactiveFor(messages: readonly Message[], active: readonly Tool[]): Tool[] | undefined {
|
|
43
|
+
#inactiveFor(messages: readonly Message[], active: readonly Tool[], standby?: readonly Tool[]): Tool[] | undefined {
|
|
39
44
|
let declared: readonly string[] | undefined;
|
|
40
45
|
for (let index = messages.length - 1; index >= 0; index--) {
|
|
41
46
|
const message = messages[index];
|
|
@@ -44,13 +49,18 @@ export class SentToolDefinitions {
|
|
|
44
49
|
break;
|
|
45
50
|
}
|
|
46
51
|
}
|
|
47
|
-
if (!declared) return undefined;
|
|
48
52
|
const activeNames = new Set(active.map(tool => tool.name));
|
|
49
53
|
const inactive: Tool[] = [];
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
if (declared) {
|
|
55
|
+
for (const name of declared) {
|
|
56
|
+
if (activeNames.has(name)) continue;
|
|
57
|
+
const tool = this.#byName.get(name) ?? standby?.find(candidate => candidate.name === name);
|
|
58
|
+
if (tool) inactive.push(tool);
|
|
59
|
+
}
|
|
60
|
+
} else if (standby) {
|
|
61
|
+
for (const tool of standby) {
|
|
62
|
+
if (!activeNames.has(tool.name)) inactive.push(tool);
|
|
63
|
+
}
|
|
54
64
|
}
|
|
55
65
|
return inactive.length > 0 ? inactive : undefined;
|
|
56
66
|
}
|
package/src/tokenizer.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
isSameModelTurn,
|
|
14
14
|
shouldDropTruncatedThinkingOnlyAssistant,
|
|
15
15
|
} from "@oh-my-pi/pi-ai/providers/transform-messages";
|
|
16
|
+
import { replaysSignedReasoningText } from "@oh-my-pi/pi-ai/utils/reasoning-source";
|
|
16
17
|
import { resolveThinkingReplayTokens, type ThinkingReplayTokens } from "@oh-my-pi/pi-catalog/compat/thinking-replay";
|
|
17
18
|
import type { ModelTokenizer } from "@oh-my-pi/pi-catalog/types";
|
|
18
19
|
import * as natives from "@oh-my-pi/pi-natives";
|
|
@@ -569,8 +570,15 @@ export class Tokenizer {
|
|
|
569
570
|
continue;
|
|
570
571
|
}
|
|
571
572
|
if (this.#dropsOllamaThinking && ownOllamaTurn) continue;
|
|
572
|
-
// Chat-completions drops it unless LiteLLM replays it in `thinking_blocks
|
|
573
|
-
|
|
573
|
+
// Chat-completions drops it unless LiteLLM replays it in `thinking_blocks`
|
|
574
|
+
// or signed `reasoning_details` text replays with it.
|
|
575
|
+
if (
|
|
576
|
+
ownDroppedCompletionsTurn &&
|
|
577
|
+
!isLiteLLMThinkingSignature(block.thinkingSignature) &&
|
|
578
|
+
!replaysSignedReasoningText(block.thinkingSignature)
|
|
579
|
+
) {
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
574
582
|
if (this.#filtersReasoningHistory && this.#model !== undefined) {
|
|
575
583
|
// The demoted rendering is the visible text the request carries.
|
|
576
584
|
if (block.thinking.trim()) fragments.push(renderDemotedThinking(this.#model.id, block.thinking));
|
package/src/tool-arguments.ts
CHANGED
|
@@ -6,7 +6,8 @@ import type { AgentTool } from "./types";
|
|
|
6
6
|
* - `"parsed"`: a provider stream parsed the arguments, so `__parseError` is a
|
|
7
7
|
* genuine parse-failure sentinel and is never handed to a tool.
|
|
8
8
|
* - `"payload"`: the arguments are a payload the model wrote (eval tool bridge,
|
|
9
|
-
*
|
|
9
|
+
* a tool command line parsed into arguments), so those keys are forged and
|
|
10
|
+
* only stripped.
|
|
10
11
|
*/
|
|
11
12
|
export type ToolArgumentSource = "parsed" | "payload";
|
|
12
13
|
|
package/src/types.ts
CHANGED
|
@@ -145,8 +145,8 @@ export interface SoftToolRequirement {
|
|
|
145
145
|
/**
|
|
146
146
|
* Per-call compliance check: a turn satisfies the requirement only when every
|
|
147
147
|
* tool call passes. Defaults to `name === toolName`. Lets a host demand a
|
|
148
|
-
* specific invocation shape (e.g. `
|
|
149
|
-
* instead of any call to `toolName`. Escalation still forces `toolName`.
|
|
148
|
+
* specific invocation shape (e.g. a `bash` call running a particular tool
|
|
149
|
+
* command) instead of any call to `toolName`. Escalation still forces `toolName`.
|
|
150
150
|
*/
|
|
151
151
|
satisfies?(toolCall: { name: string; arguments?: Record<string, unknown> }): boolean;
|
|
152
152
|
/** Host-owned reminder messages, injected once per `id` activation. */
|
|
@@ -452,8 +452,8 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
|
|
|
452
452
|
/**
|
|
453
453
|
* Resolve a tool call whose name matched no advertised tool (including
|
|
454
454
|
* `customWireName` aliases). Lets hosts route calls to tools they expose
|
|
455
|
-
* through side
|
|
456
|
-
* with "Tool not found". Returning `undefined` keeps the failure.
|
|
455
|
+
* through a side transport (e.g. mounted tool commands run through `bash`)
|
|
456
|
+
* instead of failing with "Tool not found". Returning `undefined` keeps the failure.
|
|
457
457
|
*
|
|
458
458
|
* `advertised` is the very snapshot exact-name dispatch just searched — the
|
|
459
459
|
* set offered to THIS request. A host must resolve against it rather than
|
|
@@ -465,9 +465,9 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
|
|
|
465
465
|
resolveFallbackTool?: (name: string, advertised: readonly AgentTool<any>[]) => AgentTool<any> | undefined;
|
|
466
466
|
/**
|
|
467
467
|
* Names reachable through {@link resolveFallbackTool} but absent from the
|
|
468
|
-
* advertised set (e.g.
|
|
469
|
-
* plausible target when a call misses, so a mis-transcribed
|
|
470
|
-
* recoverable; never a dispatch source.
|
|
468
|
+
* advertised set (e.g. mounted tool commands run through `bash`). Consulted
|
|
469
|
+
* only to name a plausible target when a call misses, so a mis-transcribed
|
|
470
|
+
* command name is recoverable; never a dispatch source.
|
|
471
471
|
*/
|
|
472
472
|
suggestFallbackToolNames?: () => Iterable<string>;
|
|
473
473
|
|
|
@@ -1087,9 +1087,9 @@ export type ToolTier = "read" | "write" | "exec";
|
|
|
1087
1087
|
/**
|
|
1088
1088
|
* How an enabled tool is presented to the model. `"essential"` tools are exposed
|
|
1089
1089
|
* as normal top-level tools. `"discoverable"` tools are removed from the top-level
|
|
1090
|
-
* schema and either mounted
|
|
1091
|
-
* active) or surfaced through BM25 tool search — keeping their schemas
|
|
1092
|
-
* request. Selection (settings, `hidden`, `defaultInactive`, explicit `--tools`,
|
|
1090
|
+
* schema and either mounted as a tool command in the `bash` tool (when that
|
|
1091
|
+
* tool is active) or surfaced through BM25 tool search — keeping their schemas
|
|
1092
|
+
* off every request. Selection (settings, `hidden`, `defaultInactive`, explicit `--tools`,
|
|
1093
1093
|
* provider availability) decides whether a tool is enabled; `loadMode` only
|
|
1094
1094
|
* decides how an enabled tool is presented.
|
|
1095
1095
|
*/
|
|
@@ -1112,11 +1112,6 @@ export type ToolApprovalDecision =
|
|
|
1112
1112
|
reason?: string;
|
|
1113
1113
|
override?: boolean;
|
|
1114
1114
|
policy?: "allow" | "deny" | "prompt";
|
|
1115
|
-
/** User-policy key for this decision. When set, `tools.approval.<policyKey>`
|
|
1116
|
-
* is consulted instead of `tools.approval.<tool.name>`. Lets a dispatcher
|
|
1117
|
-
* tool (e.g. `write` for an `xd://` device call) scope user allow/deny/
|
|
1118
|
-
* prompt policies to the tool it dispatches into. */
|
|
1119
|
-
policyKey?: string;
|
|
1120
1115
|
};
|
|
1121
1116
|
export type ToolApproval = ToolApprovalDecision | ((args: unknown, context?: AgentToolContext) => ToolApprovalDecision);
|
|
1122
1117
|
|
|
@@ -1195,7 +1190,7 @@ export interface AgentTool<
|
|
|
1195
1190
|
readonly delegationGuidance?: string;
|
|
1196
1191
|
/**
|
|
1197
1192
|
* On-demand documentation topics (`topic → markdown`), readable as
|
|
1198
|
-
* `
|
|
1193
|
+
* `help://<tool>/<topic>`. Lets a tool keep large sub-surfaces out of its
|
|
1199
1194
|
* description and advertise only a one-line pointer per topic.
|
|
1200
1195
|
*/
|
|
1201
1196
|
docTopics?(): Readonly<Record<string, string>>;
|
|
@@ -1318,6 +1313,12 @@ export interface AgentContext {
|
|
|
1318
1313
|
systemPrompt: string[];
|
|
1319
1314
|
messages: AgentMessage[];
|
|
1320
1315
|
tools?: AgentTool<any>[];
|
|
1316
|
+
/**
|
|
1317
|
+
* Inactive tools that may become active later in the conversation. A provider that announces tool changes
|
|
1318
|
+
* in-band (Anthropic `tool_addition`) declares them from the first request, so activating one leaves the
|
|
1319
|
+
* cached prefix intact. See {@link SentToolDefinitions.withInactiveTools}.
|
|
1320
|
+
*/
|
|
1321
|
+
standbyTools?: AgentTool<any>[];
|
|
1321
1322
|
}
|
|
1322
1323
|
|
|
1323
1324
|
/**
|