A long standing feature request has been to run GenAIScript programmatically from other scripts. We are happy to announce that we have released a Node.JS API for GenAIScript. This API allows you to call GenAIScript from other TypeScript scripts (v1.83+).
The run API is meant to mimic the behavior of the GenAIScript CLI. It takes the same arguments as the CLI and returns the same results. This allows you to call GenAIScript from other TypeScript scripts.
The result object contains the full list of messages, and additional parsed information like modified files, diagnostics and so forth.
Don’t mess with my process
On the caller side, the run implementation is a dependency free, side effect free function. It spawns a worker thread where GenAIScript does the work.
No global added
No package loaded
A few hunbred b of memory used
Help us improve it!
Obvisouly this is a first draft and we could do a better job at providing callbacks for progress. Send us your feedback!
Tools is a powerful feature of LLM models
that allows you to augment the LLM reasoning with external tools.
These days, many LLM models come with a built-in support for tools. However, some of them
don’t… like OpenAI’s o1-preview and o1-mini.
Fallback tools
With GenAIScript 1.72.0, we introduce the concept of fallback tools.
Basically, it consists of a system script that “teaches” the LLM model about available tools and how to call them.
A tool example
Here is an example of a tool that generates a random number between 0 and 1.
o1-mini trace (using GitHub Models)
gemma2 model (using Ollama)
Activation
The fallback tool mode is automatically activated for known LLM models that don’t support tools natively. The list is not complete
so open an issue if you stumble upon a model that should have fallback tools enabled.
It can also be activated manually (see documentation).
GenAIScript defines an agent as a tool that
runs an inline prompt to accomplish a task. The agent LLM is typically augmented with
additional tools.
In this blog post, we’ll walk through building a user interaction agent that enables the agent to ask questions to the user.
Let’s dive into understanding how to create an “Agent that can ask questions to the user.”
You can find the full script on GitHub right here.
Metadata
The script is written in JavaScript. It starts by declaring the metadata to make the script available as a system script,
which can be reused in other scripts.
This line sets up the title for our system, making it clear that it’s intended to interact with the user by asking questions.
title and description
The defAgent function defines the behavior of our agent. It takes an agent identifier and a description. These two are quite important,
as they will help the “host” LLM choose to use this agent.
GenAIScript will automatically append a description of all the tools used by the agent prompt so you don’t have to worry about that part in the description.
prompt
The third argument is a string or a function to craft prompt instructions for the agent LLM call. The agent implementation already contains generic prompting
to make the prompt behave like an agent, but you can add more to specify a role, tone, and dos and don’ts.
model configuration
The last argument is a set of model options, similar to runPrompt, to configure the LLM call made by the agent.
In particular, this is where you list the tools that the agent can use.
How to use the agent
The agent is used like any other tool by referencing it in the script options.
Let’s try it!
Let’s try the agent with:
and let’s look at the results…
✔ What would be the most unexpected thing to find inside a refrigerator? toaster
✔ Based on your answer, which of the following would also be unexpected to find inside a refrigerator? A television
✔ Is your selection of ‘A television’ the correct unexpected item to find inside a refrigerator? yes