feat(core): Create AgentManager struct

This commit is contained in:
2025-12-26 19:17:27 +01:00
parent 6acb1dc091
commit 1e7c7cd65d
2 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
use std::sync::Arc;
use tokio::sync::Mutex;
use crate::state::AppState;
use llm_core::LlmProvider;
/// Manages the lifecycle and state of the agent
pub struct AgentManager {
client: Arc<dyn LlmProvider>,
state: Arc<Mutex<AppState>>,
}
impl AgentManager {
/// Create a new AgentManager
pub fn new(client: Arc<dyn LlmProvider>, state: Arc<Mutex<AppState>>) -> Self {
Self { client, state }
}
/// Get a reference to the LLM client
pub fn client(&self) -> &Arc<dyn LlmProvider> {
&self.client
}
/// Get a reference to the shared state
pub fn state(&self) -> &Arc<Mutex<AppState>> {
&self.state
}
}
#[cfg(test)]
mod tests {
use super::*;
use llm_core::{LlmProvider, ChatMessage, ChatOptions, Tool, ChunkStream};
use async_trait::async_trait;
struct MockProvider;
#[async_trait]
impl LlmProvider for MockProvider {
fn name(&self) -> &str { "mock" }
fn model(&self) -> &str { "mock" }
async fn chat_stream(
&self,
_messages: &[ChatMessage],
_options: &ChatOptions,
_tools: Option<&[Tool]>,
) -> Result<ChunkStream, llm_core::LlmError> {
unimplemented!()
}
}
#[tokio::test]
async fn test_agent_manager_creation() {
let client = Arc::new(MockProvider);
let state = Arc::new(Mutex::new(AppState::new()));
let manager = AgentManager::new(client.clone(), state.clone());
assert_eq!(manager.client().name(), "mock");
}
}

View File

@@ -2,6 +2,7 @@ mod commands;
mod messages;
mod engine;
mod state;
mod agent_manager;
use clap::{Parser, ValueEnum};
use color_eyre::eyre::{Result, eyre};