GenAIScript
- agent-framework
Automatable GenAI Scripting
About
What is GenAIScript?
GenAIScript is a JavaScript toolbox for programmatically assembling prompts and orchestrating LLMs, tools, and data in code. It runs as a Visual Studio Code extension or a command-line tool and is designed for developers who want to treat prompt engineering like software engineering.
How to use GenAIScript?
Install the Visual Studio Code extension or use the command line (npx genaiscript). Write scripts using the $ template tag to create prompts and the def function to include files, data, or schemas. Connect to supported LLM providers—GitHub Copilot, GitHub Models, OpenAI, Azure OpenAI, Anthropic, and local models via Ollama—and run, debug, and test scripts directly in VS Code or from the terminal.
Key features of GenAIScript
- Stylized JavaScript/TypeScript for prompt assembly
- Fast edit, debug, run, and test loop in VS Code
- Reusable, version-controlled script files
- Built-in data schemas with Zod support
- Ingest PDF, DOCX, CSV, XLSX, and more
- File generation with diff preview and refactoring UI
- File search (grep, fuzz) within scripts
- LLM tools and agents, including MCP tools
- Vector search (RAG) built in
- Code interpreter in sandboxed environment
- Docker container execution
- Video processing (transcription, frame extraction)
- LLM composition (run prompts within prompts)
- Prompty format support
- Secret scanning for chat security
- CLI and API for automation
- Responsible AI content safety support
- Pull request reviews (GitHub Actions, Azure DevOps)
- Tests and evals powered by promptfoo
Use cases of GenAIScript
- Generate structured outputs (e.g., JSON) from file analysis
- Classify text or images with custom categories
- Automate pull request reviews with AI comments
- Run code interpretation for data analysis tasks
- Build agents that query repositories or external APIs
FAQ from GenAIScript
What is GenAIScript?
GenAIScript is an open-source JavaScript framework for programmatically building prompts, orchestrating LLMs, and integrating tools and data. It is developed by Microsoft and available on GitHub.
Which LLMs are supported?
GenAIScript supports GitHub Copilot, GitHub Models, OpenAI, Azure OpenAI, Anthropic, and local models via Ollama (e.g., Phi-3). It also supports any OpenAI-compatible endpoint.
How do I install GenAIScript?
You can install the Visual Studio Code extension from the marketplace or use the command line via npx genaiscript after installing Node.js.
Can I use GenAIScript with MCP tools?
Yes. GenAIScript has built-in support for Model Context Protocol (MCP) tools, which can be registered and used in scripts.
What file formats can GenAIScript ingest?
GenAIScript can read text from PDF, DOCX, CSV, XLSX, and plain text files. It can also parse images and audio for transcription.
Details
- Author
- microsoft
- GitHub stars
- 2,633
- Category
- agent-framework
- Repository
- microsoft/genaiscript
GenAIScript
Prompting is Coding
Programmatically assemble prompts for LLMs using JavaScript. Orchestrate LLMs, tools, and data in code.
- JavaScript toolbox to work with prompts
- Abstraction to make it easy and productive
- Seamless Visual Studio Code integration or flexible command line
- Built-in support for GitHub Copilot and GitHub Models, OpenAI, Azure OpenAI, Anthropic, and more
- 📄 Read the ONLINE DOCUMENTATION at microsoft.github.io/genaiscript
- 💬 Join the Discord server
- 📝 Read the blog for the latest news
- 📺 Watch Mr. Maeda's Cozy AI Kitchen
- 🤖 Agents - read the llms-full.txt
---
Hello world
Say to you want to create an LLM script that generates a 'hello world' poem. You can write the following script:
$Write a 'hello world' poem.
The $ function is a template tag that creates a prompt. The prompt is then sent to the LLM (you configured), which generates the poem.
Let's make it more interesting by adding files, data and structured output. Say you want to include a file in the prompt, and then save the output in a file. You can write the following script:
// read files
const file = await workspace.readText("data.txt")
// include the file content in the prompt in a context-friendly way
def("DATA", file)
// the task
$Analyze DATA and extract data in JSON in data.json.
The def function includes the content of the file, and optimizes it if necessary for the target LLM. GenAIScript script also parses the LLM output
and will extract the data.json file automatically.
---
🚀 Quickstart Guide
Get started quickly by installing the Visual Studio Code Extension or using the command line.
---
✨ Features
🎨 Stylized JavaScript & TypeScript
Build prompts programmatically using JavaScript or TypeScript.
def("FILE", env.files, { endsWith: ".pdf" })
$Summarize FILE. Today is ${new Date()}.
---
🚀 Fast Development Loop
Edit, Debug, Run, and Test your scripts in Visual Studio Code or with the command line.
---
🔗 Reuse and Share Scripts
Scripts are files! They can be versioned, shared, and forked.
// define the context
def("FILE", env.files, { endsWith: ".pdf" })
// structure the data
const schema = defSchema("DATA", { type: "array", items: { type: "string" } })
// assign the task
$Analyze FILE and extract data to JSON using the ${schema} schema.
---
📋 Data Schemas
Define, validate, and repair data using schemas. Zod support builtin.
const data = defSchema("MY_DATA", { type: "array", items: { ... } })
$Extract data from files using ${data} schema.
---
📄 Ingest Text from PDFs, DOCX, ...
def("PDF", env.files, { endsWith: ".pdf" })
const { pages } = await parsers.PDF(env.files[0])
---
📊 Ingest Tables from CSV, XLSX, ...
Manipulate tabular data from CSV, XLSX, ...
def("DATA", env.files, { endsWith: ".csv", sliceHead: 100 })
const rows = await parsers.CSV(env.files[0])
defData("ROWS", rows, { sliceHead: 100 })
---
📝 Generate Files
Extract files and diff from the LLM output. Preview changes in Refactoring UI.
$Save the result in poem.txt.
FILE ./poem.txt
The quick brown fox jumps over the lazy dog.
---
🔍 File Search
Grep or fuzz search files.
const { files } = await workspace.grep(/[a-z][a-z0-9]+/, { globs: ".md" })
---
Classify
Classify text, images or a mix of all.
const joke = await classify(
"Why did the chicken cross the road? To fry in the sun.",
{
yes: "funny",
no: "not funny",
}
)
LLM Tools
Register JavaScript functions as tools
(with fallback for models that don't support tools). Model Context Protocol (MCP) tools are also supported.
defTool(
"weather",
"query a weather web api",
{ location: "string" },
async (args) =>
await fetch(https://weather.api.api/?location=${args.location})
)
---
LLM Agents
Register JavaScript functions as tools and combine tools + prompt into agents.
defAgent(
"git",
"Query a repository using Git to accomplish tasks.",
Your are a helpful LLM agent that can use the git tools to query the current repository.
Answer the question in QUERY.
- The current repository is the same as github repository.,
{ model, system: ["system.github_info"], tools: ["git"] }
)
then use it as a tool
script({ tools: "agent_git" })
$Do a statistical analysis of the last commits
See the git agent source.
---
🔍 RAG Built-in
const { files } = await retrieval.vectorSearch("cats", "/.md")
---
🐙 GitHub Models and GitHub Copilot
Run models through GitHub Models or GitHub Copilot.
script({ ..., model: "github:gpt-4o" })
---
💻 Local Models
Run your scripts with Open Source models, like Phi-3, using Ollama, LocalAI.
script({ ..., model: "ollama:phi3" })
---
🐍 Code Interpreter
Let the LLM run code in a sand-boxed execution environment.
script({ tools: ["python_code_interpreter"] })
---
🐳 Containers
Run code in Docker containers.
const c = await host.container({ image: "python:alpine" })
const res = await c.exec("python --version")
---
Video processing
Transcribe and screenshot your videos so that you can feed them efficiently in your LLMs requests.
// transcribe
const transcript = await transcript("path/to/audio.mp3")
// screenshots at segments
const frames = await ffmpeg.extractFrames("path_url_to_video", { transcript })
def("TRANSCRIPT", transcript)
def("FRAMES", frames)
🧩 LLM Composition
Run LLMs to build your LLM prompts.
for (const file of env.files) {
const { text } = await runPrompt((_) => {
_.def("FILE", file)
_.$Summarize the FILE.
})
def("SUMMARY", text)
}
$Summarize all the summaries.
---
🅿️ Prompty support
Run your Prompty files as well!
---
name: poem
---
Write me a poem
---
Pluggable Secret Scanning
Scan your chats for secrets using secret scanning.
{
"secretPatterns": {
...,
"OpenAI API Key": "sk-[A-Za-z0-9]{32,48}"
}
}
⚙ Automate with CLI or API
Automate using the CLI or API.
npx genaiscript run tlaplus-linter ".tla"
import { run } from "genaiscript/api"
const res = await run("tlaplus-linter", ".tla")
---
Safety First!
GenAIScript provides built-in Responsible AI system prompts and Azure Content Safety supports
to validate content safety.
``js wrap
script({ ...,
system: ["system.safety_harmful_content", ...],
contentSafety: "azure" // use azure content safety
})
const safety = await host.contentSafety()
const res = await safety.detectPromptInjection(env.vars.input)
---
💬 Pull Request Reviews
Integrate into your Pull Requests checks through comments, reviews, or description updates. Supports GitHub Actions and Azure DevOps pipelines.
bash wrapnpx genaiscript ... --pull-request-reviews
---
⭐ Tests and Evals
Build reliable prompts using tests and evals powered by promptfoo.
js wrapscript({ ..., tests: {
files: "penguins.csv",
rubric: "is a data analysis report",
facts: "The data refers about penguin population in Antarctica.",
}})
`
---
LLM friendly docs
The entire content of the docs is rendered at https://microsoft.github.io/genaiscript/llms-full.txt in markdown. Feed it directly into your favorite RAG system.
If you are an LLM crawler, add the
.md` suffix to any documentation URLs to get a raw markdown content. For example, https://microsoft.github.io/genaiscript/guides/prompt-as-code.md (note the .md extension)
Contributing
We accept contributions! Checkout the CONTRIBUTING page for details and developer setup.
---
Trademarks
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
trademarks or logos is subject to and must follow
Microsoft's Trademark & Brand Guidelines.
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.






