use localharness::{deny_all, Agent, ClosureTool, GeminiAgentConfig, Policy};
use serde_json::json;
#[tokio::main]
async fn main() -> localharness::Result<()> {
let api_key = std::env::var("GEMINI_API_KEY")
.expect("set GEMINI_API_KEY (https://aistudio.google.com/app/apikey)");
let add = ClosureTool::new(
"add",
"Add two integers and return their sum.",
json!({
"type": "object",
"properties": {
"a": { "type": "integer" },
"b": { "type": "integer" }
},
"required": ["a", "b"]
}),
|args, _ctx| async move {
let a = args["a"].as_i64().unwrap_or(0);
let b = args["b"].as_i64().unwrap_or(0);
Ok(json!({ "sum": a + b }))
},
);
let agent = Agent::start_gemini(
GeminiAgentConfig::new(api_key)
.with_system_instructions("You are a calculator. Use the `add` tool to compute sums.")
.with_tool(add)
.with_policies(vec![
deny_all(),
Policy::allow("add"),
Policy::allow("finish"),
]),
)
.await?;
let response = agent.chat("What is 17 plus 25?").await?;
println!("{}", response.text().await?);
agent.shutdown().await?;
Ok(())
}