Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Hello agent

This is the smallest troupekit program. In the hello example we define one agent with #[agent] and run it once. Its doc comment becomes the instructions.

use troupekit::prelude::*;

/// Greet the user by name.
#[agent(model = "openai/gpt-6-luna")]
fn greeter() {}

#[tokio::main]
async fn main() -> Result<(), KitError> {
    println!("{}", greeter().run("I am Ada").await?);
    Ok(())
}

Run it

export OPENAI_API_KEY="sk-..."
cargo run -p troupekit --example hello

The example needs the kit feature, which is on by default, and an OpenAI key.

What happens

  1. greeter() returns an Agent named greeter whose instructions are the doc comment.
  2. run builds it: the selector openai/gpt-6-luna resolves against the catalog and the key is read from OPENAI_API_KEY.
  3. One model call answers, and run returns the text.

Change the model

To try another vendor, change the selector. Any catalog selector works, such as anthropic/claude-haiku-5-5 with ANTHROPIC_API_KEY set. Models and providers lists the vendors.