Skip to main content

How to read the conversation context

When you build an AI chatbot or an interactive flow in Asgard, understanding the context of a message is what lifts the quality of the response. Whether you are steering a large language model to answer on the basis of what has already been said, or building a flow that remembers, access to the conversation history is not optional.

Asgard gives you two common ways to read what the user has said: prevMessage and history(start, end). Both read the conversation, but they suit different situations and differ in how flexible they are.

This page goes through the syntax of prevMessage and history(start, end), explains why reading the conversation record matters, and shows with examples where it does the real work in a workflow.

prevMessage​

The tutorial on building an echo bot with expressions uses prevMessage as its expression, meaning the bot reads the previous message and sends it back out as the echo.

  • What it does: returns the previous message
  • Simple syntax: easy to use, and it suits a single-turn exchange
  • Example:
prevMessage
  • Where it fits:
    • An echo bot replying with the previous message
    • A quick response to a single command or a one-turn query

history(start, end)​

In the tutorial on building an AI chatbot, the Template mode of the Prompt uses history(0, -1) to pull every message so far in the flow, from the first to the most recent, and hand the full conversation to the nodes that follow. That is what lets the AI generate a reply, keep the logic of the conversation consistent, or record what the user said for later analysis.

  • What it does: returns the whole conversation history, or a section of it
  • Flexible syntax: you give a start and an end position, which suits multi-turn conversations and reasoning over context
  • Examples:
// the full history
history(0, -1)

// the last three messages
history(-3, -1)

// take the previous line as the reference and judge its sentiment
history(-1, -1)
ArgumentWhat it means
0Start at the first message, the oldest
-1Run to the last message, the newest

So history(0, -1) means every message in the conversation so far, the complete record from beginning to end.

  • Where it fits:
    • An LLM chatbot whose answer depends on the context
    • Multi-turn interaction, tasks that need memory, summarising, analysis

Worked examples​

  • When you write an LLM prompt, history(0, -1) passes the whole conversation into the model, so the answer is made with the context in view.
  • Combined with a system prompt it looks like this:
You are a helpful assistant. Here is the conversation so far:
{{ history(0, -1) }}
  • If you only need the most recent message, use prevMessage or history(-1)
Bot: hello!User: How many months in a yearBot: There are 12…User: The Classic…Bot: Japan
01234
-5-4-3-2-1