operon-agents-core 0.1.0-alpha.14 → 0.1.0-alpha.15

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.
@@ -653,7 +653,6 @@ class Engine {
653
653
  tools: toolset.tools,
654
654
  deferredToolNames: toolset.deferredToolNames,
655
655
  deferEnabled: toolset.deferEnabled,
656
- serverToolSearch: toolset.serverToolSearch,
657
656
  onToolsPrepared: (tools) => { permissionTools = tools; },
658
657
  refreshTools: () => buildRunTools(current, state, (agent, childContext, childState, childResume) => this.run(agent, childContext, childState, childResume), model),
659
658
  hooks,
@@ -20,8 +20,6 @@ export interface RunToolset {
20
20
  readonly tools: readonly Tool[];
21
21
  readonly deferredToolNames: ReadonlySet<string>;
22
22
  readonly deferEnabled: boolean;
23
- /** The provider runs tool search itself (`ChatModel.serverToolSearch`); no SearchTool. */
24
- readonly serverToolSearch: boolean;
25
23
  }
26
24
  export declare function buildRunTools<TContext>(active: Agent<TContext>, state: RunState<TContext>, runAgent: RunAgentFn<TContext>, model: ChatModel): Promise<RunToolset>;
27
25
  //# sourceMappingURL=toolset.d.ts.map
@@ -31,8 +31,7 @@ export async function buildRunTools(active, state, runAgent, model) {
31
31
  return false;
32
32
  });
33
33
  const deferEnabled = active.deferTools !== false && model.supportsDeferredTools;
34
- const serverToolSearch = active.deferTools !== false && !deferEnabled && model.serverToolSearch;
35
- const deferredToolNames = new Set(deferEnabled || serverToolSearch ? capTools.map((tool) => tool.schema.name) : []);
34
+ const deferredToolNames = new Set(deferEnabled ? capTools.map((tool) => tool.schema.name) : []);
36
35
  const tools = [...active.tools, ...capTools];
37
36
  if (deferEnabled)
38
37
  tools.push(buildSearchTool(capTools.map((t) => t.schema)));
