use letta::client::LettaClient;
use letta::types::*;
use std::env;
fn get_cloud_client() -> LettaClient {
let api_key = env::var("LETTA_API_KEY").expect("LETTA_API_KEY must be set for cloud tests");
LettaClient::cloud(&api_key).unwrap()
}
#[tokio::test]
#[ignore = "Requires cloud API key"]
async fn test_list_templates() {
let client = get_cloud_client();
let result = client.templates().list(None, None, None, None).await;
let response = result.expect("Failed to list templates");
println!("Found {} templates", response.templates.len());
for template in response.templates.iter().take(5) {
println!("Template: {} ({})", template.name, template.id);
assert!(
!template.name.is_empty(),
"Template name should not be empty"
);
assert!(!template.id.is_empty(), "Template ID should not be empty");
}
println!("Has next page: {}", response.has_next_page);
}
#[tokio::test]
#[ignore = "Requires cloud API key and existing agent"]
async fn test_create_template_from_agent() {
let client = get_cloud_client();
let agents = client
.agents()
.list(Some(ListAgentsParams {
limit: Some(1),
..Default::default()
}))
.await;
let agents = agents.expect("Failed to list agents");
if agents.is_empty() {
println!("No agents found to create template from, skipping test");
return;
}
let agent = &agents[0];
println!("Using agent: {} ({})", agent.name, agent.id);
let projects = client.projects().list(None, None, None).await;
let request = match projects {
Ok(proj_response) if !proj_response.projects.is_empty() => {
CreateTemplateRequest {
project: Some(proj_response.projects[0].slug.clone()),
}
}
_ => {
CreateTemplateRequest {
project: Some("default".to_string()),
}
}
};
let result = client
.templates()
.create_from_agent(&agent.id, &request)
.await;
let response = result.unwrap_or_else(|e| {
panic!("Failed to create template from agent: {}", e);
});
println!(
"Created template: {} ({})",
response.template_name, response.template_id
);
assert!(
!response.template_name.is_empty(),
"Template name should not be empty"
);
assert!(
!response.template_id.is_empty(),
"Template ID should not be empty"
);
}
#[tokio::test]
#[ignore = "Requires cloud API key and existing agent"]
async fn test_get_agent_memory_variables() {
let client = get_cloud_client();
let agents = client
.agents()
.list(Some(ListAgentsParams {
limit: Some(1),
..Default::default()
}))
.await;
let agents = agents.expect("Failed to list agents");
if agents.is_empty() {
println!("No agents found, skipping test");
return;
}
let agent = &agents[0];
println!("Using agent: {} ({})", agent.name, agent.id);
let response = client
.get_agent_memory_variables(&agent.id)
.await
.expect("Failed to get agent memory variables");
println!("Memory variables:");
for (key, value) in response.variables.iter() {
println!(" {}: {}", key, value);
assert!(!key.is_empty(), "Variable key should not be empty");
}
assert!(
response.variables.is_empty() || !response.variables.is_empty(),
"Variables should be a valid HashMap"
);
}
#[tokio::test]
#[ignore = "Requires cloud API key and existing template"]
async fn test_create_agents_from_template() {
let client = get_cloud_client();
let templates = client.templates().list(None, None, None, None).await;
let templates = templates.expect("Failed to list templates");
if templates.templates.is_empty() {
println!("No templates found, skipping test");
return;
}
let template = &templates.templates[0];
println!("Using template: {}", template.name);
let project = "default"; let template_version = format!("{}:latest", template.name);
let request = CreateAgentsFromTemplateRequest {
agent_name: Some("Test Agent from Template".to_string()),
tags: Some(vec!["test".to_string(), "from-template".to_string()]),
..Default::default()
};
let result = client
.templates()
.create_agents_from_template(project, &template_version, &request)
.await;
let response = result.unwrap_or_else(|e| {
panic!("Failed to create agents from template: {}", e);
});
println!("Created {} agents from template", response.agents.len());
assert!(
!response.agents.is_empty(),
"Should create at least one agent"
);
for agent in &response.agents {
println!(" Agent: {} ({})", agent.name, agent.id);
assert!(!agent.name.is_empty(), "Agent name should not be empty");
assert!(
!agent.id.as_str().is_empty(),
"Agent ID should not be empty"
);
}
}