Skip to main content

Asgard built-in helpers

Asgard provides eight helpers for the Handlebars template system.

📖 Handlebars basics
The Handlebars guide is worth reading first for the syntax itself.

Conversation history​

history​

Returns the channel's conversation history over an index range.

{{{history 0 2}}}
<!-- returns the three messages at indexes 0, 1 and 2 -->
{{{history -3 -1}}}
<!-- returns the last three messages -->
{{{history 0 -1}}}
<!-- returns everything -->

Parameters:

  • start: where to start, from 0, with negative values counting from the end
  • end: where to stop, inclusive, with negative values counting from the end

historySize​

Returns how many messages the channel's history holds.

{{{historySize}}} <!-- output: 5 -->

Data handling​

toJson​

Converts any value into a JSON string.

{{{toJson user}}} <!-- turns the user object into a JSON string -->

urlEncode​

URL-encodes a string.

{{{urlEncode 'hello world'}}}
<!-- output: hello%20world -->
{{{urlEncode searchQuery}}}
<!-- URL-encodes a variable -->

xpathExtract​

Looks up a value in an XML document with XPath.

{{{xpathExtract xmlData '/root/item'}}}

Parameters:

  • xml: the XML document
  • path: the XPath query

Example:

<!-- input XML: <root><item>1</item><item>2</item></root> -->
<!-- output: 1\n2 -->

vecToStr​

Converts a vector array into a string.

{{{vecToStr vector '{' '}' ','}}} <!-- [1,2,3] → {1,2,3} -->

Parameters:

  • vector: the vector array
  • prefix: the opening character
  • suffix: the closing character
  • delimiter: the separator

Date and time​

isoNow​

Returns the current date and time in a given timezone, as an RFC3339 string.

{{{isoNow 'Asia/Taipei'}}} <!-- 2025-05-27T01:08:44+08:00 -->

isoToday​

Returns the current date in a given timezone, as an RFC3339 string.

{{{isoToday 'Asia/Taipei'}}} <!-- 2025-05-27 -->

Worked examples​

A system status report​

🤖 System status -
{{{isoNow 'Asia/Taipei'}}}

📊 Conversation length: {{{historySize}}}
messages 📝 Recent messages:
{{{history -3 -1}}}

🔧 System configuration:
{{{toJson systemConfig}}}

Handling an API query​

🔍 Query: {{{urlEncode searchTerm}}}
📄 XML result: {{{xpathExtract responseXml '//result/item'}}}
🔢 Vector: {{{vecToStr embeddings '[' ']' ','}}}
⏰ Processed at: {{{isoNow 'Asia/Taipei'}}}

Good practice​

  1. Conversation history: use history and historySize for context awareness
  2. Safety: always urlEncode anything going into a URL
  3. Timezones: state the timezone explicitly
  4. JSON: use toJson so the output is valid JSON
  5. XML: make sure the XPath is correct
  6. Vectors: pick the delimiter that suits the consumer

These helpers cover conversation history, data conversion and formatting inside a Handlebars template.