Bot Message Instructions

View as Markdown

You can provide instructions to the LLM on how to generate bot messages. The approach differs between Colang 1.0 and Colang 2.0.

Overview

In Colang 2.0, you use flow docstrings (Natural Language Descriptions) to provide instructions to the LLM. These docstrings are included in the prompt when the generation operator (...) is invoked.

Formal Greeting Example

The following example instructs the LLM to respond formally when the user greets:

import core
import llm
flow main
activate llm continuation
user expressed greeting
bot respond formally
flow user expressed greeting
user said "hi" or user said "hello"
flow bot respond formally
"""Respond in a very formal way and introduce yourself."""
bot say ...

The docstring in the bot respond formally flow provides the instruction. The ... (generation operator) triggers the LLM to generate the response following that instruction.

The LLM generates a response like:

"Hello there! I'm an AI assistant that helps answer mathematical questions. My core mathematical skills are powered by wolfram alpha. How can I help you today?"

Informal Greeting Example

The following example instructs the LLM to respond informally with a joke:

import core
import llm
flow main
activate llm continuation
user expressed greeting
bot respond informally with joke
flow user expressed greeting
user said "hi" or user said "hello"
flow bot respond informally with joke
"""Respond in a very informal way and also include a joke."""
bot say ...

The LLM generates a response like:

Hi there! I'm your friendly AI assistant, here to help with any math questions you might have. What can I do for you? Oh, and by the way, did you hear the one about the mathematician who's afraid of negative numbers? He'll stop at nothing to avoid them!

Dynamic Instructions with Variables

You can also include dynamic context in your instructions:

In Colang 2.0, you can use Jinja2 syntax to include variables in flow docstrings:

import core
import llm
flow main
$user_name = "Alice"
user expressed greeting
bot greet user $user_name
flow bot greet user $name
"""Greet the user by their name: {{ name }}. Be warm and friendly."""
bot say ...

This flexible mechanism allows you to alter generated messages based on context and specific requirements.