Agents

First-class AI agent primitives built into the language. Define tools, configure agents, and build AI-powered applications natively.

Turbo is the first compiled language with agent and tool fn as language-level keywords. No frameworks, no SDKs -- agents are part of the type system.

Tool Functions

Define functions that an AI agent can call with the tool fn keyword:

tool fn search(q: str) -> str {
    "found: {q}"
}

tool fn calc(x: i64) -> i64 {
    x * 2
}

fn main() {
    // Tool functions can also be called directly
    print(search("turbo"))    // found: turbo
    print(calc(21))           // 42
}

The Agent Keyword

Define an agent with a model, system prompt, and a set of tools:

tool fn search(q: str) -> str { "found: {q}" }
tool fn calc(x: i64) -> i64 { x * 2 }

agent Helper {
    model: "claude-sonnet"
    tools: [search, calc]
    system: "You are a helpful assistant."
}

fn main() {
    let a = Helper {}
    print(a.model)     // claude-sonnet
}

Agent Fields

Agents expose their configuration as fields:

FieldTypeDescription
modelstrThe model identifier (e.g. "claude-sonnet")
systemstrThe system prompt
tools[fn]Array of tool functions available to the agent

Multi-Agent Patterns

Define multiple specialized agents that work together:

tool fn web_search(q: str) -> str { "results for: {q}" }
tool fn summarize(text: str) -> str { "summary of: {text}" }
tool fn write_code(spec: str) -> str { "code for: {spec}" }

agent Researcher {
    model: "claude-sonnet"
    tools: [web_search, summarize]
    system: "You research topics thoroughly."
}

agent Coder {
    model: "claude-sonnet"
    tools: [write_code]
    system: "You write clean, tested code."
}

fn main() {
    let researcher = Researcher {}
    let coder = Coder {}
    print(researcher.model)    // claude-sonnet
    print(coder.model)         // claude-sonnet
}

Why Language-Level Agents?

  • Type-checked tools -- The compiler validates that agent tools exist and are marked with tool fn
  • Auto-generated schemas -- Tool function signatures are automatically converted to JSON schemas for LLM calling
  • Static validation -- Agent configurations are checked at compile time, not runtime
  • No SDK dependency -- Agents are a language primitive, not a library import