Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,29 @@ is a [=model context=] [=struct=] created alongside the {{ModelContext}}.
<dd>
<p>Executes a tool on the document it was registered on. Returns a promise that resolves to the
stringified result of the tool's execution.</p>

<p><var ignore>tool</var> is a {{RegisteredTool}} returned by {{ModelContext/getTools()}}. Its
{{RegisteredTool/inputSchema}} is exposed as a parsed JavaScript object. Callers pass the
structured JavaScript value described by that schema as <var ignore>inputObject</var>; the user
agent serializes and transfers it to the tool's execution context, so callers do not
{{JSON/stringify()}} it first.</p>
</dd>
</dl>

<div class=example id=executing-a-discovered-tool>
The following discovers a tool and executes it with a JavaScript object:

```js
const tools = await document.modelContext.getTools();
const tool = tools.find(({name}) => name === "example_tool");

if (tool) {
console.log(tool.inputSchema.type); // "object"
const result = await document.modelContext.executeTool(tool, {message: "hello"});
}
```
</div>


<div algorithm>
The <dfn method for=ModelContext>registerTool(<var>tool</var>, <var>options</var>)</dfn> method steps are:
Expand Down