Prompts

Fetch in production

Fetch a prompt with get, fill it with compile, pick a label or an exact version, and keep the fetch off your critical path with caching and a fallback.

Your app needs two calls: get fetches a prompt by name, and compile fills in its variables. get goes over the network but is cached; compile runs in your process. This page covers both, how to choose a version, and what happens when Trodo can't be reached.

get and compile

Call init once at startup, then fetch and compile wherever you build a model call. Fetch per request rather than once at startup: the cache makes repeat calls free, and it is how a label move reaches your app.

import trodo from 'trodo-node';

trodo.init({ siteId: process.env.TRODO_SITE_ID! });

const prompt = await trodo.prompts.get('refund-agent');
const { messages, model, tools, response_format } = prompt.compile({
  company: 'Acme',
  question: 'Where is my refund?',
});
import os
import trodo

trodo.init(site_id=os.environ["TRODO_SITE_ID"])

prompt = trodo.get_prompt("refund-agent")
compiled = prompt.compile(company="Acme", question="Where is my refund?")
# compiled.messages, compiled.model, compiled.tools, compiled.response_format

get returns the whole prompt: its messages with the {{variables}} still in them, its model config, tools, output format, variables, and which version it is. compile fills the variables into the messages and returns them with the model config, tools and output format unchanged. It never calls a model. See Variables for what it accepts and Model, tools & output format for passing the rest to your provider.

Choose a version

You passYou get
nothingThe version labelled production, or the newest version if none has that label yet.
labelThe version that label is on now, such as staging.
versionThat exact version, by hash (full, or a short prefix such as f25a4d) or by number.
await trodo.prompts.get('refund-agent');                          // production
await trodo.prompts.get('refund-agent', { label: 'staging' });
await trodo.prompts.get('refund-agent', { version: 'f25a4d' });   // pinned, never moves
trodo.get_prompt("refund-agent")                       # production
trodo.get_prompt("refund-agent", label="staging")
trodo.get_prompt("refund-agent", version="f25a4d")     # pinned, never moves

Pass label or version, not both. Follow a label to ship by moving it; pin a version when a result has to be reproducible, such as a test or a frozen integration. The version you got is on the prompt as versionHash (Python version_hash).

A label or version that doesn't exist on the prompt throws at once, with code set to label_not_found, version_not_found or no_versions (the prompt has never been saved). That is a mistake in your code, so it is never covered by the cache or the fallback below.

A/B test two versions

A label is read on every fetch, so you can split traffic in your own code: put prod-a and prod-b on two versions and choose per request.

const label = Math.random() < 0.5 ? 'prod-a' : 'prod-b';
const prompt = await trodo.prompts.get('refund-agent', { label });
label = "prod-a" if random.random() < 0.5 else "prod-b"
prompt = trodo.get_prompt("refund-agent", label=label)

Each span records which version it ran, so you can compare the two in Traces, with evals, or in each version's ⋯ → Usage.

Caching and fallback

A prompt fetch sits on your request path, so it must never take your app down. Each get works down this list:

Fresh cache. Fetched within the last 60 seconds: returned with no network call.

Stale cache. Older than that: returned at once, and refreshed in the background for the next call.

Fetch. Nothing cached: fetched from Trodo, with up to 2 retries.

Fallback. Nothing cached and Trodo can't be reached: the fallback you passed is used, and the prompt's isFallback (Python is_fallback) is true.

Error. No cache and no fallback: get throws (Python raises LookupError).

Each label and each pinned version is cached separately. Moving a label reaches running apps within one cache window: lower cacheTtlSeconds (Python cache_ttl_seconds) for faster changes, raise it for fewer fetches, or set it to 0 to fetch every time, which helps in development.

The fallback is a minimal prompt: messages, and optionally model and variables. Log when it was used: a span that ran it is marked as a fallback in Traces.

const prompt = await trodo.prompts.get('refund-agent', {
  cacheTtlSeconds: 60,
  fallback: {
    messages: [
      { role: 'system', content: [{ type: 'text', text: 'You are a refund support agent.' }] },
      { role: 'user', content: [{ type: 'text', text: '{{question}}' }] },
    ],
    variables: [{ name: 'question' }],
  },
});

if (prompt.isFallback) logger.warn('refund-agent: running on the fallback prompt');
prompt = trodo.get_prompt(
    "refund-agent",
    cache_ttl_seconds=60,
    fallback={
        "messages": [
            {"role": "system", "content": [{"type": "text", "text": "You are a refund support agent."}]},
            {"role": "user", "content": [{"type": "text", "text": "{{question}}"}]},
        ],
        "variables": [{"name": "question"}],
    },
)

if prompt.is_fallback:
    logger.warning("refund-agent: running on the fallback prompt")

List prompts

list returns every prompt in your team without its messages: name, description, newest version number, labels, and when it changed. It returns an empty list on error instead of throwing.

const prompts = await trodo.prompts.list();
prompts = trodo.list_prompts()

On this page