use wasm_agent::{AgentConfig, LoopRunner, ReActStep, ToolRegistry, ToolSpec};
use wasm_agent::types::ToolResult;
fn main() -> Result<(), wasm_agent::AgentError> {
let mut tools = ToolRegistry::new();
tools.register(
ToolSpec::new("capital", "Returns the capital of a country", r#"{"type":"string"}"#),
Box::new(|country: &str| ToolResult {
tool_name: "capital".into(),
output: if country == "France" { "Paris".into() } else { "unknown".into() },
success: true,
}),
)?;
let config = AgentConfig { recover_from_errors: true, ..Default::default() };
let mut runner = LoopRunner::new(&config, &tools).with_system_prompt();
runner.ask("What is the capital of France?");
runner.step("Thought: I should look it up.\nAction: capital(France)")?;
match runner.step("Final Answer: Paris")? {
ReActStep::FinalAnswer(answer) => println!("answer: {answer}"),
other => println!("not done: {other:?}"),
}
print!("{}", runner.transcript());
Ok(())
}