Skip to main content

codetether_agent/agent/
core.rs

1//! Core agent state and construction.
2//!
3//! This module defines the main `Agent` struct and its constructor. Execution,
4//! tool dispatch, and swarm integration live in separate submodules.
5//!
6//! # Examples
7//!
8//! ```ignore
9//! let agent = Agent::new(info, provider, tools, "system".into());
10//! ```
11
12use crate::config::PermissionAction;
13use crate::provider::Provider;
14use crate::tool::ToolRegistry;
15use std::collections::HashMap;
16use std::sync::Arc;
17
18use super::{AgentInfo, ToolMetadata};
19
20/// Stateful runtime for executing prompts with tools and a provider.
21///
22/// An `Agent` owns the provider, tool registry, and permission metadata used
23/// while serving a session.
24///
25/// # Examples
26///
27/// ```ignore
28/// let agent = Agent::new(info, provider, tools, "system".into());
29/// ```
30pub struct Agent {
31    /// Static metadata describing the agent.
32    pub info: AgentInfo,
33    /// Provider used for model completions.
34    pub provider: Arc<dyn Provider>,
35    /// Tool registry available to the agent.
36    pub tools: ToolRegistry,
37    /// Per-tool permission policy for audit and enforcement.
38    pub permissions: HashMap<String, PermissionAction>,
39    /// Metadata for registered tools.
40    pub metadata: HashMap<String, ToolMetadata>,
41    pub(super) system_prompt: String,
42}
43
44impl Agent {
45    /// Constructs a new agent from provider, tool, and prompt state.
46    ///
47    /// The agent starts with empty permission and metadata maps so callers can
48    /// customize them after construction.
49    ///
50    /// # Examples
51    ///
52    /// ```ignore
53    /// let agent = Agent::new(info, provider, tools, "system".into());
54    /// ```
55    pub fn new(
56        info: AgentInfo,
57        provider: Arc<dyn Provider>,
58        tools: ToolRegistry,
59        system_prompt: String,
60    ) -> Self {
61        Self {
62            info,
63            provider,
64            tools,
65            permissions: HashMap::new(),
66            metadata: HashMap::new(),
67            system_prompt,
68        }
69    }
70}