Expressions and templates¶
At various places in the configuration of blocks, you can write expressions. Expressions use a simple variant of the CEL langauge.
Some fields in the UI accept a CEL expression (e.g. setting state entries, defining exit conditions) whereas other fields accept a string containing CEL templates (e.g. instructions for core loop and LLM request blocks)
An expression is a snippet of CEL that will be evaluated, such as state.x + state.y
A templated string is a string that can contain placeholders which contain CEL expressions, for example Always answer the user in {{state.language}}
CEL expressions¶
CEL is a simple expression language that uses a Python-like expression syntax, with some custom functions and variables tailored to Structured Visual Agents.
Data types: number, string, list, dictionary (as in Python)
Boolean operators:
and,or,notComparison operators:
==,!=,<,<=,>,>=Numerical operators:
+,-,*,/,mod,powRegular parentheses for operator precedence
String functions:
upper,lower,trim,matches(regex)Dict and list functions:
len,lengthList functions:
sumConversion functions:
string,str,intJSON functions:
to_json(dict -> str or list -> str),parse_json(str -> list or str -> dict)
Within a CEL expression the following variables are available:
state, a dictionaryscratchpad, a dictionarycontext, a dictionarylast_output, a string containing the text output of the last block
Advanced variables: initial_messages - messages passed into this turn generated_messages - messages generated during this turn all_messages - (initial_messages + generated_messages)
CEL templates¶
CEL templates contain CEL expressions delimited by {{ }}. They are usable in most “Instructions”-type fields
Jinja¶
Jinja is an alternative templating language, with more power than CEL.
It is usable in the Emit Output block and in the Generate Artifact block.
An example of using Jinja to generate an agent response, using Markdown that can be rendered in the DSS chat interface:
<hr>
Messages:
{% for message in all_messages %}
{{ message }}
{% endfor %}
<hr>
State:
{% for key, value in state.items() | sort %}
```
{{ key }}: {{ value }}
```
{% else %}
(empty)
{% endfor %}