agents_runtime/
lib.rs

1//! Tokio-powered runtime that glues together planners, tools, and prompt packs.
2//! The initial implementation focuses on synchronous message handling with
3//! pluggable state stores and tracing hooks.
4
5use std::sync::Arc;
6
7use agents_core::agent::{AgentDescriptor, AgentHandle};
8use agents_core::messaging::AgentMessage;
9use agents_core::state::AgentStateSnapshot;
10use async_trait::async_trait;
11
12pub mod agent;
13pub mod middleware;
14pub mod planner;
15pub mod prompts;
16pub mod providers;
17
18// Re-export key functions for convenience - now from the agent module
19pub use agent::{
20    create_async_deep_agent, create_deep_agent, get_default_model, ConfigurableAgentBuilder,
21    DeepAgent, SubAgentConfig, SummarizationConfig,
22};
23
24// Re-export provider configurations and models
25pub use providers::{
26    AnthropicConfig, AnthropicMessagesModel, GeminiChatModel, GeminiConfig, OpenAiChatModel,
27    OpenAiConfig,
28};
29
30// Re-export HITL types
31pub use middleware::HitlPolicy;
32
33// Re-export prompt format for TOON support
34pub use prompts::PromptFormat;
35
36/// Default runtime wrapper that delegates to an inner agent implementation.
37pub struct RuntimeAgent<T>
38where
39    T: AgentHandle,
40{
41    inner: Arc<T>,
42}
43
44impl<T> RuntimeAgent<T>
45where
46    T: AgentHandle,
47{
48    pub fn new(inner: Arc<T>) -> Self {
49        Self { inner }
50    }
51}
52
53#[async_trait]
54impl<T> AgentHandle for RuntimeAgent<T>
55where
56    T: AgentHandle + Sync + Send,
57{
58    async fn describe(&self) -> AgentDescriptor {
59        self.inner.describe().await
60    }
61
62    async fn handle_message(
63        &self,
64        input: AgentMessage,
65        state: Arc<AgentStateSnapshot>,
66    ) -> anyhow::Result<AgentMessage> {
67        tracing::debug!(role = ?input.role, "handling message");
68        self.inner.handle_message(input, state).await
69    }
70}