diff --git a/index.bs b/index.bs index 241bb2c..db2961c 100644 --- a/index.bs +++ b/index.bs @@ -635,9 +635,29 @@ is a [=model context=] [=struct=] created alongside the {{ModelContext}}.

Executes a tool on the document it was registered on. Returns a promise that resolves to the stringified result of the tool's execution.

+ +

tool 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 inputObject; the user + agent serializes and transfers it to the tool's execution context, so callers do not + {{JSON/stringify()}} it first.

+
+ 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"}); + } + ``` +
+
The registerTool(tool, options) method steps are: