Skip to content
RELKIT
Esc
↑↓navigate↵open⌘Jpreview
On this page

Constants and prompts

Declare shared values with defineConstants and definePrompt, and understand how context resolution works.

Use defineConstants for named JSON values, environment references, or resolver functions. Use definePrompt for nonempty text or an ordered list of text fragments. Both APIs create immutable descriptors; they do not read the environment or call a model during construction.

Scaffold shared values

From an installed application’s root, with an existing orders service, create the values you need:

bun run relkit add constants receipt-settings --service orders
bun run relkit add prompt receipt-policy --service orders \
  --text "Summarize the receipt."

The commands create src/services/orders/constants/receipt-settings.constants.ts and src/services/orders/prompts/receipt-policy.prompt.ts. Constants start with a domain-qualified key and a "replace-me" value; edit that value in source. Repeated --text flags preserve separate prompt segments. Neither artifact becomes a public service member.

Use --create-service orders instead of --service orders if the service does not exist. To create both artifacts, create the service with the first command and use --service orders for the second. For manual setup, define the same descriptors in source as shown below.

See the constants command and prompt command for all flags, then use a prompt in an agent.

Define shared values

/** Declares shared context values and resolves them without starting an HTTP server or model. */
import {
  createApplicationContextResolver,
  defineConstants,
  defineEnv,
  definePrompt,
  env,
} from "@relkit/app";

const environment = defineEnv({ REGION: env.string() });
export const limits = defineConstants(
  { maxItems: 20, region: environment.REGION },
  { id: "orders.constants" },
);
export const supportPrompt = definePrompt(
  ["Answer using the order details.", "Do not invent delivery dates."],
  { id: "support.prompt" },
);

export const contextResolver = createApplicationContextResolver({
  env: { REGION: "eu-west-1" },
  constants: { orders: limits },
  prompts: { support: supportPrompt },
});

limits declares maxItems and a typed environment reference. supportPrompt keeps its two text fragments in order. The explicit IDs remain stable if you move or rename the file. For environment parsing and defaults, read Environment contracts.

Resolve the context

The example also constructs createApplicationContextResolver for a caller that owns context resolution. Call its resolve method with a logger and cancellation signal. It returns constants.maxItems as 20, constants.region as "eu-west-1", and prompts.support as the two text fragments.

Static values are prepared when the resolver is created. Function-valued constants run on each resolution and receive the environment, logger, and cancellation signal. Duplicate constant names across registered descriptors are rejected. These are context-resolution APIs; defineApp does not accept constants or prompts configuration properties.

See defineConstants, definePrompt, and createApplicationContextResolver for their exact contracts. Continue with Invocation context or Build an offline agent.

Reference and source