Skip to content

Commit 5379da1

Browse files
authored
Clarify tool-call and tool-result in README
Updated README to clarify tool-call and tool-result usage.
1 parent 14d59fc commit 5379da1

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,30 @@ await session.append([
185185
]);
186186
```
187187
188-
Note that "role" and "type" now supports "tool-call" and "tool-result". `content.result` is a list of a dictionary of `type` and `value`, where `type` can be `{"text", "image", "audio", "object" }` and `value` is `any`.
188+
Note that "role" and "type" now supports "tool-call" and "tool-result".
189+
`content.result` is a list of a dictionary of `type` and `value`, where `type` can be `{"text", "image", "audio", "object" }` and `value` is `any`.
189190
190191
#### Open Loop:
191192
192-
Without automatic execution, the API will return a `ToolCall` object with `callId` (a unique identifier of this tool call), `name` (name of the tool), and `arguments` (a dictionary fitting the JSON input schema of the tool's declaration), and client is expected to handle the tool execution and append the tool result back to the session.
193+
Open loop is enabled by specifying `tool-call` in `expectedOutputs` when the session is created.
194+
195+
When a tool needs to be called, the API will return an object with `callId` (a unique identifier of this tool call), `name` (name of the tool), and `arguments` (inputs to the tool), and client is expected to handle the tool execution and append the tool result back to the session. The `argument` is a dictionary fitting the JSON input schema of the tool's declaration; if the input schema is not "object", the value will be wrapped in a key.
193196
194197
Example:
195198
196199
```js
197-
const result = await session.prompt("What is the weather in Seattle?");
200+
sessionOptions = structuredClone(options);
201+
sessionOptions.expectedOutputs.push(["tool-call"]);
202+
session = await LanguageModel.create(sessionOptions);
203+
204+
var result = await session.prompt("What is the weather in Seattle?");
198205
if (result.type=="tool-call") {
199206
if (result.name == "get_weather") {
200207
const tool_result = getWeather(result.arguments.location);
201-
session.prompt([{role:"tool-result", content: {type: "tool-result", value: {callId: result.callID, name: result.name, result: [{type:"object", value: tool_result}]}}}])
208+
result = session.prompt([{role:"tool-result", content: {type: "tool-result", value: {callId: result.callID, name: result.name, result: [{type:"object", value: tool_result}]}}}])
202209
}
210+
} else{
211+
console.log(result)
203212
}
204213
```
205214
@@ -239,7 +248,7 @@ const session = await LanguageModel.create({
239248
},
240249
}
241250
],
242-
toolUseConfig: {enabled: true, max_tool_calls: 5},
251+
toolUseConfig: {enabled: true},
243252
});
244253

245254
const result = await session.prompt("What is the weather in Seattle?");

0 commit comments

Comments
 (0)