Skip to content

feat(platform): let external agents call granted workspace tools - #2585

Merged
larryro merged 7 commits into
mainfrom
feat/external-agent-workspace-tools
Jul 8, 2026
Merged

larryro merged 7 commits into
mainfrom
feat/external-agent-workspace-tools

Conversation

@larryro

@larryro larryro commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

External agents (Claude Code & co. in the sandbox) can now carry toolNames like normal agents and call those platform tools from inside their container. The schema unlocks a curated, request/response-only subset (EXTERNAL_AGENT_TOOL_NAMES: rag_search, document_find, document_retrieve, document_write); the grant set plus the execution context (agent/thread/user) ride the session token's scope; a new POST /api/tools/execute|status dispatch reuses the integration bridge's auth and invokes the loop's own registry tool implementations with a synthesized ToolCtx — so tool-internal authorization, untrusted-content handling, and document_write's approval card apply unchanged. The sandbox bridge (tale-integrations-mcp) gains generic workspace_tool / workspace_status tools with zero adapter changes (the tools URL derives from TALE_INTEGRATIONS_URL). The Tools tab shows the existing platform-tools picker for external agents, filtered to the subset.

Design decisions (settled in design discussion):

  • Presented as "Tools", not a first-party integration — same concept users already know from normal agents; the integration rails are reused only as mechanism.
  • No migration — the schema change is a data-safe relaxation (migrations:check green); existing configs stay valid and admins opt in per agent by editing the agent config.
  • BYO agents excluded — no session key ⇒ no bridge, same posture as the integration dispatch.
  • Loop-coupled tools (request_human_input, spawn_agent, file_*, run_code, …) stay excluded: the coding agent has native file/shell tools, and interactive tools can't run outside the platform loop. A drift test pins the subset against the registry markings (sandboxBridge: true).

Checklist

  • bun run check passes (format, lint, typecheck, all tests). — Constituents verified individually in the dev env: oxfmt clean (6,767 files), turbo lint+typecheck 20/20, full platform suite 726 files / 75,099 tests green, docs/ui/web/shared suites green. The composite command itself dies early in this dev env at uvx (ruff) being uninstalled; the diff contains no Python files. CI should confirm.
  • bun run lint:sast passes (Opengrep) — 467 rules, 0 findings (plus per-commit hook scans, 0 findings).
  • Translations updated in services/platform/messages/{en,de,fr}.json — settings.agents.form.sectionToolsExternalDescription rewritten in all three.
  • Docs updated in docs/{en,de,fr}/ — platform/agents/external-agent.md gains the workspace-tools paragraph, written natively per locale; tests/manual/agents.md F17 expectation extended.
  • README.md / README.de.md / README.fr.md updated — N/A: no env var, setup, or top-level capability list change; the feature is documented on the external-agent docs page.

Test plan

Unit/static (all run in this branch):

  • bun run --cwd services/platform typecheck and bun run --cwd services/platform test — includes the new schema cases (lib/shared/schemas/agents.test.ts), the subset drift guard (convex/agent_tools/sandbox_bridge.test.ts), and the untouched suites of the four bridged tools.
  • bun run --cwd services/platform migrations:check — proves the schema change is data-safe (no migration).

End-to-end (needs a real deployment + sandbox — not observed in the dev sandbox used to author this, please verify):

  1. On a managed Claude Code agent, open Tools and tick rag_search + document_write (picker now shows only the four workspace tools for external agents).
  2. In a chat with that agent, ask it to search the org knowledge base — expect a workspace_tool call with rag_search results (agent-scoped, same allow-list as a loop turn).
  3. Ask it to save a summary to the documents hub — expect status: requires_approval relayed by the agent, an approval card in the chat, and the write landing in the hub after approval.
  4. Un-tick the tools and repeat — expect workspace_status to report nothing granted and workspace_tool to return unavailable (schema also rejects non-subset names at config save).

Notes for review

  • Riskiest surface first: convex/agent_tools/dispatch_http.ts — bearer auth (convex/sandbox/dispatch_auth.ts, extracted unchanged from the integration dispatch), grant gates, zod re-validation at the boundary, and the {...tool, ctx} invocation (the SDK's own wrapTools contract; getCtx(this) reads this.ctx).
  • Workspace-tool results are deliberately not blanket-wrapped as untrusted (unlike integration results): the loop tools carry their own trust calculus (e.g. rag_search wraps video-link transcripts, strips reserved tags). Rationale in the file header.
  • convex/_generated/api.d.ts entries for the three new modules were added by hand in the generator's exact format (no CONVEX_DEPLOYMENT in the authoring env); the next convex dev regenerates identically.
  • The test(platform) commit fixes a genuine wedge the first drift-guard version introduced: a vi.mock factory returning a get-anything Proxy is an unsettleable thenable to vitest (factories are awaited) and stalled the whole suite at 0% CPU.

@larryro
larryro force-pushed the feat/external-agent-workspace-tools branch from 681ff48 to 1c660bd Compare July 8, 2026 11:45
@larryro
larryro force-pushed the feat/external-agent-workspace-tools branch from 1c660bd to a25a968 Compare July 8, 2026 12:12
larryro added a commit that referenced this pull request Jul 8, 2026
@larryro
larryro force-pushed the feat/external-agent-workspace-tools branch from cfde4ce to 33775ba Compare July 8, 2026 13:57
larryro added 7 commits July 8, 2026 22:17
An external agent's toolNames (schema-restricted to the new
EXTERNAL_AGENT_TOOL_NAMES subset: rag_search, document_find,
document_retrieve, document_write) now becomes the session's
workspace-tool grant set, dispatched from the sandbox over the
existing MCP bridge:

