Skip to content

Strings

Compose text, measure it and split it.

Inside double-quoted strings, {expression} interpolates a value. This example splits comma-separated tags into a list and returns their count.

Complete example

Save the example as strings.aal

strings.aal
agent Tutorial is Agent
  public
    ability run(text: String) -> String effects()
      tags = text.split(",")
      return "{tags.len()} tags: {text}"
Download .aal

Syntax explained

  1. Use {{ and }} for literal braces, \n for a newline and " for a double quote.

  2. .len() counts Unicode scalar values. Indexes start at 0; negative indexes are unsupported.

  3. .split(",") uses a literal separator, not a regular expression. The separator must be nonempty; empty fields are preserved.

Build and run

Terminal
cargo run --locked --bin aalc -- check strings.aal

cargo run --locked --bin aalc -- build strings.aal -o strings.aalc

cargo run --locked --bin aalc -- run strings.aalc \
  --agent Tutorial --ability run \
  --args '{"text":"docs,tools,agents"}' \
  --state-dir .aal-tutorial/strings --invocation strings-1

Run with a fresh state directory. The returned value is shown below; the CLI also prints execution information.

Expected result
"3 tags: docs,tools,agents"

Try it yourself

Set text to docs,tools, and run with a new invocation ID. The count remains 3 because the trailing empty field is preserved.

Language source and specification