Repository navigation
feat(platform): let external agents call granted workspace tools - #2585
Merged
Merged
Conversation
larryro
force-pushed
the
feat/external-agent-workspace-tools
branch
from
July 8, 2026 11:45
681ff48 to
1c660bd
Compare
4 tasks
larryro
force-pushed
the
feat/external-agent-workspace-tools
branch
from
July 8, 2026 12:12
1c660bd to
a25a968
Compare
larryro
added a commit
that referenced
this pull request
Jul 8, 2026
larryro
force-pushed
the
feat/external-agent-workspace-tools
branch
from
July 8, 2026 13:57
cfde4ce to
33775ba
Compare
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
force-pushed
the
feat/external-agent-workspace-tools
branch
from
July 8, 2026 14:18
33775ba to
b220ea1
Compare
10 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
External agents (Claude Code & co. in the sandbox) can now carry
toolNameslike 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 newPOST /api/tools/execute|statusdispatch reuses the integration bridge's auth and invokes the loop's own registry tool implementations with a synthesizedToolCtx— so tool-internal authorization, untrusted-content handling, anddocument_write's approval card apply unchanged. The sandbox bridge (tale-integrations-mcp) gains genericworkspace_tool/workspace_statustools with zero adapter changes (the tools URL derives fromTALE_INTEGRATIONS_URL). The Tools tab shows the existing platform-tools picker for external agents, filtered to the subset.Design decisions (settled in design discussion):
migrations:checkgreen); existing configs stay valid and admins opt in per agent by editing the agent config.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 checkpasses (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 atuvx(ruff) being uninstalled; the diff contains no Python files. CI should confirm.bun run lint:sastpasses (Opengrep) — 467 rules, 0 findings (plus per-commit hook scans, 0 findings).services/platform/messages/{en,de,fr}.json—settings.agents.form.sectionToolsExternalDescriptionrewritten in all three.docs/{en,de,fr}/—platform/agents/external-agent.mdgains the workspace-tools paragraph, written natively per locale;tests/manual/agents.mdF17 expectation extended.README.md/README.de.md/README.fr.mdupdated — 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 typecheckandbun 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):
rag_search+document_write(picker now shows only the four workspace tools for external agents).workspace_toolcall withrag_searchresults (agent-scoped, same allow-list as a loop turn).status: requires_approvalrelayed by the agent, an approval card in the chat, and the write landing in the hub after approval.workspace_statusto report nothing granted andworkspace_toolto returnunavailable(schema also rejects non-subset names at config save).Notes for review
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 ownwrapToolscontract;getCtx(this)readsthis.ctx).rag_searchwraps video-link transcripts, strips reserved tags). Rationale in the file header.convex/_generated/api.d.tsentries for the three new modules were added by hand in the generator's exact format (noCONVEX_DEPLOYMENTin the authoring env); the nextconvex devregenerates identically.test(platform)commit fixes a genuine wedge the first drift-guard version introduced: avi.mockfactory returning a get-anything Proxy is an unsettleable thenable to vitest (factories are awaited) and stalled the whole suite at 0% CPU.