Skip to content

computer: Let the exec tool start runs with metadata - #292

Open
ben-reitz wants to merge 1 commit into
browser/exec-metadatafrom
browser/exec-tool-metadata
Open

ben-reitz wants to merge 1 commit into
browser/exec-metadatafrom
browser/exec-tool-metadata

Conversation

@ben-reitz

@ben-reitz ben-reitz commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

The exec tool starts every run without metadata, and the AI SDK and TanStack adapters pass only the abort signal on, so an app using the tool sets has no way to tell host modules who a run is for.

createExecTool now takes metadata and every tool set takes execMetadata: a record of strings, or a function that picks one from the tool call's id, which every agent library passes on. A throw from the function fails the call before anything runs.

const tools = createAITools({
  workspace,
  execMetadata: ({ toolCallId }) => ({ conversation: this.name, toolCall: toolCallId }),
});

A pi caller runs each call itself, so it can also pass metadata with the call: execute(call, { metadata }). When both are given, metadata passed with the call wins outright and the function isn't called, since the caller that passed it knows that call best. defineExec accepts either on each execute.

The function gets only { toolCallId }, not each library's whole call. The known callers need a value per call (pi passes it) or per agent (closed over), and the call id covers linking runs to tool calls. Handing over the AI SDK's or TanStack's own call object can be added later without breaking anyone.

Tests cover each adapter, a static record, the precedence rule, and a picker that throws. docs/09_tool_interface.md has a new section on run metadata.

@changeset-bot

changeset-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a4e28b0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@cloudflare/computer Minor
@cloudflare/dofs Minor
@cloudflare/computer-rpc Minor
@cloudflare/computerd Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot closed this Nov 2, 2026
@ben-reitz ben-reitz added the allow-pr Allow a PR to remain open. label Nov 2, 2026
@ben-reitz ben-reitz reopened this Nov 2, 2026
@ben-reitz
ben-reitz added this pull request to stack #294 November 2, 2026 17:27
@pkg-pr-new

pkg-pr-new Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/computer@292

commit: a4e28b0

@ben-reitz
ben-reitz force-pushed the browser/exec-tool-metadata branch from 352353b to 8692445 Compare November 3, 2026 10:14
@ben-reitz
ben-reitz marked this pull request as ready for review November 3, 2026 10:25

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@ben-reitz
ben-reitz force-pushed the browser/exec-tool-metadata branch from 8692445 to eab3b67 Compare November 3, 2026 11:31
devin-ai-integration[bot]

This comment was marked as resolved.

@cloudflare cloudflare deleted a comment from github-actions Bot Nov 3, 2026
@ben-reitz
ben-reitz force-pushed the browser/exec-tool-metadata branch from eab3b67 to 5cff4a5 Compare November 3, 2026 11:50
Comment thread docs/09_tool_interface.md
// Inside an agent with one instance per conversation.
const tools = createAITools({
workspace,
execMetadata: ({ toolCallId }) => ({ conversation: this.name, toolCall: toolCallId }),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd rather this was exec: { metadata: ... }

@ben-reitz ben-reitz Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aron-cf exec is just used for the backend definitions right now.

createAITools({
  workspace,
  exec: { javascript: {}, container: { description: "…" } }, // backends, keyed by id
  execOutput: { maxBytes, maxLines },
  execMetadata: ({ toolCallId }) => ({ … }),                  // added in this pr
});

we could change the api to something like this instead which is a bit nicer than what we have right now?

createAITools({
  workspace,
  exec: { 
    backends: { javascript: {}, container: { description: "…" } }, // backends, keyed by id
    output: { maxBytes, maxLines },
    metadata: ({ toolCallId }) => ({ … }),                  // added in this pr
  }
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#300 i've opened this in case we want to make this change.

A run's metadata tells host modules who the run is for, but the exec
tool started every run without any, and the AI SDK and TanStack tools
passed only the abort signal on, so an app had no way to supply it.

`createExecTool` now takes `metadata` and every tool set takes
`execMetadata`: a record of strings, or a function that picks one from
the tool call's id, which each agent library passes on. A throw from
the function fails the call before anything runs. A pi caller runs
each call itself, so it can pass `metadata` on the context it hands
`execute` instead, and metadata passed with a call wins, since the
caller that passed it knows that call best.
@ben-reitz
ben-reitz force-pushed the browser/exec-tool-metadata branch from 88bc6b2 to a4e28b0 Compare November 4, 2026 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

allow-pr Allow a PR to remain open.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants