use std::sync::Arc;
use oris_runtime::{
agent::{create_agent, DynamicPromptMiddleware},
schemas::messages::Message,
tools::{SimpleContext, ToolContext},
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let dynamic_prompt = DynamicPromptMiddleware::with_template(
"You are a helpful assistant. Address the user as {user_name}. \
The user ID is {user_id}."
.to_string(),
);
let _custom_prompt = DynamicPromptMiddleware::new(|ctx: &dyn ToolContext| {
let user_id = ctx.user_id().unwrap_or("Guest");
format!(
"You are a personalized assistant for user {}. Be friendly and helpful.",
user_id
)
});
let middleware: Vec<Arc<dyn oris_runtime::agent::Middleware>> = vec![Arc::new(dynamic_prompt)];
let agent = create_agent(
"gpt-4o-mini",
&[],
Some("Default system prompt"), Some(middleware),
)?
.with_context(Arc::new(
SimpleContext::new()
.with_user_id("user_123".to_string())
.with_custom("user_name".to_string(), "John".to_string()),
));
let result = agent
.invoke_messages(vec![Message::new_human_message("What's my name?")])
.await?;
println!("Agent response: {}", result);
Ok(())
}