Write and use prompts
A prompt is the text that tells a model who it is and what to do. In Cognipeer a prompt is either written inline in an agent or saved as a template under Build → Prompt Studio, where it is versioned, reused by several agents and fetched by the client API. This page covers the writing: the template syntax, the values Cognipeer fills in, and how to build a prompt that is easy to test and keep.
Template syntax
A template is plain text with Mustache tags. The same engine renders the Prompt Studio preview, the render endpoint and an agent's instructions.
| Tag | Meaning |
|---|---|
{{name}} | Inserts the value of name. A dotted name reads inside an object: {{customer.name}}. |
{{#name}}…{{/name}} | A section. It is shown when name is true or not empty, and repeated for each item when name is a list. |
{{^name}}…{{/name}} | An inverted section. It is shown when name is missing, false or empty. |
{{! note }} | A comment. It is dropped from the rendered text. |
A value is inserted exactly as it was given. The text is for a model, not a web page, so &, <, > and quotes are not turned into HTML entities, and {{name}}, {{{name}}} and {{&name}} give the same result.
A variable that nobody fills renders as an empty string. The prompt still runs, it just says less than you wrote, and Cognipeer logs a warning that names the unresolved variables. Check the Live Preview and Rendered Output of the prompt (Template & Preview tab) with sample data before you rely on a variable. The Preview Data (JSON) field takes that sample data.
Optional parts
A section replaces the checkbox-style switches that other tools offer. An optional block shows only when its variable is true or has a value:
Answer the customer's question about {{product}}.
{{#policy}}
Quote this policy where it applies:
{{policy}}
{{/policy}}
{{^policy}}
No policy text was supplied. Do not invent one.
{{/policy}}Where an agent's variables come from
When an agent runs, Cognipeer builds one set of values and renders the prompt with it. Where a name exists in more than one place, the later place wins. From lowest to highest precedence:
- Defaults set on the agent, stored as
config.promptVariablesin the agent's configuration. - Values the caller sends in the call's
runtimeContext.metadata(an API request or an agent-to-agent caller). They fill only placeholders the prompt author wrote; any other key is ignored. - The agent's declared variables, read as
{{variables.name}}. You declare them under Configure → Variables and the caller sends them next to the message. See Variables. - Built-in values, below. They are written last, so a caller cannot forge them.
Built-in values
| Value | Contents |
|---|---|
{{agent.key}}, {{agent.name}}, {{agent.version}} | The agent's key and name, and the version that runs when the run is pinned to one. |
{{now.iso}}, {{now.date}}, {{now.time}} | The current moment as an ISO timestamp, the date (YYYY-MM-DD) and the time (HH:MM:SS). Always UTC, so the same agent does not answer differently depending on the server that handled the call. |
{{user.id}} | The id of the person the run is for, when there is one. |
A call cannot override agent, now or user.
When an inline prompt is rendered
A prompt saved in Prompt Studio is always rendered. A prompt written inline in the agent is rendered only when the agent declares variables, has defaults set, or the text uses a built-in ({{now.date}}, {{agent.name}}, {{user.id}}). Otherwise it is sent as written, so a literal pair of braces in an older prompt stays untouched.
Values from outside
A value that arrives from outside the platform's own callers, such as a webhook trigger's payload or an anonymous agent-to-agent caller, does not fill {{variables.…}} in the instructions: it would read as the author's own words. It reaches the model in the message, in a Variables block. The declared defaults and the values a trigger fixes itself still fill the prompt.
Structure a prompt
These habits make a prompt easier to read, test and change.
- Say what you want, to whom, and what good looks like. "Answer billing questions for small-business customers in at most five sentences" works better than "help with billing".
- Set the role and the audience first. One or two sentences: who the model is, who it talks to, and the purpose.
- Divide long prompts into labelled sections (role, rules, steps, output format). Number steps that have to happen in order and put the most important rule first.
- State the output format. Say the length, the headings or the JSON shape you expect. For machine-read answers use the agent's structured output setting rather than asking for JSON in prose.
- Say what not to do in one place, in plain words. Do not give contradictory instructions in different sections.
- Keep the prompt short enough to maintain. A prompt that repeats itself or runs to thousands of words is hard to test and costs tokens on every call. The System prompt checks card of the cost analysis runs fixed rules on an agent's live prompt: size, repeated paragraphs and sentences, leftover placeholders such as
TODOor an unrendered tag, and dates or ids in the first part of the prompt that defeat prompt caching. See Cost. - Keep per-call data out of the start of the prompt. Put the stable text first and the parts that change last, so cached prefixes stay valid. A date from
{{now.iso}}at the top changes the prefix on every call.
Examples of useful variables
A support agent, with the customer's details declared as agent variables:
You are the support assistant of {{variables.company}}. Today is {{now.date}}.
You are talking to {{variables.customer_name}}{{#variables.plan}}, who is on the {{variables.plan}} plan{{/variables.plan}}.
Answer from the knowledge base. If it does not contain the answer, say so and offer to hand over to a person.
Reply in {{variables.language}}.For a multilingual agent, declare the language as a variable (or let the caller send it) instead of keeping one prompt per language, and name the language in the instruction ("Reply in the customer's language; if unsure, reply in {{variables.language}}"). Keep proper names, product names and code in their original form, and test each language you support with real questions.
Keep prompts manageable
- Name and key. Give each prompt a name that says its job and a stable key. The key is what an agent and the SDK refer to; if you leave it blank, Cognipeer generates one.
- Write a version comment. Every save in Prompt Studio creates a version, and the Version comment ("Summarize what changed in this version") is shown in the version history. A short comment saves a lot of guessing when you roll back.
- Compare before you promote. The Version History tab and the compare view show the difference between two versions. Promote a version through dev and staging before prod, as described in Prompts.
- Discuss changes. The Comments section of the prompt keeps the discussion next to the template.
- Test with a model. The Playground tab sends the rendered template as the system prompt to a model you choose. Try the questions your users really ask, including the awkward ones.
- Measure, then change. Run an evaluation on the agent before and after a prompt change, and change one thing at a time. Let the prompt optimizer suggest improvements when you have test data.
See also
- Prompts: versions, environments and the client API.
- Build and publish an agent: inline prompt or a template from Prompt Studio.
- Prompt optimizer

