Skip to content

Improvement: knowledge search and image generation exist twice, once for chat and shared-engine task runs and once for the harness bridge #4875

Open

Description

@yannickmonney

Summary

Two implementations of the same capabilities serve the two ways an agent can work:

  • the in-process engine, for chat replies and task runs on the shared engine: createChatToolExecutor for knowledge, backend/domains/agent_tools/* for files, skills, code and images;
  • the harness bridge, for coding agents in a full workspace (the MCP workspace_tool over /api/tools/execute): backend/core/node_only/sandbox/workspace_*.ts for knowledge, images, tasks, documents and more.

They share the leaf pieces (searchKnowledge, fetchWebPageByUrl, the image provider core, wrapUntrusted) but not the tool layer. Argument handling, authority checks, limits, billing and result shape are written twice, and the two have already drifted. This issue collects the evidence and the options for sharing more code between chats and tasks. It proposes no design.

Part of #4879.

Where the code is

Line counts at main a83e645e27.

Engine Harness bridge
knowledge tools backend/core/chat/assistant_tools.ts (2,633 lines): rag_search, rag_fetch, web_fetch workspace_tools_bridge.ts (1,319): rag_search, rag_fetch, document_find and the other finders (runKnowledgeTool, :998)
image tool agent_tools/image.ts (276), image-billing.ts (179), image-model.ts (47) workspace_image_tool.ts (804) and backend/domains/sandbox/image-generation.ts (553)
other tools create_file, load_skill, read_skill_file, run_code, use_workspace (agent_tools/, 1,938 lines in all) the 10 task tools, document_create, knowledge_entry_write, ask_human (workspace_domain_tools.ts, 2,044; workspace_knowledge_tools.ts, 200)
names CHAT_TOOL_NAMES (3, lib/chat/tools.ts:31), WORK_TOOL_NAMES (6, lib/agent/work-tools.ts:22) ALL_WORKSPACE_TOOLS (workspace_tools_bridge.ts:91), AGENT_TOOL_CATALOG (17 grantable names, packages/shared/src/agent-tool-grants.ts:18)
composed in executeTurn (backend/core/chat/turn_action.ts:1456, :1494) dispatchWorkspaceToolImpl (workspace_tools_bridge.ts:508)

Where the copies already differ

From reading the code at main a83e645e27, not from comparing behavior at runtime.

Engine Bridge
arguments of rag_search action (search or list), query, kind, status, projectId, limit, cursor (lib/chat/tools.ts) query, limit (workspace_tools_bridge.ts:151)
total size of reference images for generate_image 16 MiB (agent_tools/image.ts:45) 20 MiB (workspace_image_tool.ts:90)
images one turn may create TURN_MAX_GENERATED_IMAGES = 16 (image-billing.ts:37) SANDBOX_TURN_MAX_GENERATED_IMAGES = 16 (backend/core/sandbox/session_constants.ts:68): the same number, defined twice
parallel image calls allowed up to the ceiling; a race in this path let ten parallel calls of four images pass it (fixed in #4849) one generation in flight per turn (workspace_image_tool.ts:21)
a retried identical call deduplicated within one step only attaches to the first call's result for 10 minutes (REPEAT_WINDOW_MS, workspace_image_tool.ts:100)
a policy changed mid-turn the image model is resolved when the turn starts the policy is re-read at every call (workspace_image_tool.ts:18-19: "stops the next call, not the next turn")
where the spend is held the turn's generation row (app.generations.reserved_cost_cents) the session's op row (app.sandbox_session_ops)
result shape a flat object: {status: 'ok', images, artifacts, …} or {status, message} ToolResult: {status: 'ok', output}, {status: 'unavailable', blockers}, {status, message} (workspace_tool_shared.ts)
authority a person: the chat's user or the run's starter (WorkToolScope) the session's binding or the starter: WorkspaceActionAuthority (actorId, scope, confinedToTaskId)

One comment already contradicts the code: backend/core/sandbox/tool_names.ts:55 says generate_image is "never" granted "to chat", which has not been true since #4817.

What only the bridge has

Task tools (create, comment, status, metadata, review, delegate review, start agent, upsert by external ref), document_create, knowledge_entry_find and _write, contact_find, product_find, website_find and ask_human. A task run on the shared engine can read tasks, projects and documents through rag_search but has no tool to write any of them (the host writes the run's report and deliverables when it settles); an agent in a worker can, when granted.

Constraints any change has to respect

  • Transport and timing. A bridge call is request and response over HTTP from inside a sandbox, from an MCP client that may time out and retry (hence the 10-minute idempotency window). Engine tools run in process inside a supervised batch (lib/chat/tool-batch.ts: 16 calls, 5 minutes, Stop).
  • Authority. A bridge call proves a session and a turn by token and resolves its authority from the session's binding; a member's run is confined to its task. The engine acts for a person.
  • Names are data. AGENT_TOOL_CATALOG names are stored in agents' equipment and in managed configuration (packages/shared/src/schemas/managed-configuration.ts:44). About 35 source files and 13 documentation files name tools only the bridge has.
  • Rolling upgrades. The platform and the sandbox runtime roll separately, and agents read the MCP tool descriptions inside running sessions.
  • Different ledgers. The bridge books against a harness turn's op row, the engine against the turn's generation row.

Options (not exhaustive, no preference stated)

  1. One executor per capability, two thin transports. The bridge's handlers call the engine's executor with an authority built from the session. The engine's ports in agent_tools/scope.ts (ArtifactSink, InputFiles, ImageBilling, Escalation) already separate "where files go", "which files may be read", "who pays" and "what a hand-over does" from the tool.
  2. Share the leaf pieces only. Limits and constants in one module, admission and booking behind one interface; keep two tool layers and pin the contract with one conformance suite run against both.
  3. Make the bridge a pass-through to the engine's executors over HTTP, so the harness calls the same code in the platform.
  4. Leave it. List the intended differences (one generation in flight, 10-minute idempotency, op-row billing), fix the stale comment, and add a test that fails when the shared constants diverge.

Questions

  • Which differences are intentional? One generation in flight per turn, and the 16 and 20 MiB limits, look like candidates either way.
  • Should the harness get the engine's work tools (create_file, skills) or keep its shell and staged skills?
  • Is the unit of sharing the executor, or the capability's contract (schema, limits, result shape)?

Related

#4844 (task runs on the shared engine), #4849, #4876 (a wider engine needs the tools the bridge provides), #4878.

Observed at main a83e645e27.

Activity

  1. added
    needs discussion
    improvement
    service: platform
    on Oct 12, 2026
  2. yannickmonney commented on Nov 14, 2026

    @yannickmonney
    ContributorAuthor

    Decision

    Rule: one executor per capability, two thin transports (option 1), done one capability at a time. rag_search, rag_fetch and generate_image each get a single executor that does not care which transport calls it. The executor owns the contract: argument parsing, limits, a fixed order of admission steps, untrusted-content wrapping, which kinds and subjects a caller may reach, and a result union tied to neither wire format. It talks to the outside through ports, building on agent_tools/scope.ts:

    • Knowledge: a RetrievalScope port. Its work access carries task confinement and project limits.
    • Images: ReferenceImageSource, ImageOutput, ImageBilling, and an ImageModelSource that is re-read on every call.

    The engine and the harness bridge remain adapters. Each one builds its own authority, maps results to the wire shape it already uses, and keeps its transport-specific behaviour. Tool names do not change.

    Answers

    • Which differences are intentional?
      • Intentional, bridge only: one generation in flight per turn, the 10-minute repeat window for an identical call, and billing on the op row. They are written into the sandbox spec.
      • Drift, now fixed:
        • 16 vs 20 MiB: 4 references x 4 MiB already caps a call at 16 MiB, so both lanes use 16.
        • The ceiling of 16 images: now one constant.
        • Policy read at turn start vs on every call: both lanes re-read on every call.
        • The bridge's narrow rag_search arguments: the bridge accepts the engine's arguments, limited by grant and role on every path.
    • Should the harness get create_file and skills? No. It keeps its shell and staged skills. web_fetch stays engine-only.
    • Is the unit of sharing the executor or the contract? The executor, with the contract inside it. Each capability has one conformance table that runs against both adapters.

    Rationale

    The two copies have already drifted on security-relevant behaviour (#4849), and a single executor means each such bug is fixed once.

    Because the shared executor is richer than today's bridge code, it gates every path, not only search and list. Kinds and role subjects also apply to rag_fetch's project:, task: and msg: refs. A harness agent therefore reaches only documents and crawled pages, plus the kinds its find tools grant. It never reaches mail, and a confined member run never reaches another task.

    The image executor's step order is written down so that the synchronous ceiling reserve from #4849 survives the new per-call policy read.

    Wire shapes and tool names stay as they are, so nothing stored or running breaks.

    The rejected options:

    • Sharing leaf pieces only: keeps two layers that drift.
    • An HTTP pass-through: adds a hop and buys nothing.
    • Leaving it as is: treats the symptoms only.

    Implementation units (base: main)

    1. Shared image limits (S). One module. The bridge's reference total becomes 16 MiB. Fix the stale tool_names.ts comment. A sandbox spec rule lists the intentional differences.
    2. Extract the knowledge executor (M). Kind, subject and confinement gating on search, list and every fetch ref form. No change to engine behaviour.
    3. Bridge on the shared knowledge executor (L). Kinds limited to grants (task_find also gives projects; mail and conversations never). Role checks per kind. Confinement for task listing and fetch. Old {query, limit} calls still work. A conformance table runs against both adapters, and the docs are updated in EN, DE and FR. Depends on 2.
    4. Image executor on ports (M). A fixed step order, the per-call policy re-read on the engine, a new CHAT rule and a test. Depends on 1.
    5. Bridge generate_image on the shared executor (M). Single flight and the repeat window stay in the adapter, and a conformance table covers both adapters. Depends on 4.

    The bridge-only tools are not part of this change. If they come to the engine (#4876), they follow the same pattern.

    Cross-issue amendments (decisions taken together with #4879):

  3. added
    agent-ready
    and removed
    needs discussion
    on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyimprovementservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions