TypeScriptPrompts

Prompts

Offer reusable message templates that users can pick

Prompts are reusable instructions your server offers, such as a code review checklist or a support triage script. A client usually lists them in a menu, the user picks one and fills in its arguments, and the prompt's messages go into the conversation.

Basic Prompt Definition

Prompts are defined using the @Prompt decorator on class methods:

import { PromptDecorator as Prompt, ExecutionContext } from '@nitrostack/core';

export class ProductPrompts {
  constructor(private productService: ProductService) {}

  @Prompt({
    name: 'product_review',
    description: 'Generate a structured product review request',
    arguments: [
      {
        name: 'product_id',
        description: 'The product identifier to review',
        required: true
      }
    ]
  })
  async getReviewPrompt(args: { product_id: string }, context: ExecutionContext) {
    const product = await this.productService.findById(args.product_id);

    if (!product) {
      throw new Error(`Product not found: ${args.product_id}`);
    }

    return [
      {
        role: 'user' as const,
        content: {
          type: 'text' as const,
          text: `Please provide a detailed review for: ${product.name}

Product Details:
- Category: ${product.category}
- Price: $${product.price}
- Description: ${product.description}

Review Criteria:
1. Quality and durability
2. Value for money
3. Key features and benefits
4. Potential improvements
5. Overall recommendation`
        }
      }
    ];
  }
}

Prompt topics

On this page