Skip to content

Conversation

@jingyun19
Copy link

@jingyun19 jingyun19 commented Nov 19, 2025

Update explainer and spec to support tool use functionalities without automatic execution.

Explainer: added an example and explained how to make tool calls
Spec: reflect IDL changes in https://chromium-review.googlesource.com/c/chromium/src/+/7092943


Preview | Diff

Added detailed explanations for tool use modes, including examples for open loop and closed loop execution.
Updated README to clarify tool-call and tool-result usage.
Added new types and enums for tool calls and responses.
@jingyun19
Copy link
Author

Copy link
Contributor

@tomayac tomayac left a comment

Choose a reason for hiding this comment

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

Tried to make the code samples more readable and correct. Maybe consider running them all through a tool like prettier, which catches typos like missing commas or parentheses.

As general feedback, could the explainer outline why developers would choose closed vs. open?

Comment on lines +180 to +185
await session.append([
{role: "user", content: "What is the weather in Seattle?"},
{role: "tool-call", content: {type: "tool-call", value: {callID:" get_weather_1", name: "get_weather", arguments: {location:"Seattle"}}},
{role: "tool-result", content: {type: "tool-response", value: {callID: "get_weather_1", name: "get_weather", result: [{type:"object", value: {temperature: "55F", humidity: "67%"}}]}},
{role: "assistant", content: "The temperature in Seattle is 55F and humidity is 67%"},
]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
await session.append([
{role: "user", content: "What is the weather in Seattle?"},
{role: "tool-call", content: {type: "tool-call", value: {callID:" get_weather_1", name: "get_weather", arguments: {location:"Seattle"}}},
{role: "tool-result", content: {type: "tool-response", value: {callID: "get_weather_1", name: "get_weather", result: [{type:"object", value: {temperature: "55F", humidity: "67%"}}]}},
{role: "assistant", content: "The temperature in Seattle is 55F and humidity is 67%"},
]);
await session.append([
{ role: "user", content: "What is the weather in Seattle?" },
{
role: "tool-call",
content: {
type: "tool-call",
value: {
callID: " get_weather_1",
name: "get_weather",
arguments: { location: "Seattle" },
},
},
},
{
role: "tool-result",
content: {
type: "tool-response",
value: {
callID: "get_weather_1",
name: "get_weather",
result: [
{ type: "object", value: { temperature: "55F", humidity: "67%" } },
],
},
},
},
{
role: "assistant",
content: "The temperature in Seattle is 55F and humidity is 67%",
},
]);

]);
```
Note that "role" and "type" now supports "tool-call" and "tool-result".
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Note that "role" and "type" now supports "tool-call" and "tool-result".
Note that `"role"` and `"type"` now support `"tool-call"` and `"tool-result"`.

Comment on lines +200 to +212
sessionOptions = structuredClone(options);
sessionOptions.expectedOutputs.push(["tool-call"]);
session = await LanguageModel.create(sessionOptions);

var result = await session.prompt("What is the weather in Seattle?");
if (result.type=="tool-call") {
if (result.name == "get_weather") {
const tool_result = getWeather(result.arguments.location);
result = session.prompt([{role:"tool-result", content: {type: "tool-result", value: {callId: result.callID, name: result.name, result: [{type:"object", value: tool_result}]}}}])
}
} else{
console.log(result)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
sessionOptions = structuredClone(options);
sessionOptions.expectedOutputs.push(["tool-call"]);
session = await LanguageModel.create(sessionOptions);
var result = await session.prompt("What is the weather in Seattle?");
if (result.type=="tool-call") {
if (result.name == "get_weather") {
const tool_result = getWeather(result.arguments.location);
result = session.prompt([{role:"tool-result", content: {type: "tool-result", value: {callId: result.callID, name: result.name, result: [{type:"object", value: tool_result}]}}}])
}
} else{
console.log(result)
}
sessionOptions = structuredClone(options);
sessionOptions.expectedOutputs.push(["tool-call"]);
session = await LanguageModel.create(sessionOptions);
var result = await session.prompt("What is the weather in Seattle?");
if (result.type == "tool-call") {
if (result.name == "get_weather") {
const tool_result = getWeather(result.arguments.location);
result = session.prompt([
{
role: "tool-result",
content: {
type: "tool-result",
value: {
callId: result.callID,
name: result.name,
result: [{ type: "object", value: tool_result }],
},
},
},
]);
}
} else {
console.log(result);
}

#### Closed Loop:
To enable automatic execution, add a `execute` function for each tool's implementation, and add a `toolUseConfig` to indicate that execution is enabled and pose a max number of tool calls invoked in a single session generation:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
To enable automatic execution, add a `execute` function for each tool's implementation, and add a `toolUseConfig` to indicate that execution is enabled and pose a max number of tool calls invoked in a single session generation:
To enable automatic execution, add an `execute` function for each tool's implementation, and add a `toolUseConfig` to indicate that execution is enabled and pose a max number of tool calls invoked in a single session generation:

sessionOptions.expectedOutputs.push(["tool-call"]);
session = await LanguageModel.create(sessionOptions);

var result = await session.prompt("What is the weather in Seattle?");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var result = await session.prompt("What is the weather in Seattle?");
let result = await session.prompt("What is the weather in Seattle?");

Example:
```js
sessionOptions = structuredClone(options);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
sessionOptions = structuredClone(options);
const sessionOptions = structuredClone(options);

```js
sessionOptions = structuredClone(options);
sessionOptions.expectedOutputs.push(["tool-call"]);
session = await LanguageModel.create(sessionOptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
session = await LanguageModel.create(sessionOptions);
const session = await LanguageModel.create(sessionOptions);

jingyun19 and others added 4 commits November 26, 2025 09:08
Co-authored-by: Thomas Steiner <tomac@google.com>
Co-authored-by: Thomas Steiner <tomac@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants