Home/Tools/@tpmjs/tools-recipe-generate-from-grammar

recipeGenerateFromGrammarTool

@tpmjs/tools-recipe-generate-from-grammar

Generate recipes following a grammar/template with rules. Useful for creating structured workflows or recipes from a formal grammar definition. Supports optional seeding for deterministic generation.

Official
agent
v0.2.0
MIT
⚠️

This tool is currently broken

Execution Failed
Runtime error with test parameters
Grammar must have a "start" rule name

Last checked: 1/1/2026, 8:18:51 AM

Interactive Playground

Test @tpmjs/tools-recipe-generate-from-grammar (recipeGenerateFromGrammarTool) with AI-powered execution

0/2000 characters

Installation & Usage

Install this tool and use it with the AI SDK

1. Install the package

npm install @tpmjs/tools-recipe-generate-from-grammar
pnpm add @tpmjs/tools-recipe-generate-from-grammar
yarn add @tpmjs/tools-recipe-generate-from-grammar
bun add @tpmjs/tools-recipe-generate-from-grammar
deno add npm:@tpmjs/tools-recipe-generate-from-grammar

2. Import the tool

import { recipeGenerateFromGrammarTool } from '@tpmjs/tools-recipe-generate-from-grammar';

3. Use with AI SDK

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { recipeGenerateFromGrammarTool } from '@tpmjs/tools-recipe-generate-from-grammar';

const result = await generateText({
  model: openai('gpt-4o'),
  tools: { recipeGenerateFromGrammarTool },
  prompt: 'Your prompt here...',
});

console.log(result.text);

Parameters

Available configuration options

Auto-extracted
grammar
Required
Type: object

Grammar definition with "start" rule name and "rules" object mapping rule names to values (strings, arrays of alternatives, or nested objects)

seed
Optional
Type: string

Optional seed string for deterministic generation

Schema extracted: 1/1/2026, 8:18:51 AM

README

Recipe Generate from Grammar

Generate recipes following a grammar/template system with rules and optional seeding for deterministic generation.

Installation

npm install @tpmjs/tools-recipe-generate-from-grammar

Usage

import { recipeGenerateFromGrammarTool } from '@tpmjs/tools-recipe-generate-from-grammar';

const result = await recipeGenerateFromGrammarTool.execute({
  grammar: {
    start: 'workflow',
    rules: {
      workflow: {
        steps: ['analyze', 'process', 'output']
      },
      analyze: ['parse data', 'validate input'],
      process: ['transform data', 'apply rules'],
      output: ['generate report', 'save results']
    }
  },
  seed: 'deterministic-seed' // Optional
});

console.log(result.recipe);
// {
//   name: 'workflow',
//   steps: [
//     { action: 'analyze', details: 'parse data', order: 0 },
//     { action: 'process', details: 'transform data', order: 1 },
//     { action: 'output', details: 'generate report', order: 2 }
//   ],
//   metadata: { generatedAt: '2025-01-01T00:00:00.000Z', grammarHash: 'abc123...' }
// }

Grammar Format

The grammar is a structured object with:

  • start: Name of the starting rule
  • rules: Object mapping rule names to definitions

Rule definitions can be:

  • String: A literal value or reference to another rule
  • Array: Multiple alternatives (one will be randomly selected)
  • Object: Nested structure that will be expanded

Features

  • Deterministic generation with optional seed
  • Recursive rule expansion
  • Support for nested grammar structures
  • SHA-256 hash of grammar for tracking
  • Automatic step extraction and ordering

Examples

Simple Linear Recipe

const result = await recipeGenerateFromGrammarTool.execute({
  grammar: {
    start: 'recipe',
    rules: {
      recipe: {
        steps: [
          { action: 'prepare', details: 'gather ingredients' },
          { action: 'cook', details: 'apply heat' },
          { action: 'serve', details: 'plate and garnish' }
        ]
      }
    }
  }
});

Branching Recipe with Alternatives

const result = await recipeGenerateFromGrammarTool.execute({
  grammar: {
    start: 'deployment',
    rules: {
      deployment: {
        steps: ['build', 'test', 'deploy']
      },
      build: ['npm build', 'docker build'],
      test: ['unit tests', 'integration tests', 'e2e tests'],
      deploy: ['deploy to staging', 'deploy to production']
    }
  },
  seed: 'build-123' // Same seed = same output
});

Use Cases

  • Generating workflow templates
  • Creating procedural recipes
  • Building test scenarios
  • Generating documentation structures
  • Creating parameterized task lists

License

MIT

Statistics

Downloads/month

0

Quality Score

0%

Bundle Size

NPM Keywords

tpmjs
agent
recipe
grammar
generation

Maintainers

thomasdavis(thomasalwyndavis@gmail.com)

Frameworks

vercel-ai