Resource Expanders

What are resource expanders?

Resource Expanders are intended to provide a quick and global way to provide web-based data to your LLM prompts and other scripts. For example, if a user mentions a Github repository, a JIRA ticket, or a confluence page, you may want the LLM to be able to use the content from those links as part of it’s response.

Expanders run before any other prompt processing (even Raw Prompt Hooks) and are triggered with a regex match. An expander will be triggered for each match, so you could provide multiple Github links and multiple Jira links and the expanders will execute for each of those matches.

Notice we are saying “execute” and not “fetch”, when an expander triggers, it actually runs a tengo script. This provides maximal flexibility to the bot developer as the content can be manipulated before it is embedded into downstream components.

Expanders make their data available to downstream scripts, and the Prompt template.

While Expanders are global objects, they must be specifically referenced in the bots that make use of them for security purposes.

With the introduction of Expanders, a bot will no longer unwrap a link in the prompt by default, this behaviour must be specified as an expander.

The order in which expanders are executed is the order in which they are added to a bot.

Sample Resource Expander script:

fmt := import("fmt")

link := montagUserMessage

headers := {"x-Montag": "foo"}

// Fetch string (could also use montagGetReadableURL to exclude HTML)
clean := montagMakeHttpRequest("GET", link, headers, "")

// Fetch bytes
raw := montagMakeHttpRequestForBytes("GET", link, headers, "")
uri := link

// The following outputs MUST be present
montagOutputs := {
  "uri": uri,
  "status": clean.status,
  "raw": raw.response,
  "clean": clean.response

With a downstream script, such as a Raw Prompt hook, you can make use of the data like so:

fmt := import("fmt")
for x in montagResources {

montagOverride := "Done"

To access the data in a template, the object is a little different:

{{ range $res := .ExpandedResources }}
URL: {{$res.URI}}
Raw: {{$res.Raw}}
Clean: {{$res.Clean}}
Status: {{$res.Status}}
{{ end }}