-
Notifications
You must be signed in to change notification settings - Fork 126
feat: skills: support script execution #276
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
371dfdc
feat:support script exectuion for skills
kalenkevich e50c164
Add more tests
kalenkevich 60d0798
tests
kalenkevich 1477540
pr comment fixes
kalenkevich 1ca67ea
fixes
kalenkevich 0d0497e
fixes
kalenkevich d2f2c76
fixes
kalenkevich 79899de
fix tests
kalenkevich 972ed01
author
kalenkevich 0a63465
mock curl requests to reduce tests flakyness
kalenkevich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import {FunctionDeclaration, Type} from '@google/genai'; | ||
| import {isLlmAgent} from '../../agents/llm_agent.js'; | ||
| import {CodeExecutionLanguage} from '../../code_executors/code_execution_utils.js'; | ||
| import {experimental} from '../../utils/experimental.js'; | ||
| import {materializeFiles} from '../../utils/file_utils.js'; | ||
| import {BaseTool, RunAsyncToolRequest} from '../base_tool.js'; | ||
| import {SkillToolset} from './skill_toolset.js'; | ||
|
|
||
| @experimental | ||
| export class RunSkillInlineScriptTool extends BaseTool { | ||
| constructor(private toolset: SkillToolset) { | ||
| super({ | ||
| name: 'run_skill_inline_script', | ||
| description: | ||
| 'Executes an inline script provided directly in the request.', | ||
| }); | ||
| } | ||
|
|
||
| override _getDeclaration(): FunctionDeclaration { | ||
| return { | ||
| name: this.name, | ||
| description: this.description, | ||
| parameters: { | ||
| type: Type.OBJECT, | ||
| properties: { | ||
| script_content: { | ||
| type: Type.STRING, | ||
| description: 'The content of the script to execute.', | ||
| }, | ||
| language: { | ||
| type: Type.STRING, | ||
| description: 'The language/type of the script.', | ||
| enum: Object.values(CodeExecutionLanguage).filter( | ||
| (l) => l !== CodeExecutionLanguage.UNSPECIFIED, | ||
| ), | ||
| }, | ||
| args: { | ||
| anyOf: [ | ||
| {type: Type.OBJECT}, | ||
| {type: Type.ARRAY, items: {type: Type.STRING}}, | ||
| ], | ||
| description: | ||
| 'Optional arguments to pass to the script as key-value pairs or an array of strings.', | ||
| }, | ||
| }, | ||
| required: ['script_content', 'language'], | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| override async runAsync({ | ||
| args, | ||
| toolContext, | ||
| }: RunAsyncToolRequest): Promise<unknown> { | ||
| const inlineScriptContent = args['script_content'] as string; | ||
| const language = args['language'] as string; | ||
| const scriptArgs = args['args'] as | ||
| | string[] | ||
| | Record<string, string | number | boolean> | ||
| | undefined; | ||
|
|
||
| if (!inlineScriptContent) { | ||
| return { | ||
| error: 'Script content is required.', | ||
| errorCode: 'MISSING_SCRIPT_CONTENT', | ||
| }; | ||
| } | ||
| if (!language) { | ||
| return { | ||
| error: 'Language is required.', | ||
| errorCode: 'MISSING_LANGUAGE', | ||
| }; | ||
| } | ||
|
|
||
| let codeExecutor = this.toolset?.codeExecutor; | ||
| if (!codeExecutor) { | ||
| const agent = toolContext.invocationContext.agent; | ||
| if (isLlmAgent(agent)) { | ||
| codeExecutor = agent.codeExecutor; | ||
| } | ||
| } | ||
|
|
||
| if (!codeExecutor) { | ||
| return { | ||
| error: 'No code executor configured.', | ||
| errorCode: 'NO_CODE_EXECUTOR', | ||
| }; | ||
| } | ||
|
|
||
| try { | ||
| const result = await codeExecutor.executeCode({ | ||
| invocationContext: toolContext.invocationContext, | ||
| codeExecutionInput: { | ||
| code: inlineScriptContent, | ||
| inputFiles: [], | ||
| language: language as CodeExecutionLanguage, | ||
| args: scriptArgs, | ||
| }, | ||
| }); | ||
|
|
||
| // Final filename could be different if there was a collision, so update the result. | ||
| result.outputFiles = await materializeFiles(result.outputFiles); | ||
|
|
||
| return result; | ||
| } catch (e: unknown) { | ||
| return { | ||
| error: `Failed to execute inline script: ${(e as Error).message}`, | ||
| errorCode: 'EXECUTION_ERROR', | ||
| }; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.