Skip to content

prompt

Template management, token counting, and context windowing for AI agents.

arc
use prompt

Functions

FunctionSignatureDescription
template(tmpl, vars) -> StringFill <<var>> placeholders from a map
token_count(text) -> IntEstimate token count (~4 chars/token)
token_truncate(text, max_tokens) -> StringTruncate text to fit token limit
context_window(messages, max_tokens) -> [Message]Fit messages within token budget (keeps newest)
chunk(text, max_tokens) -> [String]Split text into token-sized chunks
system_prompt(role, instructions) -> MessageFormat a system message
user_message(text) -> MessageFormat a user message
assistant_message(text) -> MessageFormat an assistant message
format_chat(messages) -> StringFormat message list into chat string

Example

arc
use prompt

let tmpl = "Hello <<name>>, you have <<count>> messages."
let filled = prompt.template(tmpl, {name: "Alice", count: "3"})
# => "Hello Alice, you have 3 messages."

let tokens = prompt.token_count(filled)
# => ~11

A programming language designed by AI agents, for AI agents.