Edit

Output modes and templates

Set the output once on the conversation, or for one message:

{
  "agent": "atlas",
  "output": {
    "mode": "json",
    "json_schema": { "type": "object", "properties": { "summary": { "type": "string" } }, "required": ["summary"] },
    "template": { "source": "<p>{{output.summary}}</p>", "format": "html" }
  }
}

POST /conversations/{id}/messages accepts the same output object to override it for that message only.

modeYou get
viewsText deltas plus view events for structured data. The default when the agent supports views.
markdownText only. Views are turned into their Markdown fallback and streamed as text. Good for chat apps, email, Slack.
jsonText while the agent works, then an output event with an object that matches your json_schema.

An agent's supported modes are in its output_modes; asking for another one is refused.

JSON

In json mode the agent answers as usual (it can still call tools and ask for approvals), then the server turns its answer into an object that must validate against your schema.

  1. The answer is converted to JSON and validated.
  2. If it fails, the model gets the validation errors and tries again.
  3. After 3 attempts the server stops and sends what it has.

The output event, and the message's output, tell you how it went:

{
  "type": "output",
  "conversation_id": "agconv_1",
  "message_id": "agmsg_5",
  "format": "json",
  "data": { "summary": "3 courses are below 30% completion", "courses": [{ "uuid": "course_x", "rate": 22 }] },
  "valid": true,
  "attempts": 1,
  "errors": []
}

When valid is false, errors lists what was still wrong after the last attempt, and an error event with code output_invalid comes before message.done. Always check valid before using data.

Supported schema keywords

The schema is a subset of JSON Schema:

KeywordNotes
typeobject, array, string, number, integer, boolean, null, or a list of these
properties, required, additionalPropertiesadditionalProperties is a boolean
itemsOne schema for every item
enum, const
minLength, maxLength, pattern
minimum, maximum
minItems, maxItems
anyOf
$defs and local $ref"$ref": "#/$defs/Course"
description, title, defaultDescriptions are shown to the model: use them to explain fields

A schema over 16 KB, nested deeper than 8 levels, or using another keyword is refused with 422 invalid_schema.

{
  "type": "object",
  "additionalProperties": false,
  "required": ["summary", "courses"],
  "properties": {
    "summary": { "type": "string", "maxLength": 280, "description": "One sentence for a dashboard tile" },
    "courses": {
      "type": "array",
      "maxItems": 10,
      "items": { "$ref": "#/$defs/Course" }
    }
  },
  "$defs": {
    "Course": {
      "type": "object",
      "required": ["uuid", "rate"],
      "properties": {
        "uuid": { "type": "string", "pattern": "^course_" },
        "rate": { "type": "number", "minimum": 0, "maximum": 100 },
        "risk": { "enum": ["low", "medium", "high"] }
      }
    }
  }
}

Templates

A template turns a reply into HTML, Markdown or plain text on the server, so you can drop it into an email, a widget or a CMS without writing a renderer. The result comes as a rendered event and in the message's rendered.

{ "source": "<h2>{{conversation.title}}</h2>{{#output.courses}}<p>{{uuid}}: {{rate}}%</p>{{/output.courses}}", "format": "html" }

Syntax

Templates use a small part of Mustache. Nothing in a template can run code.

TagDoes
{{name}}The value, escaped for the format
{{a.b.c}}A nested value
{{.}}The current item inside a section
{{#list}}…{{/list}}Repeats for each item of a list. With an object, renders once with it as context. With any other truthy value, renders once.
{{^x}}…{{/x}}Renders when x is missing, false or an empty list
{{! note }}A comment, not rendered

There are no partials, no lambdas, and no unescaped output: {{{x}}} and {{&x}} are refused with 422 invalid_template.

Escaping

Every value is escaped for the template's format:

formatEscaping
htmlHTML entities (<, >, & and quotes)
markdownMarkdown special characters are backslash-escaped, so a value can't add links, images or formatting
textNone

Only the template's own text is trusted. Text the model wrote (or a learner typed) can't inject tags. A text result is not escaped at all: don't put it into HTML yourself.

Data

Variable
textThe reply's text (Markdown)
viewsThe views, as in Views
citationsThe citations
outputThe JSON output in json mode, else null
planThe plan steps, or null
suggestionsFollow-up prompts
conversationid, title, metadata, external_user_id
messageid, status

Limits

The source can be up to 20 KB, the result up to 200 KB, and sections can nest 8 deep.

HTML example

<div class="lh-answer">
  <p>{{text}}</p>
  {{#citations}}
    <a href="https://learn.your-school.com{{url}}">[{{index}}] {{title}}</a>
  {{/citations}}
  {{^citations}}<p>No sources.</p>{{/citations}}
</div>

text is inserted as escaped text, not as rendered Markdown. If you want formatting in HTML, render text with your own Markdown renderer instead, or use json mode with fields you lay out yourself.

Markdown example

## Weekly report for {{conversation.metadata.workspace}}

{{output.summary}}

{{#output.courses}}
- {{uuid}}: {{rate}}% ({{risk}})
{{/output.courses}}

Values like a course name with * or [ in it stay literal: they are escaped.

Previewing

POST /templates/render renders a template with data you pass, without calling the agent and without using credits. Use it to build and test templates:

curl -X POST $LH/templates/render \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{
    "template": { "source": "Hello {{name}}!", "format": "html" },
    "data": { "name": "<Ana>" }
  }'
# {"format": "html", "content": "Hello &lt;Ana&gt;!"}

Errors in the template answer 422 invalid_template with the reason in message.

The same template can be set on the conversation and changed per message through output.template.