use llm_agent_runtime::memory::{AgentId, EpisodicStore};
use llm_agent_runtime::runtime::AgentRuntime;
#[tokio::main]
async fn main() {
let runtime = AgentRuntime::quick(5, "echo-model");
let memory = EpisodicStore::new();
let agent_id = AgentId::new("chat-agent");
let turns = vec![
"Hello, who are you?",
"What can you do?",
"Tell me a fun fact.",
];
for user_input in turns {
println!("User: {user_input}");
let context = memory
.recall(&agent_id, 3)
.unwrap_or_default();
let context_prefix = if context.is_empty() {
String::new()
} else {
let lines = context
.iter()
.map(|item| format!("[context] {}", item.content))
.collect::<Vec<_>>()
.join("\n");
format!("{lines}\n\n")
};
let full_prompt = format!("{context_prefix}User: {user_input}");
let session = runtime
.run_agent(agent_id.clone(), &full_prompt, |ctx| async move {
format!("Echo: {ctx}")
})
.await;
let reply = match session {
Ok(ref s) => s
.steps
.last()
.map(|step| step.observation.clone())
.unwrap_or_else(|| "(no response)".to_string()),
Err(ref e) => format!("(error: {e})"),
};
println!("Agent: {reply}\n");
let _ = memory.add_episode(agent_id.clone(), user_input, 0.8);
let _ = memory.add_episode(agent_id.clone(), &reply, 0.7);
}
}