Skip to content

Commit 69b73b4

Browse files
mlmrxdomfarolino
andauthored
Clarify executeTool() input and schema values, and add an example (#279)
Co-authored-by: Dominic Farolino <[email protected]>
1 parent 321d83c commit 69b73b4

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎index.bs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,27 @@ is a [=model context=] [=struct=] created alongside the {{ModelContext}}.
655655
<dd>
656656
<p>Executes a tool on the document it was registered on. Returns a promise that resolves to the
657657
stringified result of the tool's execution.</p>
658+
659+
<p><var ignore>tool</var> is a {{RegisteredTool}}, often retrieved by
660+
{{ModelContext/getTools()}}. Callers pass a JavaScript object in as the
661+
{{ModelContext/executeTool(tool)/inputObject}} argument for the tool; it's expected to match the
662+
schema described by the tool's {{RegisteredTool/inputSchema}}.</p>
658663
</dd>
659664
</dl>
660665

666+
<div class=example id=executing-a-discovered-tool>
667+
The following discovers a tool and executes it with input arguments:
668+
669+
```js
670+
const tools = await document.modelContext.getTools();
671+
const tool = tools.find(t => t.name === 'example_tool');
672+
673+
if (tool) {
674+
const result = await document.modelContext.executeTool(tool, {message: "hello"});
675+
}
676+
```
677+
</div>
678+
661679

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

0 commit comments

Comments
 (0)