Skip to content

Completers as a first class option in Prompts #1474

@mattzcarey

Description

@mattzcarey

One thought for a potential follow-up: now that the SDK is moving to schema-library-agnostic types, the completable() API could be simplified to decouple it from Zod entirely.

Instead of embedding completion callbacks inside schema objects (which requires Zod-specific introspection to extract), completers could be passed explicitly in the prompt config:

server.registerPrompt('greeting', {
  argsSchema: type({ name: 'string', language: 'string' }),  // any library
  completers: {
    name: (value) => ['Alice', 'Bob'].filter(n => n.startsWith(value)),
    language: (value) => ['en', 'fr'].filter(l => l.startsWith(value))
  }
}, callback);

The type simplifies too, since completion values are always strings over the wire:

type CompleteCallback = (
  value: string,
  context?: { arguments?: Record<string, string> }
) => string[] | Promise<string[]>;

This PR already does most of the internal plumbing — RegisteredPrompt stores completers?: Map<string, CompleteCallback>. The remaining step would be accepting them in the config directly, which would let us deprecate completable(), extractCompleters, and the Zod-specific helpers (getZodSchemaShape, unwrapZodOptionalSchema, etc.).

Not suggesting this as a blocker for this PR — just flagging as a natural follow-up that would complete the schema-agnostic story.

Originally posted by @felixweinberger in #1473 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions