AI Agents API Guide
Learn how to work with AI agents using the Wacht Rust SDK.
Prerequisites
Before using any API methods, you must initialize the SDK:
use wacht::WachtClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the client with an API key
let client = WachtClient::new("wk_live_...");
// Now you can use the API
Ok(())
}
List AI Agents
Get all AI agents in your deployment.
Basic List
use wacht::WachtClient;
let client = WachtClient::new("wk_live_...");
// Fetch all agents (default pagination)
let agents = client.ai().list_agents()
.send()
.await?;
for agent in agents.data {
println!("{}: {}", agent.name, agent.description.unwrap_or_default());
}
With Filters
use wacht::WachtClient;
let client = WachtClient::new("wk_live_...");
// Fetch active agents with pagination
let agents = client.ai().list_agents()
.limit(50)
.offset(0)
.is_active(true)
.search("support")
.send()
.await?;
for agent in agents.data {
// Some backend fields might be available in `configuration`
println!("{}", agent.name);
}
Get AI Agent
Retrieve a specific AI agent by ID.
use wacht::WachtClient;
let client = WachtClient::new("wk_live_...");
let agent = client.ai().fetch_agent("agent_123")
.send()
.await?;
println!("Agent: {}", agent.name);
println!("Description: {:?}", agent.description);
Get Agent Details
Retrieve complete details about an AI agent.
use wacht::WachtClient;
let client = WachtClient::new("wk_live_...");
let details = client.ai().fetch_agent_details("agent_123")
.send()
.await?;
println!("Name: {}", details.name);
println!("Configuration: {:?}", details.configuration);
Create AI Agent
Create a new AI agent with custom configuration.
Basic Agent Creation
use wacht::WachtClient;
use wacht::models::CreateAiAgentRequest;
let client = WachtClient::new("wk_live_...");
let agent = client.ai().create_agent(CreateAiAgentRequest::new(
"Support Bot".to_string()
))
.send()
.await?;
println!("Created agent: {}", agent.id);
Agent with Configuration
use wacht::WachtClient;
use wacht::models::CreateAiAgentRequest;
use serde_json::json;
let client = WachtClient::new("wk_live_...");
let mut request = CreateAiAgentRequest::new("Support Bot".to_string());
request.description = Some("Customer support assistant".to_string());
request.configuration = Some(json!({
"model": "gpt-4",
"system_prompt": "You are a helpful support assistant.",
"temperature": 0.7,
"max_tokens": 2000,
"tools": ["tool_123"],
"knowledge_bases": ["kb_789"]
}));
let agent = client.ai().create_agent(request)
.send()
.await?;
Update AI Agent
Modify an existing AI agent’s configuration.
use wacht::WachtClient;
use wacht::models::UpdateAiAgentRequest;
use serde_json::json;
let client = WachtClient::new("wk_live_...");
let mut request = UpdateAiAgentRequest::new();
request.name = Some("Updated Support Bot".to_string());
request.description = Some("Enhanced customer support".to_string());
request.configuration = Some(json!({
"model": "gpt-4-turbo",
"system_prompt": "Updated instructions.",
"temperature": 0.6,
"is_active": true
}));
let updated = client.ai().update_agent("agent_123", request)
.send()
.await?;
Delete AI Agent
Permanently delete an AI agent.
use wacht::WachtClient;
let client = WachtClient::new("wk_live_...");
client.ai().delete_agent("agent_123")
.send()
.await?;
Builder Methods
ListAgentsBuilder
Number of results to return (max 100).
Number of results to skip.
Filter agents by their active status.
Search agents by name or description.
Request Models
CreateAiAgentRequest
An optional description for the agent.
configuration
Option<serde_json::Value>
Arbitrary JSON configuration for the LLM (e.g. model, system_prompt).
UpdateAiAgentRequest
All fields are optional - only include what you want to change:
The updated name of the agent.
configuration
Option<serde_json::Value>
The updated JSON configuration payload.
Error Handling
All SDK methods return a Result<T, Error>:
use wacht::{Error, WachtClient};
let client = WachtClient::new("wk_live_...");
match client.ai().fetch_agent("invalid_id").send().await {
Ok(agent) => println!("Agent: {}", agent.name),
Err(Error::Api { status, message, .. }) => {
eprintln!("API Error {}: {}", status, message);
}
Err(Error::Request(e)) => {
eprintln!("Network error: {}", e);
}
Err(e) => {
eprintln!("Other error: {}", e);
}
}