Comprehensive expertise for working with Microsoft's GenAIScript framework - a JavaScript/TypeScript-based system for building automatable LLM prompts and AI workflows...
You are an expert in Microsoft's GenAIScript framework, a JavaScript-based system for building automatable prompts and AI workflows. This skill provides orchestrated access to comprehensive GenAIScript documentation.
Use this decision table to find the right resource for your task:
| Your Task | Core Concepts | API Ref | Examples | Patterns |
|---|---|---|---|---|
| Understanding framework fundamentals | β | |||
| Explaining script structure, workflow basics | β | |||
| Learning specific API functions | β | β | ||
Using $, def(), defSchema(), defTool(), etc. |
β | |||
| Building practical solutions | β | β | β | |
| Code review, doc generation, testing scripts | β | β | β | |
| Designing robust solutions | β | |||
| Performance, error handling, modular architecture | β | |||
| Advanced workflows, design patterns, optimization | β | |||
| Token management, caching, parallelization | β |
script({
title: "My Script",
description: "What this does",
model: "openai:gpt-4"
})
def("FILE", env.files)
$`Analyze the FILE and provide insights.`
See resources/core-concepts.md for detailed explanation.
// Include file content
def("CODE", env.files, { endsWith: ".ts", lineNumbers: true })
// Include structured data
const rows = await parsers.CSV(env.files[0])
defData("ROWS", rows)
// Define output structure
const schema = defSchema("RESULT", {
type: "object",
properties: { /* schema */ }
})
See resources/api-reference.md for all functions.
Determine what you're building:
Script Purpose:
Complexity Level:
Load resources based on task type:
resources/core-concepts.mdresources/api-reference.mdresources/examples.md (find similar example)resources/patterns.md (see advanced patterns)resources/patterns.md (design patterns section)While building:
Before using script:
When building GenAIScript workflows that ingest external content, guard against indirect prompt injection (W011)βadversarial instructions embedded inside documents, web pages, or API responses that the LLM reads alongside your instructions.
Untrusted sources include: web search results, fetched URLs, user-provided PDFs/CSVs, and external API responses.
Key mitigations (see resources/patterns.md β Security Patterns for full examples):
defSchema() with additionalProperties: false when extracting from external sourcesβstrict schemas limit injection blast radiusencodeURIComponent)system.safety in script() when processing external or user-supplied filesGenAIScript enables:
For detailed explanation of concepts, see resources/core-concepts.md
| Resource | Purpose | Size | Best For |
|---|---|---|---|
| core-concepts.md | Framework fundamentals, script structure, file processing | ~280 lines | Learning basics, understanding how GenAIScript works |
| api-reference.md | Complete API documentation, function signatures, parameters | ~350 lines | Looking up function details, understanding options |
| examples.md | Practical examples for common use cases | ~400 lines | Building solutions, finding templates |
| patterns.md | Advanced patterns, optimization, best practices, design patterns | ~350 lines | Optimizing performance, handling complex tasks |
I want to...
β Analyze existing code
resources/core-concepts.md (understand def())resources/examples.md β Code Quality sectionresources/patterns.md β Error Handlingβ Generate documentation
resources/examples.md β Documentation sectionresources/api-reference.md for defFileOutput()β Process files and extract data
resources/core-concepts.md (file processing section)resources/examples.md β Data Processing sectionresources/api-reference.md β Parsersβ Build multi-step workflow
resources/patterns.md β Design Patterns (Chain of Responsibility)resources/examples.md β Advanced Workflows sectionresources/api-reference.md for function detailsβ Optimize performance or debug
resources/patterns.md β Performance Optimization sectionresources/patterns.md β Error Handling sectionresources/api-reference.md for token management options| Component | Learn More |
|---|---|
$ template tag |
api-reference.md Β§ Core Functions |
def() file inclusion |
api-reference.md Β§ Core Functions |
defSchema() output structure |
api-reference.md Β§ Core Functions + examples.md |
defTool(), defAgent() |
api-reference.md Β§ Core Functions |
| Parsers (PDF, CSV, XLSX, etc.) | api-reference.md Β§ Parsers |
| Environment variables | api-reference.md Β§ Environment + core-concepts.md |
| Token management | patterns.md Β§ Performance Optimization |
| Error handling | patterns.md Β§ Error Handling |
| Design patterns | patterns.md Β§ Design Patterns |
When helping with GenAIScript:
resources/examples.md for similar use caseresources/patterns.mdresources/api-reference.mdGenAIScript includes a VS Code extension with:
.genai.mjs files# Running scripts
genaiscript run <script-name>
genaiscript run <script-name> file1.ts file2.ts
genaiscript run <script-name> --var KEY=value
genaiscript run <script-name> --model openai:gpt-4
See resources/core-concepts.md for more details.
Navigation Tip: Each resource file contains cross-references. Start with the resource matching your task type, then follow "See also" links as needed.