-
Notifications
You must be signed in to change notification settings - Fork 82
tool use without auto execution #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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.
tomayac
left a comment
There was a problem hiding this 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?
| 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%"}, | ||
| ]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Note that "role" and "type" now supports "tool-call" and "tool-result". | |
| Note that `"role"` and `"type"` now support `"tool-call"` and `"tool-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) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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?"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| sessionOptions = structuredClone(options); | |
| const sessionOptions = structuredClone(options); |
| ```js | ||
| sessionOptions = structuredClone(options); | ||
| sessionOptions.expectedOutputs.push(["tool-call"]); | ||
| session = await LanguageModel.create(sessionOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| session = await LanguageModel.create(sessionOptions); | |
| const session = await LanguageModel.create(sessionOptions); |
Co-authored-by: Thomas Steiner <tomac@google.com>
Co-authored-by: Thomas Steiner <tomac@google.com>
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