openai_agents_rust/agent/
mod.rs1pub mod configured;
2pub mod runner;
3pub mod runtime;
4pub mod traits;
5pub mod types;
6
7pub use runner::{Runner, ToolUseBehavior};
8pub use runtime::AgentRuntime;
9pub use traits::{Agent, AgentContext};
10pub use types::AgentConfig;
11
12use async_trait::async_trait;
13
14use crate::{error::AgentError, model::Model, model::openai_chat::OpenAiChat};
15
16pub struct EchoAgent {
18 model: Box<dyn Model>,
19}
20
21impl EchoAgent {
22 pub fn new(model: Box<dyn Model>) -> Self {
23 Self { model }
24 }
25}
26
27#[async_trait]
28impl Agent for EchoAgent {
29 async fn run(&self, _ctx: &AgentContext) -> Result<(), AgentError> {
30 let response = self.model.generate("Hello from EchoAgent").await?;
31 tracing::info!("EchoAgent response: {}", response);
32 Ok(())
33 }
34}
35
36pub fn register_default_agent(runtime: &mut AgentRuntime) {
38 let model = Box::new(OpenAiChat::new((*runtime.config).clone()));
39 let agent = EchoAgent::new(model);
40 runtime.register(agent);
41
42 let rt_model = crate::model::openai_realtime::OpenAiRealtime::new((*runtime.config).clone());
44 let configured = crate::agent::configured::ConfiguredAgent::new("configured", rt_model);
45 runtime.register(configured);
46}