From 797d6edbc7948e8300f9152ec5abad1b4d1fcaa3 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 2 Oct 2024 19:59:44 +0000 Subject: [PATCH] Add user input tools and refactor existing GitHub actions and tools for enhanced user interaction and validation --- docs/genaisrc/genaiscript.d.ts | 6 + docs/src/components/BuiltinTools.mdx | 4 + .../content/docs/reference/scripts/system.mdx | 398 +++++++++++++----- genaisrc/genaiscript.d.ts | 6 + packages/auto/genaiscript.d.ts | 6 + packages/core/src/genaisrc/genaiscript.d.ts | 6 + .../src/genaisrc/system.agent_fs.genai.mjs | 3 +- .../src/genaisrc/system.agent_git.genai.mjs | 3 +- .../genaisrc/system.agent_github.genai.mjs | 1 - .../system.agent_interpreter.genai.mjs | 1 - .../system.agent_user_input.genai.mjs | 38 ++ .../genaisrc/system.github_actions.genai.mjs | 63 +-- .../genaisrc/system.github_files.genai.mjs | 36 +- .../genaisrc/system.github_issues.genai.mjs | 58 ++- .../genaisrc/system.github_pulls.genai.mjs | 59 ++- .../core/src/genaisrc/system.math.genai.js | 29 +- .../src/genaisrc/system.user_input.genai.mjs | 70 +++ .../sample/genaisrc/blog/genaiscript.d.ts | 6 + packages/sample/genaisrc/genaiscript.d.ts | 6 + .../sample/genaisrc/node/genaiscript.d.ts | 6 + .../sample/genaisrc/python/genaiscript.d.ts | 6 + .../sample/genaisrc/style/genaiscript.d.ts | 6 + packages/sample/genaisrc/user-input.genai.mjs | 7 + packages/sample/src/aici/genaiscript.d.ts | 6 + packages/sample/src/errors/genaiscript.d.ts | 6 + packages/sample/src/genaiscript.d.ts | 6 + packages/sample/src/makecode/genaiscript.d.ts | 6 + packages/sample/src/tla/genaiscript.d.ts | 6 + packages/sample/src/vision/genaiscript.d.ts | 6 + packages/vscode/genaisrc/genaiscript.d.ts | 6 + slides/genaisrc/genaiscript.d.ts | 6 + 31 files changed, 680 insertions(+), 192 deletions(-) create mode 100644 packages/core/src/genaisrc/system.agent_user_input.genai.mjs create mode 100644 packages/core/src/genaisrc/system.user_input.genai.mjs create mode 100644 packages/sample/genaisrc/user-input.genai.mjs diff --git a/docs/genaisrc/genaiscript.d.ts b/docs/genaisrc/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/docs/genaisrc/genaiscript.d.ts +++ b/docs/genaisrc/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/docs/src/components/BuiltinTools.mdx b/docs/src/components/BuiltinTools.mdx index df1e60c935..7a7842505e 100644 --- a/docs/src/components/BuiltinTools.mdx +++ b/docs/src/components/BuiltinTools.mdx @@ -10,6 +10,7 @@ import { LinkCard } from '@astrojs/starlight/components'; + @@ -38,4 +39,7 @@ import { LinkCard } from '@astrojs/starlight/components'; + + + diff --git a/docs/src/content/docs/reference/scripts/system.mdx b/docs/src/content/docs/reference/scripts/system.mdx index 52a9184d0c..3089ef78da 100644 --- a/docs/src/content/docs/reference/scripts/system.mdx +++ b/docs/src/content/docs/reference/scripts/system.mdx @@ -119,7 +119,6 @@ defTool( type: "string", description: "Query to answer", }, - required: ["query"], }, async (args) => { const { context, query } = args @@ -147,7 +146,7 @@ defTool( "system.retrieval_fuzz_search", "system.md_frontmatter", ], - label: "agent file system" + label: "agent file system", } ) return res @@ -180,7 +179,6 @@ defTool( type: "string", description: "Query to answer", }, - required: ["query"], }, async (args) => { const { context, query } = args @@ -205,7 +203,7 @@ defTool( "system.explanations", "system.git", ], - label: "agent git" + label: "agent git", } ) return res @@ -238,7 +236,6 @@ defTool( type: "string", description: "Query to answer", }, - required: ["query"], }, async (args) => { const { context, query } = args @@ -302,7 +299,6 @@ defTool( type: "string", description: "Query to answer", }, - required: ["query"], }, async (args) => { const { context, query } = args @@ -339,6 +335,57 @@ defTool( ````` +### `system.agent_user_input` + +Agent that can asks questions to the user. + + + +- tool `agent_user_input`: Ask user for input to confirm, select or answer a question. + +`````js wrap title="system.agent_user_input" +system({ + title: "Agent that can asks questions to the user.", +}) + +const model = env.vars.agentInterpreterModel +defTool( + "agent_user_input", + "Ask user for input to confirm, select or answer a question.", + { + query: { + type: "string", + description: "Query to answer", + }, + }, + async (args) => { + const { context, query } = args + context.log(`agent user input: ${query}`) + const res = await runPrompt( + (_) => { + _.def("QUERY", query) + _.$`You are an agent that can ask questions to the user and receive answers. Use the tools to interact with the user. + + Analyze and answer QUERY. + + - the message should be very clear. Add context from the conversation as needed. + - Assume that your answer will be analyzed by an AI, not a human. + - If you cannot answer the query, return an empty string. + ` + }, + { + model, + system: ["system", "system.tools", "system.user_input"], + label: "agent user input", + } + ) + return res + } +) + +````` + + ### `system.annotations` Emits annotations compatible with GitHub Actions @@ -893,17 +940,21 @@ defTool( "github_actions_runs_list", "List all runs for a workflow. Use 'git_actions_list_workflows' to list workflows.", { - workflow_id: { - type: "string", - description: "ID of the workflow to list runs for.", - }, - branch: { - type: "string", - description: "Branch to list runs for.", - }, - status: { - type: "string", - description: "Filter runs by completion status: success, failured.", + type: "object", + properties: { + workflow_id: { + type: "string", + description: "ID of the workflow to list runs for.", + }, + branch: { + type: "string", + description: "Branch to list runs for.", + }, + status: { + type: "string", + description: + "Filter runs by completion status: success, failured.", + }, }, required: ["workflow_id"], }, @@ -932,10 +983,13 @@ defTool( "github_actions_jobs_list", "List all jobs for a run.", { - run_id: { - type: "string", - description: - "ID of the run to list jobs for. Use 'git_actions_list_runs' to list runs for a workflow.", + type: "object", + properties: { + run_id: { + type: "string", + description: + "ID of the run to list jobs for. Use 'git_actions_list_runs' to list runs for a workflow.", + }, }, required: ["run_id"], }, @@ -954,9 +1008,12 @@ defTool( "github_actions_job_logs_get", "Download workflow job log.", { - job_id: { - type: "string", - description: "ID of the job to download log for.", + type: "object", + properties: { + job_id: { + type: "string", + description: "ID of the job to download log for.", + }, }, required: ["job_id"], }, @@ -974,13 +1031,16 @@ defTool( "github_actions_job_los_diff", "Diffs two workflow job logs.", { - job_id: { - type: "string", - description: "ID of the job to compare.", - }, - other_job_id: { - type: "string", - description: "ID of the other job to compare.", + type: "object", + properties: { + job_id: { + type: "string", + description: "ID of the job to compare.", + }, + other_job_id: { + type: "string", + description: "ID of the other job to compare.", + }, }, required: ["job_id", "other_job_id"], }, @@ -1013,13 +1073,16 @@ defTool( "github_files_get", "Get a file from a repository.", { - filepath: { - type: "string", - description: "Path to the file", - }, - ref: { - type: "string", - description: "Branch, tag, or commit to get the file from", + type: "object", + properties: { + filepath: { + type: "string", + description: "Path to the file", + }, + ref: { + type: "string", + description: "Branch, tag, or commit to get the file from", + }, }, required: ["filepath", "ref"], }, @@ -1035,14 +1098,17 @@ defTool( "github_files_list", "List all files in a repository.", { - path: { - type: "string", - description: "Path to the directory", - }, - ref: { - type: "string", - description: - "Branch, tag, or commit to get the file from. Uses default branch if not provided.", + type: "object", + properties: { + path: { + type: "string", + description: "Path to the directory", + }, + ref: { + type: "string", + description: + "Branch, tag, or commit to get the file from. Uses default branch if not provided.", + }, }, required: ["path"], }, @@ -1076,22 +1142,26 @@ defTool( "github_issues_list", "List all issues in a repository.", { - state: { - type: "string", - description: - "state of the issue from 'open, 'closed', 'all'. Default is 'open'.", - }, - labels: { - type: "string", - description: "Comma-separated list of labels to filter by.", - }, - sort: { - type: "string", - description: "What to sort by: 'created', 'updated', 'comments'", - }, - direction: { - type: "string", - description: "Direction to sort: 'asc', 'desc'", + type: "object", + properties: { + state: { + type: "string", + description: + "state of the issue from 'open, 'closed', 'all'. Default is 'open'.", + }, + labels: { + type: "string", + description: "Comma-separated list of labels to filter by.", + }, + sort: { + type: "string", + description: + "What to sort by: 'created', 'updated', 'comments'", + }, + direction: { + type: "string", + description: "Direction to sort: 'asc', 'desc'", + }, }, }, async (args) => { @@ -1108,7 +1178,16 @@ defTool( defTool( "github_issues_get", "Get a single issue by number.", - { number: "number" }, + { + type: "object", + properties: { + number: { + type: "number", + description: "The 'number' of the issue (not the id)", + }, + }, + required: ["number"], + }, async (args) => { const { number: issue_number, context } = args context.log(`github issue get ${issue_number}`) @@ -1128,7 +1207,16 @@ defTool( defTool( "github_issues_comments_list", "Get comments for an issue.", - { number: "number" }, + { + type: "object", + properties: { + number: { + type: "number", + description: "The 'number' of the issue (not the id)", + }, + }, + required: ["number"], + }, async (args) => { const { number: issue_number, context } = args context.log(`github issue list comments ${issue_number}`) @@ -1166,22 +1254,26 @@ defTool( "github_pulls_list", "List all pull requests in a repository.", { - state: { - type: "string", - description: - "state of the pull request from 'open, 'closed', 'all'. Default is 'open'.", - }, - labels: { - type: "string", - description: "Comma-separated list of labels to filter by.", - }, - sort: { - type: "string", - description: "What to sort by: 'created', 'updated', 'comments'", - }, - direction: { - type: "string", - description: "Direction to sort: 'asc', 'desc'", + type: "object", + properties: { + state: { + type: "string", + description: + "state of the pull request from 'open, 'closed', 'all'. Default is 'open'.", + }, + labels: { + type: "string", + description: "Comma-separated list of labels to filter by.", + }, + sort: { + type: "string", + description: + "What to sort by: 'created', 'updated', 'comments'", + }, + direction: { + type: "string", + description: "Direction to sort: 'asc', 'desc'", + }, }, }, async (args) => { @@ -1202,7 +1294,16 @@ defTool( defTool( "github_pulls_get", "Get a single pull request by number.", - { number: "number" }, + { + type: "object", + properties: { + number: { + type: "number", + description: "The 'number' of the pull request (not the id)", + }, + }, + required: ["number"], + }, async (args) => { const { number: pull_number, context } = args context.log(`github pull get ${pull_number}`) @@ -1222,7 +1323,17 @@ defTool( defTool( "github_pulls_review_comments_list", "Get review comments for a pull request.", - { number: "number" }, + { + type: "object", + properties: { + number: { + type: "number", + description: "The 'number' of the pull request (not the id)", + }, + }, + required: ["number"], + }, + async (args) => { const { number: pull_number, context } = args context.log(`github pull comments list ${pull_number}`) @@ -1251,19 +1362,25 @@ system({ description: "Register a function that evaluates math expressions", }) -defTool("math_eval", "Evaluates a math expression", { - type: "object", - properties: { - expression: { - type: "string", - description: "Math expression to evaluate using mathjs format.", - } +defTool( + "math_eval", + "Evaluates a math expression", + { + type: "object", + properties: { + expression: { + type: "string", + description: "Math expression to evaluate using mathjs format.", + }, + }, + required: ["expression"], }, - required: ["expression"], -}, async (args) => { - const { expression } = args - return "" + (await parsers.math(expression) ?? "?") -}) + async (args) => { + const { expression } = args + return "" + ((await parsers.math(expression)) ?? "?") + } +) + ````` @@ -1383,8 +1500,8 @@ defTool( required: ["main"], }, async (args) => { - const { main = "" } = args - console.log(`python code interpreter: run`) + const { context, main = "" } = args + context.log(`python code interpreter: run`) const container = await getContainer return await queue.add(async () => { await container.writeText("main.py", main) @@ -1409,8 +1526,8 @@ defTool( required: ["from"], }, async (args) => { - const { from, to = "" } = args - console.log(`python code interpreter: cp ${from} ${to}`) + const { context, from, to = "" } = args + context.log(`python code interpreter: cp ${from} ${to}`) const container = await getContainer return await queue.add(async () => { await container.copyTo(from, to) @@ -1682,6 +1799,91 @@ $`Also, you are an expert coder in TypeScript.` ````` +### `system.user_input` + +Tools to ask questions to the user. + + + +- tool `user_input_confirm`: Ask the user to confirm a message. +- tool `user_input_select`: Ask the user to select an option. +- tool `user_input_text`: Ask the user to input text. + +`````js wrap title="system.user_input" +system({ + title: "Tools to ask questions to the user.", +}) + +defTool( + "user_input_confirm", + "Ask the user to confirm a message.", + { + type: "object", + properties: { + message: { + type: "string", + description: "Message to confirm", + }, + }, + required: ["message"], + }, + async (args) => { + const { context, message } = args + context.log(`user input confirm: ${message}`) + return await host.confirm(message) + } +) + +defTool( + "user_input_select", + "Ask the user to select an option.", + { + type: "object", + properties: { + message: { + type: "string", + description: "Message to select", + }, + options: { + type: "array", + description: "Options to select", + items: { + type: "string", + }, + }, + }, + required: ["message", "options"], + }, + async (args) => { + const { context, message, options } = args + context.log(`user input select: ${message}`) + return await host.select(message, options) + } +) + +defTool( + "user_input_text", + "Ask the user to input text.", + { + type: "object", + properties: { + message: { + type: "string", + description: "Message to input", + }, + }, + required: ["message"], + }, + async (args) => { + const { context, message } = args + context.log(`user input text: ${message}`) + return await host.input(message) + } +) + +````` + + ### `system.zero_shot_cot` Zero-shot Chain Of Though diff --git a/genaisrc/genaiscript.d.ts b/genaisrc/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/genaisrc/genaiscript.d.ts +++ b/genaisrc/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/packages/auto/genaiscript.d.ts b/packages/auto/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/packages/auto/genaiscript.d.ts +++ b/packages/auto/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/packages/core/src/genaisrc/genaiscript.d.ts b/packages/core/src/genaisrc/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/packages/core/src/genaisrc/genaiscript.d.ts +++ b/packages/core/src/genaisrc/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/packages/core/src/genaisrc/system.agent_fs.genai.mjs b/packages/core/src/genaisrc/system.agent_fs.genai.mjs index 9d8ed61fdd..7ba3b86f43 100644 --- a/packages/core/src/genaisrc/system.agent_fs.genai.mjs +++ b/packages/core/src/genaisrc/system.agent_fs.genai.mjs @@ -12,7 +12,6 @@ defTool( type: "string", description: "Query to answer", }, - required: ["query"], }, async (args) => { const { context, query } = args @@ -40,7 +39,7 @@ defTool( "system.retrieval_fuzz_search", "system.md_frontmatter", ], - label: "agent file system" + label: "agent file system", } ) return res diff --git a/packages/core/src/genaisrc/system.agent_git.genai.mjs b/packages/core/src/genaisrc/system.agent_git.genai.mjs index 786a147b3c..2ce30304ac 100644 --- a/packages/core/src/genaisrc/system.agent_git.genai.mjs +++ b/packages/core/src/genaisrc/system.agent_git.genai.mjs @@ -12,7 +12,6 @@ defTool( type: "string", description: "Query to answer", }, - required: ["query"], }, async (args) => { const { context, query } = args @@ -37,7 +36,7 @@ defTool( "system.explanations", "system.git", ], - label: "agent git" + label: "agent git", } ) return res diff --git a/packages/core/src/genaisrc/system.agent_github.genai.mjs b/packages/core/src/genaisrc/system.agent_github.genai.mjs index 478c093dfe..c183792cd1 100644 --- a/packages/core/src/genaisrc/system.agent_github.genai.mjs +++ b/packages/core/src/genaisrc/system.agent_github.genai.mjs @@ -12,7 +12,6 @@ defTool( type: "string", description: "Query to answer", }, - required: ["query"], }, async (args) => { const { context, query } = args diff --git a/packages/core/src/genaisrc/system.agent_interpreter.genai.mjs b/packages/core/src/genaisrc/system.agent_interpreter.genai.mjs index 502f71ea2c..df99627e91 100644 --- a/packages/core/src/genaisrc/system.agent_interpreter.genai.mjs +++ b/packages/core/src/genaisrc/system.agent_interpreter.genai.mjs @@ -11,7 +11,6 @@ defTool( type: "string", description: "Query to answer", }, - required: ["query"], }, async (args) => { const { context, query } = args diff --git a/packages/core/src/genaisrc/system.agent_user_input.genai.mjs b/packages/core/src/genaisrc/system.agent_user_input.genai.mjs new file mode 100644 index 0000000000..a4de1d647d --- /dev/null +++ b/packages/core/src/genaisrc/system.agent_user_input.genai.mjs @@ -0,0 +1,38 @@ +system({ + title: "Agent that can asks questions to the user.", +}) + +const model = env.vars.agentInterpreterModel +defTool( + "agent_user_input", + "Ask user for input to confirm, select or answer a question.", + { + query: { + type: "string", + description: "Query to answer", + }, + }, + async (args) => { + const { context, query } = args + context.log(`agent user input: ${query}`) + const res = await runPrompt( + (_) => { + _.def("QUERY", query) + _.$`You are an agent that can ask questions to the user and receive answers. Use the tools to interact with the user. + + Analyze and answer QUERY. + + - the message should be very clear. Add context from the conversation as needed. + - Assume that your answer will be analyzed by an AI, not a human. + - If you cannot answer the query, return an empty string. + ` + }, + { + model, + system: ["system", "system.tools", "system.user_input"], + label: "agent user input", + } + ) + return res + } +) diff --git a/packages/core/src/genaisrc/system.github_actions.genai.mjs b/packages/core/src/genaisrc/system.github_actions.genai.mjs index 823b28d346..9a0b78997d 100644 --- a/packages/core/src/genaisrc/system.github_actions.genai.mjs +++ b/packages/core/src/genaisrc/system.github_actions.genai.mjs @@ -22,17 +22,21 @@ defTool( "github_actions_runs_list", "List all runs for a workflow. Use 'git_actions_list_workflows' to list workflows.", { - workflow_id: { - type: "string", - description: "ID of the workflow to list runs for.", - }, - branch: { - type: "string", - description: "Branch to list runs for.", - }, - status: { - type: "string", - description: "Filter runs by completion status: success, failured.", + type: "object", + properties: { + workflow_id: { + type: "string", + description: "ID of the workflow to list runs for.", + }, + branch: { + type: "string", + description: "Branch to list runs for.", + }, + status: { + type: "string", + description: + "Filter runs by completion status: success, failured.", + }, }, required: ["workflow_id"], }, @@ -61,10 +65,13 @@ defTool( "github_actions_jobs_list", "List all jobs for a run.", { - run_id: { - type: "string", - description: - "ID of the run to list jobs for. Use 'git_actions_list_runs' to list runs for a workflow.", + type: "object", + properties: { + run_id: { + type: "string", + description: + "ID of the run to list jobs for. Use 'git_actions_list_runs' to list runs for a workflow.", + }, }, required: ["run_id"], }, @@ -83,9 +90,12 @@ defTool( "github_actions_job_logs_get", "Download workflow job log.", { - job_id: { - type: "string", - description: "ID of the job to download log for.", + type: "object", + properties: { + job_id: { + type: "string", + description: "ID of the job to download log for.", + }, }, required: ["job_id"], }, @@ -103,13 +113,16 @@ defTool( "github_actions_job_los_diff", "Diffs two workflow job logs.", { - job_id: { - type: "string", - description: "ID of the job to compare.", - }, - other_job_id: { - type: "string", - description: "ID of the other job to compare.", + type: "object", + properties: { + job_id: { + type: "string", + description: "ID of the job to compare.", + }, + other_job_id: { + type: "string", + description: "ID of the other job to compare.", + }, }, required: ["job_id", "other_job_id"], }, diff --git a/packages/core/src/genaisrc/system.github_files.genai.mjs b/packages/core/src/genaisrc/system.github_files.genai.mjs index 622b308f63..9766f42f1c 100644 --- a/packages/core/src/genaisrc/system.github_files.genai.mjs +++ b/packages/core/src/genaisrc/system.github_files.genai.mjs @@ -6,13 +6,16 @@ defTool( "github_files_get", "Get a file from a repository.", { - filepath: { - type: "string", - description: "Path to the file", - }, - ref: { - type: "string", - description: "Branch, tag, or commit to get the file from", + type: "object", + properties: { + filepath: { + type: "string", + description: "Path to the file", + }, + ref: { + type: "string", + description: "Branch, tag, or commit to get the file from", + }, }, required: ["filepath", "ref"], }, @@ -28,14 +31,17 @@ defTool( "github_files_list", "List all files in a repository.", { - path: { - type: "string", - description: "Path to the directory", - }, - ref: { - type: "string", - description: - "Branch, tag, or commit to get the file from. Uses default branch if not provided.", + type: "object", + properties: { + path: { + type: "string", + description: "Path to the directory", + }, + ref: { + type: "string", + description: + "Branch, tag, or commit to get the file from. Uses default branch if not provided.", + }, }, required: ["path"], }, diff --git a/packages/core/src/genaisrc/system.github_issues.genai.mjs b/packages/core/src/genaisrc/system.github_issues.genai.mjs index 37fe7c7978..767d6e7c17 100644 --- a/packages/core/src/genaisrc/system.github_issues.genai.mjs +++ b/packages/core/src/genaisrc/system.github_issues.genai.mjs @@ -6,22 +6,26 @@ defTool( "github_issues_list", "List all issues in a repository.", { - state: { - type: "string", - description: - "state of the issue from 'open, 'closed', 'all'. Default is 'open'.", - }, - labels: { - type: "string", - description: "Comma-separated list of labels to filter by.", - }, - sort: { - type: "string", - description: "What to sort by: 'created', 'updated', 'comments'", - }, - direction: { - type: "string", - description: "Direction to sort: 'asc', 'desc'", + type: "object", + properties: { + state: { + type: "string", + description: + "state of the issue from 'open, 'closed', 'all'. Default is 'open'.", + }, + labels: { + type: "string", + description: "Comma-separated list of labels to filter by.", + }, + sort: { + type: "string", + description: + "What to sort by: 'created', 'updated', 'comments'", + }, + direction: { + type: "string", + description: "Direction to sort: 'asc', 'desc'", + }, }, }, async (args) => { @@ -38,7 +42,16 @@ defTool( defTool( "github_issues_get", "Get a single issue by number.", - { number: "number" }, + { + type: "object", + properties: { + number: { + type: "number", + description: "The 'number' of the issue (not the id)", + }, + }, + required: ["number"], + }, async (args) => { const { number: issue_number, context } = args context.log(`github issue get ${issue_number}`) @@ -58,7 +71,16 @@ defTool( defTool( "github_issues_comments_list", "Get comments for an issue.", - { number: "number" }, + { + type: "object", + properties: { + number: { + type: "number", + description: "The 'number' of the issue (not the id)", + }, + }, + required: ["number"], + }, async (args) => { const { number: issue_number, context } = args context.log(`github issue list comments ${issue_number}`) diff --git a/packages/core/src/genaisrc/system.github_pulls.genai.mjs b/packages/core/src/genaisrc/system.github_pulls.genai.mjs index b5a13f3c66..f61a82f184 100644 --- a/packages/core/src/genaisrc/system.github_pulls.genai.mjs +++ b/packages/core/src/genaisrc/system.github_pulls.genai.mjs @@ -6,22 +6,26 @@ defTool( "github_pulls_list", "List all pull requests in a repository.", { - state: { - type: "string", - description: - "state of the pull request from 'open, 'closed', 'all'. Default is 'open'.", - }, - labels: { - type: "string", - description: "Comma-separated list of labels to filter by.", - }, - sort: { - type: "string", - description: "What to sort by: 'created', 'updated', 'comments'", - }, - direction: { - type: "string", - description: "Direction to sort: 'asc', 'desc'", + type: "object", + properties: { + state: { + type: "string", + description: + "state of the pull request from 'open, 'closed', 'all'. Default is 'open'.", + }, + labels: { + type: "string", + description: "Comma-separated list of labels to filter by.", + }, + sort: { + type: "string", + description: + "What to sort by: 'created', 'updated', 'comments'", + }, + direction: { + type: "string", + description: "Direction to sort: 'asc', 'desc'", + }, }, }, async (args) => { @@ -42,7 +46,16 @@ defTool( defTool( "github_pulls_get", "Get a single pull request by number.", - { number: "number" }, + { + type: "object", + properties: { + number: { + type: "number", + description: "The 'number' of the pull request (not the id)", + }, + }, + required: ["number"], + }, async (args) => { const { number: pull_number, context } = args context.log(`github pull get ${pull_number}`) @@ -62,7 +75,17 @@ defTool( defTool( "github_pulls_review_comments_list", "Get review comments for a pull request.", - { number: "number" }, + { + type: "object", + properties: { + number: { + type: "number", + description: "The 'number' of the pull request (not the id)", + }, + }, + required: ["number"], + }, + async (args) => { const { number: pull_number, context } = args context.log(`github pull comments list ${pull_number}`) diff --git a/packages/core/src/genaisrc/system.math.genai.js b/packages/core/src/genaisrc/system.math.genai.js index 8c82d9d4bd..dbe3fe7c16 100644 --- a/packages/core/src/genaisrc/system.math.genai.js +++ b/packages/core/src/genaisrc/system.math.genai.js @@ -3,16 +3,21 @@ system({ description: "Register a function that evaluates math expressions", }) -defTool("math_eval", "Evaluates a math expression", { - type: "object", - properties: { - expression: { - type: "string", - description: "Math expression to evaluate using mathjs format.", - } +defTool( + "math_eval", + "Evaluates a math expression", + { + type: "object", + properties: { + expression: { + type: "string", + description: "Math expression to evaluate using mathjs format.", + }, + }, + required: ["expression"], }, - required: ["expression"], -}, async (args) => { - const { expression } = args - return "" + (await parsers.math(expression) ?? "?") -}) \ No newline at end of file + async (args) => { + const { expression } = args + return "" + ((await parsers.math(expression)) ?? "?") + } +) diff --git a/packages/core/src/genaisrc/system.user_input.genai.mjs b/packages/core/src/genaisrc/system.user_input.genai.mjs new file mode 100644 index 0000000000..e09bbe02e5 --- /dev/null +++ b/packages/core/src/genaisrc/system.user_input.genai.mjs @@ -0,0 +1,70 @@ +system({ + title: "Tools to ask questions to the user.", +}) + +defTool( + "user_input_confirm", + "Ask the user to confirm a message.", + { + type: "object", + properties: { + message: { + type: "string", + description: "Message to confirm", + }, + }, + required: ["message"], + }, + async (args) => { + const { context, message } = args + context.log(`user input confirm: ${message}`) + return await host.confirm(message) + } +) + +defTool( + "user_input_select", + "Ask the user to select an option.", + { + type: "object", + properties: { + message: { + type: "string", + description: "Message to select", + }, + options: { + type: "array", + description: "Options to select", + items: { + type: "string", + }, + }, + }, + required: ["message", "options"], + }, + async (args) => { + const { context, message, options } = args + context.log(`user input select: ${message}`) + return await host.select(message, options) + } +) + +defTool( + "user_input_text", + "Ask the user to input text.", + { + type: "object", + properties: { + message: { + type: "string", + description: "Message to input", + }, + }, + required: ["message"], + }, + async (args) => { + const { context, message } = args + context.log(`user input text: ${message}`) + return await host.input(message) + } +) diff --git a/packages/sample/genaisrc/blog/genaiscript.d.ts b/packages/sample/genaisrc/blog/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/packages/sample/genaisrc/blog/genaiscript.d.ts +++ b/packages/sample/genaisrc/blog/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/packages/sample/genaisrc/genaiscript.d.ts b/packages/sample/genaisrc/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/packages/sample/genaisrc/genaiscript.d.ts +++ b/packages/sample/genaisrc/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/packages/sample/genaisrc/node/genaiscript.d.ts b/packages/sample/genaisrc/node/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/packages/sample/genaisrc/node/genaiscript.d.ts +++ b/packages/sample/genaisrc/node/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/packages/sample/genaisrc/python/genaiscript.d.ts b/packages/sample/genaisrc/python/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/packages/sample/genaisrc/python/genaiscript.d.ts +++ b/packages/sample/genaisrc/python/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/packages/sample/genaisrc/style/genaiscript.d.ts b/packages/sample/genaisrc/style/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/packages/sample/genaisrc/style/genaiscript.d.ts +++ b/packages/sample/genaisrc/style/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/packages/sample/genaisrc/user-input.genai.mjs b/packages/sample/genaisrc/user-input.genai.mjs new file mode 100644 index 0000000000..f2296ffd3e --- /dev/null +++ b/packages/sample/genaisrc/user-input.genai.mjs @@ -0,0 +1,7 @@ +script({ + system: "system.user_input" +}) + +$`Imagine a funny question and ask the user to answer it. +From the answer, generate 3 possible answers and ask the user to select the correct one. +Ask the user if the answer is correct.` \ No newline at end of file diff --git a/packages/sample/src/aici/genaiscript.d.ts b/packages/sample/src/aici/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/packages/sample/src/aici/genaiscript.d.ts +++ b/packages/sample/src/aici/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/packages/sample/src/errors/genaiscript.d.ts b/packages/sample/src/errors/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/packages/sample/src/errors/genaiscript.d.ts +++ b/packages/sample/src/errors/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/packages/sample/src/genaiscript.d.ts b/packages/sample/src/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/packages/sample/src/genaiscript.d.ts +++ b/packages/sample/src/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/packages/sample/src/makecode/genaiscript.d.ts b/packages/sample/src/makecode/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/packages/sample/src/makecode/genaiscript.d.ts +++ b/packages/sample/src/makecode/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/packages/sample/src/tla/genaiscript.d.ts b/packages/sample/src/tla/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/packages/sample/src/tla/genaiscript.d.ts +++ b/packages/sample/src/tla/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/packages/sample/src/vision/genaiscript.d.ts b/packages/sample/src/vision/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/packages/sample/src/vision/genaiscript.d.ts +++ b/packages/sample/src/vision/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/packages/vscode/genaisrc/genaiscript.d.ts b/packages/vscode/genaisrc/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/packages/vscode/genaisrc/genaiscript.d.ts +++ b/packages/vscode/genaisrc/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = ( diff --git a/slides/genaisrc/genaiscript.d.ts b/slides/genaisrc/genaiscript.d.ts index 09451ff875..d9596b1677 100644 --- a/slides/genaisrc/genaiscript.d.ts +++ b/slides/genaisrc/genaiscript.d.ts @@ -75,6 +75,7 @@ type SystemPromptId = OptionsOrString< | "system.agent_git" | "system.agent_github" | "system.agent_interpreter" + | "system.agent_user_input" | "system.annotations" | "system.changelog" | "system.diagrams" @@ -101,6 +102,7 @@ type SystemPromptId = OptionsOrString< | "system.technical" | "system.tools" | "system.typescript" + | "system.user_input" | "system.zero_shot_cot" > @@ -109,6 +111,7 @@ type SystemToolId = OptionsOrString< | "agent_git" | "agent_github" | "agent_interpreter" + | "agent_user_input" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -137,6 +140,9 @@ type SystemToolId = OptionsOrString< | "retrieval_fuzz_search" | "retrieval_vector_search" | "retrieval_web_search" + | "user_input_confirm" + | "user_input_select" + | "user_input_text" > type FileMergeHandler = (