use anyhow::Result;
use serde_json::json;
use std::sync::Arc;
use tokio::time::Duration;
use agentor::actor::actor::Actor;
use agentor::actor::system::ActorSystem;
use agentor::agent::agent::{AgentActor, AgentMessage};
use agentor::agent::parser::JsonParser;
use agentor::agent::tool::{CalculatorTool, ToolRegistry};
#[tokio::test]
async fn test_tool_execution_flow() -> Result<()> {
let mut registry = ToolRegistry::new();
registry.register(Box::new(CalculatorTool));
let parser = Arc::new(JsonParser);
let tool_call_prompt = r#"
I will calculate this for you.
```json
{
"tool": "calculator",
"args": {
"expression": "10 + 20"
}
}
```
"#;
let agent = AgentActor::new("math_agent")
.with_tools(registry)
.with_parser(parser);
let mut system = ActorSystem::new("test_system");
let agent_ref = system.spawn_default(Box::new(agent));
agent_ref.tell(AgentMessage::UserPrompt(tool_call_prompt.to_string())).await?;
tokio::time::sleep(Duration::from_millis(100)).await;
agent_ref.tell(AgentMessage::UserPrompt("status check".to_string())).await?;
system.shutdown().await;
Ok(())
}