chore: use a Conversation type (#3735)
This commit is contained in:
@@ -3,7 +3,6 @@ use crate::{
|
||||
agents::extension::ExtensionConfig,
|
||||
agents::{extension_manager::ExtensionManager, Agent, TaskConfig},
|
||||
config::ExtensionConfigManager,
|
||||
message::{Message, MessageContent, ToolRequest},
|
||||
prompt_template::render_global_file,
|
||||
providers::errors::ProviderError,
|
||||
};
|
||||
@@ -13,6 +12,8 @@ use mcp_core::handler::ToolError;
|
||||
use rmcp::model::Tool;
|
||||
use serde::{Deserialize, Serialize};
|
||||
// use serde_json::{self};
|
||||
use crate::conversation::message::{Message, MessageContent, ToolRequest};
|
||||
use crate::conversation::Conversation;
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
use tokio::sync::{Mutex, RwLock};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
@@ -41,7 +42,7 @@ pub struct SubAgentProgress {
|
||||
/// A specialized agent that can handle specific tasks independently
|
||||
pub struct SubAgent {
|
||||
pub id: String,
|
||||
pub conversation: Arc<Mutex<Vec<Message>>>,
|
||||
pub conversation: Arc<Mutex<Conversation>>,
|
||||
pub status: Arc<RwLock<SubAgentStatus>>,
|
||||
pub config: TaskConfig,
|
||||
pub turn_count: Arc<Mutex<usize>>,
|
||||
@@ -80,7 +81,7 @@ impl SubAgent {
|
||||
|
||||
let subagent = Arc::new(SubAgent {
|
||||
id: task_config.id.clone(),
|
||||
conversation: Arc::new(Mutex::new(Vec::new())),
|
||||
conversation: Arc::new(Mutex::new(Conversation::new_unvalidated(Vec::new()))),
|
||||
status: Arc::new(RwLock::new(SubAgentStatus::Ready)),
|
||||
config: task_config,
|
||||
turn_count: Arc::new(Mutex::new(0)),
|
||||
@@ -107,7 +108,7 @@ impl SubAgent {
|
||||
&self,
|
||||
message: String,
|
||||
task_config: TaskConfig,
|
||||
) -> Result<Vec<Message>, anyhow::Error> {
|
||||
) -> Result<Conversation, anyhow::Error> {
|
||||
debug!("Processing message for subagent {}", self.id);
|
||||
|
||||
// Get provider from task config
|
||||
@@ -128,7 +129,10 @@ impl SubAgent {
|
||||
}
|
||||
|
||||
// Get the current conversation for context
|
||||
let mut messages = self.get_conversation().await;
|
||||
let mut messages = {
|
||||
let conversation = self.conversation.lock().await;
|
||||
conversation.clone()
|
||||
};
|
||||
|
||||
// Get tools from the subagent's own extension manager
|
||||
let tools: Vec<Tool> = self
|
||||
@@ -156,7 +160,7 @@ impl SubAgent {
|
||||
match Agent::generate_response_from_provider(
|
||||
Arc::clone(provider),
|
||||
&system_prompt,
|
||||
&messages,
|
||||
messages.messages(),
|
||||
&tools,
|
||||
&toolshim_tools,
|
||||
)
|
||||
@@ -264,11 +268,6 @@ impl SubAgent {
|
||||
conversation.push(message);
|
||||
}
|
||||
|
||||
/// Get the full conversation history
|
||||
async fn get_conversation(&self) -> Vec<Message> {
|
||||
self.conversation.lock().await.clone()
|
||||
}
|
||||
|
||||
/// Build the system prompt for the subagent using the template
|
||||
async fn build_system_prompt(&self, available_tools: &[Tool]) -> Result<String, anyhow::Error> {
|
||||
let mut context = HashMap::new();
|
||||
|
||||
Reference in New Issue
Block a user