feat: 添加生成系统环境信息提示词的功能,并在子代理提示词构建中集成
This commit is contained in:
parent
ecd945b309
commit
b364496601
@ -9,5 +9,6 @@ pub use agent_loop::{
|
||||
pub use context_compressor::ContextCompressor;
|
||||
pub use runtime_config::AgentRuntimeConfig;
|
||||
pub use system_prompt::{
|
||||
CompositeSystemPromptProvider, SystemPrompt, SystemPromptContext, SystemPromptProvider,
|
||||
CompositeSystemPromptProvider, generate_system_env_prompt, SystemPrompt, SystemPromptContext,
|
||||
SystemPromptProvider,
|
||||
};
|
||||
|
||||
@ -70,6 +70,31 @@ impl SystemPromptProvider for CompositeSystemPromptProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/// 生成系统环境信息提示词
|
||||
/// 供主智能体和子智能体共享使用
|
||||
pub fn generate_system_env_prompt(config: &crate::config::LLMProviderConfig) -> String {
|
||||
use std::env;
|
||||
use std::env::consts::{ARCH, OS};
|
||||
|
||||
let os_name = match OS {
|
||||
"windows" => "Windows",
|
||||
"linux" => "Linux",
|
||||
"macos" => "macOS",
|
||||
"freebsd" => "FreeBSD",
|
||||
_ => OS,
|
||||
};
|
||||
|
||||
let shell = env::var("SHELL").unwrap_or_else(|_| "unknown".to_string());
|
||||
let cwd = env::current_dir()
|
||||
.map(|p| p.display().to_string())
|
||||
.unwrap_or_else(|_| "unknown".to_string());
|
||||
|
||||
format!(
|
||||
"## 系统环境\n- 操作系统: {}\n- 架构: {}\n- Shell: {}\n- 当前工作目录: {}\n- 模型提供商: {}\n- 模型: {}",
|
||||
os_name, ARCH, shell, cwd, config.name, config.model_id
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
@ -104,26 +103,9 @@ fn strip_comments_and_whitespace(content: &str) -> String {
|
||||
}
|
||||
|
||||
/// 生成系统环境信息提示词
|
||||
/// 使用 agent 模块的共享实现
|
||||
pub(crate) fn generate_system_environment_prompt(config: &LLMProviderConfig) -> String {
|
||||
use std::env::consts::{ARCH, OS};
|
||||
|
||||
let os_name = match OS {
|
||||
"windows" => "Windows",
|
||||
"linux" => "Linux",
|
||||
"macos" => "macOS",
|
||||
"freebsd" => "FreeBSD",
|
||||
_ => OS,
|
||||
};
|
||||
|
||||
let shell = env::var("SHELL").unwrap_or_else(|_| "unknown".to_string());
|
||||
let cwd = env::current_dir()
|
||||
.map(|p| p.display().to_string())
|
||||
.unwrap_or_else(|_| "unknown".to_string());
|
||||
|
||||
format!(
|
||||
"## 系统环境\n- 操作系统: {}\n- 架构: {}\n- Shell: {}\n- 当前工作目录: {}\n- 模型提供商: {}\n- 模型: {}",
|
||||
os_name, ARCH, shell, cwd, config.name, config.model_id
|
||||
)
|
||||
crate::agent::generate_system_env_prompt(config)
|
||||
}
|
||||
|
||||
fn persist_memory_summary(path: &Path, markdown_body: &str) -> Result<(), AgentError> {
|
||||
|
||||
@ -1,19 +1,23 @@
|
||||
use super::types::SubagentType;
|
||||
use crate::config::LLMProviderConfig;
|
||||
|
||||
/// 子代理系统提示词构建器
|
||||
pub struct SubagentPromptBuilder;
|
||||
|
||||
impl SubagentPromptBuilder {
|
||||
/// 构建子代理系统提示词
|
||||
/// 构建子代理系统提示词(包含系统环境信息)
|
||||
pub fn build(
|
||||
subagent_type: SubagentType,
|
||||
description: &str,
|
||||
_prompt: &str,
|
||||
config: &LLMProviderConfig,
|
||||
) -> String {
|
||||
match subagent_type {
|
||||
let base_prompt = match subagent_type {
|
||||
SubagentType::General => Self::build_general_prompt(description),
|
||||
SubagentType::Explore => Self::build_explore_prompt(description),
|
||||
}
|
||||
};
|
||||
let env_info = crate::agent::generate_system_env_prompt(config);
|
||||
format!("{}\n\n{}", base_prompt, env_info)
|
||||
}
|
||||
|
||||
/// 构建恢复任务的提示词
|
||||
|
||||
@ -281,6 +281,7 @@ impl SubAgentRuntime for DefaultSubAgentRuntime {
|
||||
task.subagent_type,
|
||||
&task.description,
|
||||
&task.prompt,
|
||||
&self.provider_config,
|
||||
);
|
||||
|
||||
// 5. 创建子代理
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user