Skip to main content

hello_world/
hello_world.rs

1use antigravity_sdk_rust::agent::Agent;
2use tracing_subscriber::EnvFilter;
3
4#[tokio::main]
5async fn main() -> Result<(), anyhow::Error> {
6    // Initialize tracing subscriber to print info/debug logs by default
7    tracing_subscriber::fmt()
8        .with_env_filter(EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into()))
9        .init();
10
11    // Load environment variables from .env file if present
12    dotenvy::dotenv().ok();
13
14    // Check if the user specified a binary path or check the environment variable
15    let harness_path = std::env::var("ANTIGRAVITY_HARNESS_PATH").ok();
16    let api_key = std::env::var("GEMINI_API_KEY").ok();
17
18    let mut builder = Agent::builder();
19    if let Some(path) = harness_path {
20        builder = builder.binary_path(path);
21    }
22    if let Some(key) = api_key {
23        builder = builder.api_key(key);
24    }
25
26    let agent = builder
27        .default_model("gemini-3.5-flash")
28        .allow_all()
29        .build();
30
31    println!("Starting agent...");
32    let agent = agent.start().await?;
33
34    let prompt = "Say 'Hello World!'";
35    println!("  User: {}", prompt);
36
37    let response = agent.chat(prompt).await?;
38    println!("  Agent: {}", response.text);
39
40    agent.stop().await?;
41    Ok(())
42}