@@ -42,7 +41,7 @@ export async function buildRunTools(active, state, runAgent, model) {
42
41
  // (e.g. profile-loaded agents). The unified "Agent" tool spawns/resumes by type.
43
42
  const providerAgents = state.subagentProvider !== undefined ? [...(await state.subagentProvider.list())] : [];
44
43
  if (active.subagents.length === 0 && providerAgents.length === 0) {
45
- return finish(state, tools, deferredToolNames, deferEnabled, serverToolSearch);
44
+ return finish(state, tools, deferredToolNames, deferEnabled);
46
45
  }
47
46
  // One spawner (the engine seam) shared by every subagent-spawning tool: the static
48
47
  // `agent_<name>` tools, the unified `Agent` tool, and `Workflow`.
@@ -57,27 +56,26 @@ export async function buildRunTools(active, state, runAgent, model) {
57
56
  if (state.workflowTool !== false && !tools.some((tool) => tool.schema.name === "Workflow")) {
58
57
  tools.push(buildWorkflowTool(spawner, state));
59
58
  }
60
- return finish(state, tools, deferredToolNames, deferEnabled, serverToolSearch);
59
+ return finish(state, tools, deferredToolNames, deferEnabled);
61
60
  }
62
61
  /**
63
62
  * Last stop before the turn: let capabilities narrow the complete registry (the extension
64
63
  * runtime's `setActiveTools` rides this). Filtering happens AFTER assembly so a filter sees
65
64
  * handoff and subagent tools too, and the deferred-name set is pruned to whatever survived.
66
65
  */
67
- function finish(state, tools, deferredToolNames, deferEnabled, serverToolSearch) {
66
+ function finish(state, tools, deferredToolNames, deferEnabled) {
68
67
  const filtered = state.capabilities.applyToolFilters(tools, {
69
68
  address: state.address,
70
69
  isRootAgent: state.address === DEFAULT_ADDRESS,
71
70
  });
72
71
  const enabled = deferEnabled && filtered.some((tool) => tool.schema.name === "SearchTool");
73
72
  if (filtered === tools)
74
- return { tools, deferredToolNames, deferEnabled: enabled, serverToolSearch };
73
+ return { tools, deferredToolNames, deferEnabled: enabled };
75
74
  const surviving = new Set(filtered.map((tool) => tool.schema.name));
76
75
  return {
77
76
  tools: filtered,
78
- deferredToolNames: new Set(enabled || serverToolSearch ? [...deferredToolNames].filter((name) => surviving.has(name)) : []),
77
+ deferredToolNames: new Set(enabled ? [...deferredToolNames].filter((name) => surviving.has(name)) : []),
79
78
  deferEnabled: enabled,
80
- serverToolSearch,
81
79
  };
82
80
  }
83
81
  /**
@@ -89,9 +89,6 @@ export declare class ChatModel {
89
89
  readonly maxOutputTokens: number;
90
90
  /** Loading a deferred tool mid-conversation keeps the request prefix: SearchTool mode. */
91
91
  readonly supportsDeferredTools: boolean;
92
- /** The provider searches deferred tools itself (OpenRouter's `openrouter:tool_search`).
93
- * Used only where `supportsDeferredTools` is false. */
94
- readonly serverToolSearch: boolean;
95
92
  private readonly piModel;
96
93
  private readonly runtime;
97
94
  /** Build-time settings (`apiKey` + `connection`) flattened once into pi's option shape.
@@ -2,7 +2,6 @@ import { createAssistantMessageEventStream } from "@earendil-works/pi-ai";
2
2
  import { emptyUsage } from "../loop/usage.js";
3
3
  import { createModelRuntime, forceRefreshOAuth, } from "./runtime.js";
4
4
  import { classifyError } from "./errors.js";
5
- import { supportsOpenRouterToolSearch, withOpenRouterToolSearch } from "./openrouter-tool-search.js";
6
5
  export class ChatModel {
7
6
  id;
8
7
  provider;
@@ -14,9 +13,6 @@ export class ChatModel {
14
13
  maxOutputTokens;
15
14
  /** Loading a deferred tool mid-conversation keeps the request prefix: SearchTool mode. */
16
15
  supportsDeferredTools;
17
- /** The provider searches deferred tools itself (OpenRouter's `openrouter:tool_search`).
18
- * Used only where `supportsDeferredTools` is false. */
19
- serverToolSearch;
20
16
  piModel;
21
17
  runtime;
22
18
  /** Build-time settings (`apiKey` + `connection`) flattened once into pi's option shape.
@@ -35,7 +31,6 @@ export class ChatModel {
35
31
  this.contextWindow = this.piModel.contextWindow;
36
32
  this.maxOutputTokens = this.piModel.maxTokens;
37
33
  this.supportsDeferredTools = supportsNativeDeferredTools(this.piModel);
38
- this.serverToolSearch = supportsOpenRouterToolSearch(this.piModel);
39
34
  }
40
35
  stream(req, call) {
41
36
  const ctx = toContext(req);
@@ -67,11 +62,7 @@ export class ChatModel {
67
62
  }
68
63
  }
69
64
  options(req, call) {
70
- const options = toOptions(req, call, this.requestDefaults);
71
- const deferred = this.serverToolSearch
72
- ? new Set((req.tools ?? []).filter((tool) => tool.deferLoading === true).map((tool) => tool.name))
73
- : undefined;
74
- return deferred !== undefined && deferred.size > 0 ? withOpenRouterToolSearch(options, deferred) : options;
65
+ return toOptions(req, call, this.requestDefaults);
75
66
  }
76
67
  async streamWithAuthRetry(req, call, ctx, out) {
77
68
  const first = await this.runAttempt(req, call, ctx, out);
@@ -34,7 +34,6 @@ export interface RunTurnInput {
34
34
  /** Capability tools hidden until transcript load/use evidence activates them. */
35
35
  readonly deferredToolNames?: ReadonlySet<string>;
36
36
  readonly deferEnabled?: boolean;
37
- readonly serverToolSearch?: boolean;
38
37
  /** Snapshot after beforeStep, so a connection completed during a turn is seen next step. */
39
38
  readonly refreshTools?: () => Promise<ToolCatalogSnapshot>;
40
39
  readonly onToolsPrepared?: (tools: readonly Tool[]) => void;
@@ -30,7 +30,7 @@ export async function runTurn(input) {
30
30
  try {
31
31
  // HITL resume — re-run the interrupted batch with pre-loaded answers first.
32
32
  if (input.resumeFrom) {
33
- const resumeSnapshot = input.refreshTools ? await input.refreshTools() : { tools: toolList, deferredToolNames, deferEnabled: input.deferEnabled, serverToolSearch: input.serverToolSearch };
33
+ const resumeSnapshot = input.refreshTools ? await input.refreshTools() : { tools: toolList, deferredToolNames, deferEnabled: input.deferEnabled };
34
34
  const resumePrepared = prepareToolCatalog(input.context, resumeSnapshot, { announce: false });
35
35
  const resumeTools = resumePrepared.tools;
36
36
  input.onToolsPrepared?.(resumeTools);
@@ -87,7 +87,6 @@ export async function runTurn(input) {
87
87
  tools: toolList,
88
88
  deferredToolNames,
89
89
  deferEnabled: input.deferEnabled,
90
- serverToolSearch: input.serverToolSearch,
91
90
  refreshTools: input.refreshTools,
92
91
  onToolsPrepared: input.onToolsPrepared,
93
92
  hooks: input.hooks,
@@ -40,7 +40,6 @@ export interface ExecuteStepDeps {
40
40
  readonly tools: readonly Tool[];
41
41
  readonly deferredToolNames: ReadonlySet<string>;
42
42
  readonly deferEnabled?: boolean;
43
- readonly serverToolSearch?: boolean;
44
43
  readonly refreshTools?: () => Promise<ToolCatalogSnapshot>;
45
44
  readonly onToolsPrepared?: (tools: readonly Tool[]) => void;
46
45
  readonly hooks?: LoopHooks;
@@ -2,10 +2,5 @@ export interface ToolSchema {
2
2
  readonly name: string;
3
3
  readonly description: string;
4
4
  readonly parameters: Readonly<Record<string, unknown>>;
5
- /**
6
- * Withheld by the provider until its own server-side tool search reveals it
7
- * (`ChatModel.serverToolSearch`). Only the request's top-level list carries it.
8
- */
9
- readonly deferLoading?: boolean;
10
5
  }
11
6
  //# sourceMappingURL=tool-schema.d.ts.map
@@ -7,9 +7,6 @@ export interface ToolCatalogSnapshot {
7
7
  readonly tools: readonly Tool[];
8
8
  readonly deferredToolNames: ReadonlySet<string>;
9
9
  readonly deferEnabled?: boolean;
10
- /** The provider searches `deferredToolNames` itself: every tool executes and is sent,
11
- * the deferred ones marked `deferLoading`. Exclusive with `deferEnabled`. */
12
- readonly serverToolSearch?: boolean;
13
10
  }
14
11
  export interface PreparedToolCatalog {
15
12
  /** Only presently available, loaded tools can execute. */
@@ -62,13 +62,6 @@ function announcementText(input) {
62
62
  /** Called after beforeStep/compaction, once per model request, never during a tool batch. */
63
63
  export function prepareToolCatalog(context, snapshot, options = {}) {
64
64
  const enabled = snapshot.deferEnabled ?? snapshot.deferredToolNames.size > 0;
65
- if (snapshot.serverToolSearch === true) {
66
- const all = snapshot.tools.map((tool) => tool.schema);
67
- const requestTools = all.map((schema) => snapshot.deferredToolNames.has(schema.name) ? { ...schema, deferLoading: true } : schema);
68
- // The provider keeps the deferred definitions out of the prompt: they cost no context.
69
- const schemas = all.filter((schema) => !snapshot.deferredToolNames.has(schema.name));
70
- return { tools: snapshot.tools, schemas, requestTools, loaded: new Map(), catalog: new Map(), deferEnabled: false, warnings: [] };
71
- }
72
65
  if (!enabled) {
73
66
  const schemas = snapshot.tools.map((tool) => tool.schema);
74
67
  return { tools: snapshot.tools, schemas, requestTools: schemas, loaded: new Map(), catalog: new Map(), deferEnabled: false, warnings: [] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "operon-agents-core",
3
- "version": "0.1.0-alpha.14",
3
+ "version": "0.1.0-alpha.15",
4
4
  "description": "Internal engine for operon-agents. Prefer operon-agents for application code.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -1,25 +0,0 @@
1
- import type { Model, ModelsSimpleStreamOptions } from "@earendil-works/pi-ai";
2
- import type { Api } from "../protocol/index.ts";
3
- /**
4
- * OpenRouter's server-side tool search. Every deferred function tool is sent with
5
- * `defer_loading: true` next to `{ type: "openrouter:tool_search" }`; OpenRouter withholds
6
- * those definitions from the upstream prompt and lets the model regex-search them, on any
7
- * model. Measured on deepseek-v4-flash (2026-09-29): 31 tools 14.8k → 6.1k input tokens,
8
- * and adding a deferred tool mid-conversation keeps the cached prefix. What the search
9
- * revealed need not be replayed: a stripped history still calls the discovered tool.
10
- *
11
- * Responses API only — OpenRouter rejects it on Chat Completions (400), and its Messages
12
- * API is reached here only by Claude models, which take the native `tool_addition` path.
13
- */
14
- export declare const OPENROUTER_TOOL_SEARCH = "openrouter:tool_search";
15
- /**
16
- * Tools one search may reveal. OpenRouter's default is 5 (cap 50), and a model reads a
17
- * truncated page as the whole catalog: asked for Linear with 157 deferred tools, it got the
18
- * five attachment tools back and concluded `list_issues` did not exist. 20 covers a typical
19
- * MCP server's matches; a revealed tool costs input tokens only once it is found.
20
- */
21
- export declare const OPENROUTER_TOOL_SEARCH_MAX_RESULTS = 20;
22
- export declare function supportsOpenRouterToolSearch(model: Model<Api>): boolean;
23
- /** Mark `deferred` function tools and add the search tool at pi's public payload seam. */
24
- export declare function withOpenRouterToolSearch(options: ModelsSimpleStreamOptions, deferred: ReadonlySet<string>): ModelsSimpleStreamOptions;
25
- //# sourceMappingURL=openrouter-tool-search.d.ts.map
@@ -1,58 +0,0 @@
1
- /**
2
- * OpenRouter's server-side tool search. Every deferred function tool is sent with
3
- * `defer_loading: true` next to `{ type: "openrouter:tool_search" }`; OpenRouter withholds
4
- * those definitions from the upstream prompt and lets the model regex-search them, on any
5
- * model. Measured on deepseek-v4-flash (2026-09-29): 31 tools 14.8k → 6.1k input tokens,
6
- * and adding a deferred tool mid-conversation keeps the cached prefix. What the search
7
- * revealed need not be replayed: a stripped history still calls the discovered tool.
8
- *
9
- * Responses API only — OpenRouter rejects it on Chat Completions (400), and its Messages
10
- * API is reached here only by Claude models, which take the native `tool_addition` path.
11
- */
12
- export const OPENROUTER_TOOL_SEARCH = "openrouter:tool_search";
13
- /**
14
- * Tools one search may reveal. OpenRouter's default is 5 (cap 50), and a model reads a
15
- * truncated page as the whole catalog: asked for Linear with 157 deferred tools, it got the
16
- * five attachment tools back and concluded `list_issues` did not exist. 20 covers a typical
17
- * MCP server's matches; a revealed tool costs input tokens only once it is found.
18
- */
19
- export const OPENROUTER_TOOL_SEARCH_MAX_RESULTS = 20;
20
- export function supportsOpenRouterToolSearch(model) {
21
- return model.api === "openai-responses" && isOpenRouter(model.baseUrl);
22
- }
23
- function isOpenRouter(baseUrl) {
24
- try {
25
- const host = new URL(baseUrl).hostname;
26
- return host === "openrouter.ai" || host.endsWith(".openrouter.ai");
27
- }
28
- catch {
29
- return false;
30
- }
31
- }
32
- /** Mark `deferred` function tools and add the search tool at pi's public payload seam. */
33
- export function withOpenRouterToolSearch(options, deferred) {
34
- const inspect = options.onPayload;
35
- return {
36
- ...options,
37
- onPayload: async (payload, model) => {
38
- let next = payload;
39
- if (payload !== null && typeof payload === "object" && "tools" in payload && Array.isArray(payload.tools)) {
40
- let marked = false;
41
- const tools = payload.tools.map((tool) => {
42
- if (tool === null || typeof tool !== "object" || !("name" in tool) || typeof tool.name !== "string")
43
- return tool;
44
- if (!deferred.has(tool.name))
45
- return tool;
46
- marked = true;
47
- return { ...tool, defer_loading: true };
48
- });
49
- // OpenRouter rejects a deferred tool without the search tool, and the search tool
50
- // with nothing to search is only noise.
51
- if (marked)
52
- next = { ...payload, tools: [{ type: OPENROUTER_TOOL_SEARCH, parameters: { max_results: OPENROUTER_TOOL_SEARCH_MAX_RESULTS } }, ...tools] };
53
- }
54
- return (await inspect?.(next, model)) ?? next;
55
- },
56
- };
57
- }
58
- //# sourceMappingURL=openrouter-tool-search.js.map