Skip to main content

Basic Usage

Signature

Type Safety

The @Prompt decorator validates at compile time that the decorated class extends PromptContext. Using it on a plain class produces a descriptive compile error.

Configuration Options

Required Properties

Optional Properties

Argument Definition

Return Format

execute() returns a GetPromptResult, or a string, a message array or an object that the SDK turns into one (see Return Values). The full form is:
The result is checked against this shape. A message with another role, such as 'system', or content that is not a valid content block fails the call with INVALID_OUTPUT.

Text Content

Image Content

Embedded Resource

Function-Based Alternative

Multi-Message Prompts

Context Methods

The PromptContext base class provides:

Full Example

PromptContext

Context class details

PromptRegistry

Prompt registry API

@Tool

Define tools

@Agent

Define agents