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
agent Tutorial is Agent
public
ability run(text: String) -> String effects()
tags = text.split(",")
return "{tags.len()} tags: {text}"Syntax explained
-
Use {{ and }}
forliteral braces, \nfora newline and "fora double quote. -
.len()counts Unicode scalar values. Indexes start at 0; negative indexes are unsupported. -
.split(",")uses a literal separator, not a regular expression. The separator must be nonempty; empty fields are preserved.
Build and run
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-1Run with a fresh state directory. The returned value is shown below; the CLI also prints execution information.
"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.