- schema: the superRefine allows the bridgeable subset (workflows
  stay loop-only); sandbox_bridge.test.ts guards the subset against
  registry drift, since refine rules are invisible to the config
  fingerprint
- the session token scope carries toolGrants + agentSlug/threadId/
  userId, so POST /api/tools/execute derives grants AND execution
  context from the token row, never from the request body
- the dispatch reuses the loop's own registry tool implementations
  with a synthesized ToolCtx, so tool-internal authorization,
  untrusted-content handling, and document_write's approval card
  apply unchanged; a per-session rate limit and a forensic audit
  table mirror the integration dispatch
- the Tools tab shows the platform-tool picker for external agents,
  filtered to the subset (en/de/fr copy updated)

No migration: existing configs stay valid (the relaxation is
data-safe); admins opt in per agent. BYO agents have no session key
and therefore no tool bridge, matching integrations.
Add workspace_tool({tool, args}) and workspace_status() to
tale-integrations-mcp, relaying to /api/tools/execute|status with
the same per-session key the integration tools use. The tools URL
is derived from TALE_INTEGRATIONS_URL (…/api/integrations →
…/api/tools) so every adapter keeps its single env contract;
against an older platform the derived endpoint 404s and the tool
reports a plain failure instead of misrouting.
Extend the external-agent page (en/de/fr natively) with the
workspace-tool paragraph: platform tools granted on the Tools tab
execute server-side under the agent's knowledge scope, a hub write
surfaces the standard approval card, and BYO runs (no session key)
have no tool bridge.
The guard imported the whole TOOL_REGISTRY (65 tool modules) to read
two static fields, and its @convex-dev/agent mock returned a
get-anything Proxy — vitest awaits mock factory results, and a Proxy
that answers .then with a function is a thenable that never settles,
wedging collection at 0% CPU (it stalled the whole platform suite).

Rewrite the guard to import exactly the named definitions: the
dangerous drift direction is a schema-accepted name whose definition
is NOT marked (a legal grant the dispatch would deny); the opposite
direction is inert by construction since an unlisted name can never
be granted. A Record keyed by the shared union still forces this file
to grow with EXTERNAL_AGENT_TOOL_NAMES. Runs in <1s.
spawn_agent workers always receive file_read + file_list (like
update_progress): a worker handed workspace paths or fileIds in its
instructions could not ground them without a read grant — e.g. a visual
QA job with only the image tool cannot resolve a path to the fileId the
tool takes. Requesting an implicit tool is a no-op, never a narrowing.

Write-side workspace tools (file_write, file_edit, file_delete,
run_code) stay explicit parent grants, and only those attach the
post-job sandboxState to the spawn result — read-only jobs cannot
change the workspace. The tool description documents the contract;
the delegation docs (en/de/fr) note the read exception.
Chat callers pass no maxSteps and the builtin assistant config sets
none, so every chat turn ran under the odd-one-out 20-step fallback.
Tool-heavy turns (pptx generation needs 20+ tool steps) hit
stepCountIs(20) mid-loop on virtually every run, ended with
finishReason 'tool-calls', and fired the [RESPONSE_INTERRUPTED]
continue-retry with its warning marker.

40 matches create_agent_config.ts, spawn jobs, and generate_response's
stopWhen fallback; the effective ceiling is unchanged (20 + one
20-step continue), the visible seam and the full context rebuild in
the 21-40 step range are gone.
A turn that ends with finishReason 'tool-calls' ran out of its step
budget mid-work — a capacity stop, not a provider failure. It now
continues for up to MAX_STEP_CAP_CONTINUES(3) rounds within the turn
deadline, each marked with a neutral [STEP_LIMIT_CONTINUED] info
notice; provider anomalies ('length', 'unknown', DeepSeek's empty
stop) keep the single [RESPONSE_INTERRUPTED] retry as before, and
shouldRetryGeneration now reports which kind applies.

When the rounds or the remaining time run out with the work still
unfinished, the turn saves [STEP_LIMIT_REACHED] — the chat renders a
localized muted line telling the user the turn stopped at its step
limit and a message continues it — instead of the warning-styled
'The response couldn't be completed' incomplete notice.

didRetry now tracks only anomaly retries, so the retried telemetry
field no longer counts expected capacity continues.
@larryro
larryro force-pushed the feat/external-agent-workspace-tools branch from 33775ba to b220ea1 Compare July 8, 2026 14:18
@larryro
larryro merged commit 0ebea02 into main Jul 8, 2026
53 checks passed
@larryro
larryro deleted the feat/external-agent-workspace-tools branch July 8, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant