Quickstart

Create your first AI agent in under 5 minutes.

Prerequisites

  • Rust 1.95.0 or later (rustup update stable)
  • A Google API key (get one here)

Step 1: Scaffold Your Project

cargo install cargo-adk
cargo adk new my_agent
cd my_agent

This generates a working project with the right dependencies and boilerplate.

Other Templates

# Agent with custom tools using #[tool] macro
cargo adk new my_agent --template tools

# RAG agent with Gemini embeddings and in-memory vector search
cargo adk new my_agent --template rag

# REST API server ready for deployment
cargo adk new my_agent --template api

# OpenAI GPT-5-mini agent
cargo adk new my_agent --template openai

# A2A protocol agent with builder API
cargo adk new my_agent --template a2a

# Use any provider with any template
cargo adk new my_agent --template tools --provider anthropic

# Add optional addons to any template
cargo adk new my_agent --template tools --addon docker --addon ci
TemplateWhat you get
basicGemini agent with interactive console (default)
toolsAgent with #[tool] macro custom tools + schemars schema generation
ragRAG pipeline — Gemini embeddings, in-memory vector store, document ingestion
apiAxum REST server with health check, ready for docker build
openaiOpenAI GPT-5-mini agent with console
a2aA2A protocol agent with A2aServer builder and agent card
graphGraph-based workflow with checkpoints and durable resume
realtimeReal-time voice/audio streaming agent

Tip: Use the --addon flag to compose templates with optional addons like docker, ci, telemetry, and more. See the Composable Templates page for the full list of 9 addons and 5 enterprise patterns.

Step 2: Add Your API Key

cp .env.example .env
# Edit .env and add your GOOGLE_API_KEY

Step 3: Run

cargo run

That's it — you have a working agent. Chat with it in your terminal.

ADK Console Mode
Agent: my_agent
Type your message and press Enter. Ctrl+C to exit.

> Hello! What can you help me with?

I'm a helpful AI assistant. I can help you with answering questions,
explaining concepts, and having a friendly conversation.

Zero-Config Alternative — adk::run()

If you just want to run a quick agent without scaffolding, use the one-liner:

use adk_rust::run;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    dotenvy::dotenv().ok();
    // Minimal default: set GOOGLE_API_KEY. Add provider features for OpenAI/Anthropic.
    let response = run("You are a helpful assistant.", "Explain Rust in one sentence.").await?;
    println!("{response}");
    Ok(())
}

This handles provider detection for compiled providers, session creation, agent building, and execution in a single call. Great for scripts, prototypes, and quick experiments.


Understanding the Generated Code

The scaffolded src/main.rs:

use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    dotenvy::dotenv().ok();
    let api_key = std::env::var("GOOGLE_API_KEY")?;

    let model = GeminiModel::new(&api_key, "gemini-2.5-flash")?;

    let agent = LlmAgentBuilder::new("my_agent")
        .description("A helpful AI assistant")
        .instruction("You are a friendly assistant. Be concise and helpful.")
        .model(Arc::new(model))
        .build()?;

    Launcher::new(Arc::new(agent)).run().await?;
    Ok(())
}
PartWhat it does
prelude::*Imports core types: GeminiModel, LlmAgentBuilder, Arc, etc.
GeminiModel::new()Creates an LLM client with API key auth and streaming
LlmAgentBuilderBuilder pattern: name, description, instruction (system prompt), model, tools
LauncherRuns the agent in console mode by default; use the api template for HTTP serving

Adding Custom Tools

The fastest way to add tools is the #[tool] macro. Add adk-tool to your dependencies:

[dependencies]
adk-tool = "2.0.0"
schemars = "1"
serde = { version = "1", features = ["derive"] }

Then define a tool — the doc comment becomes the description, the args struct becomes the JSON schema:

use adk_tool::{tool, AdkError};
use schemars::JsonSchema;
use serde::Deserialize;
use serde_json::{json, Value};

#[derive(Deserialize, JsonSchema)]
struct WeatherArgs {
    /// The city to look up
    city: String,
}

/// Get the current weather for a city.
#[tool]
async fn get_weather(args: WeatherArgs) -> std::result::Result<Value, AdkError> {
    Ok(json!({ "temp": 22, "city": args.city, "condition": "sunny" }))
}

The macro generates a GetWeather struct implementing Tool. Add it to your agent:

let agent = LlmAgentBuilder::new("weather_agent")
    .instruction("Use the get_weather tool for weather questions.")
    .model(Arc::new(model))
    .tool(Arc::new(GetWeather))  // Generated by #[tool]
    .build()?;

Tip: Or scaffold a project with tools already set up: cargo adk new my-agent --template tools

Built-in Tools

ADK also includes ready-to-use tools:

// Google Search (handled server-side by Gemini)
.tool(Arc::new(GoogleSearchTool::new()))

// Exit a LoopAgent
.tool(Arc::new(ExitLoopTool::new()))

Running as a Web Server

Scaffold a server project when you want HTTP serving:

cargo adk new my-api --template api
cd my-api
cargo run

The default basic template uses the lightweight console launcher for fastest installs.


Using Other Models

Enable providers via feature flags. The default build stays Gemini-only for fast installs, so add only the provider you need:

[dependencies]
adk-rust = { version = "2.0.0", features = ["openai"] }

Or scaffold with a provider: cargo adk new my-agent --provider openai

OpenAI

let api_key = std::env::var("OPENAI_API_KEY")?;
let model = OpenAIClient::new(OpenAIConfig::new(api_key, "gpt-5-mini"))?;

Anthropic

let api_key = std::env::var("ANTHROPIC_API_KEY")?;
let model = AnthropicClient::new(AnthropicConfig::new(api_key, "claude-sonnet-4-6"))?;

DeepSeek

let api_key = std::env::var("DEEPSEEK_API_KEY")?;
let model = DeepSeekClient::chat(api_key)?;         // standard
// let model = DeepSeekClient::reasoner(api_key)?;   // chain-of-thought

Groq

let api_key = std::env::var("GROQ_API_KEY")?;
let model = GroqClient::new(GroqConfig::llama70b(api_key))?;

Ollama (Local)

// Requires: ollama serve && ollama pull llama3.2
let model = OllamaModel::new(OllamaConfig::new("llama3.2"))?;

Supported Models

ProviderModel ExamplesFeature Flag
Geminigemini-2.5-flash, gemini-2.5-pro, gemini-3-pro-preview(default)
OpenAIgpt-5, gpt-5-mini, gpt-4.1openai
Anthropicclaude-opus-4-7, claude-sonnet-4-6, claude-haiku-4-5anthropic
DeepSeekdeepseek-chat, deepseek-reasonerdeepseek
Groqmeta-llama/llama-4-scout-17b-16e-instruct, llama-3.3-70b-versatilegroq
Ollamaqwen3.6:35b-a3b, qwen3.5, llama3.2:3bollama

Next Steps


Previous: Introduction | Next: LlmAgent