diff --git a/resources/templates/AGENTS.md b/resources/templates/AGENTS.md new file mode 100644 index 0000000..dced2a0 --- /dev/null +++ b/resources/templates/AGENTS.md @@ -0,0 +1,19 @@ +# Agent Instructions + +You are PicoBot, a personal AI assistant. + +## Personality +- Helpful and friendly +- Concise and to the point +- Proactive when useful, respects user boundaries + +## Values +- Accuracy over speed +- User privacy and safety +- Transparency in actions + +## Communication Style +- Be clear and direct +- Use Chinese or English based on the user's language +- Explain reasoning when helpful +- Ask clarifying questions when needed diff --git a/resources/templates/USER.md b/resources/templates/USER.md new file mode 100644 index 0000000..a915ef5 --- /dev/null +++ b/resources/templates/USER.md @@ -0,0 +1,31 @@ +# 用户配置 + +PicoBot 会根据此文件了解你的偏好。 + +## 基本信息 + +- **称呼**: 用户 +- **时区**: Asia/Shanghai (UTC+8) +- **语言**: 中文 + +## 偏好设置 + +### 回复风格 +- [ ] 简洁扼要 +- [ ] 详细解释 +- [ ] 根据问题自适应 + +### 沟通风格 +- [ ] 随意 +- [ ] 专业 +- [ ] 技术导向 + +## 工作环境 + +- **主要角色**: 开发者 +- **当前项目**: +- **常用工具**: + +--- + +*编辑此文件来定制 PicoBot 的行为偏好。* diff --git a/src/agent/system_prompt.rs b/src/agent/system_prompt.rs index 4076312..e6bd8b5 100644 --- a/src/agent/system_prompt.rs +++ b/src/agent/system_prompt.rs @@ -3,8 +3,11 @@ //! This module provides a modular framework for building system prompts //! using the SystemPromptBuilder pattern. //! -//! Configuration: -//! - USER.md is loaded from ~/.picobot/USER.md (user's personal configuration) +//! Prompt section ordering: Identity → Environment → Tasks → Rules → Capabilities → Dynamic +//! +//! Configuration files loaded from ~/.picobot/: +//! - AGENTS.md — agent identity and behavior +//! - USER.md — user preferences and profile use crate::tools::ToolRegistry; use std::fmt::Write; @@ -42,16 +45,17 @@ impl SystemPromptBuilder { pub fn with_defaults() -> Self { Self { sections: vec![ - Box::new(ToolHonestySection), - Box::new(YourTaskSection), - Box::new(SafetySection), - Box::new(WorkspaceSection), + Box::new(AgentProfileSection), Box::new(UserProfileSection), + Box::new(RuntimeSection), + Box::new(DateTimeSection), + Box::new(WorkspaceSection), + Box::new(YourTaskSection), + Box::new(ToolHonestySection), + Box::new(SafetySection), + Box::new(CrossChannelSection), Box::new(MemorySection), Box::new(HistorySection), - Box::new(DateTimeSection), - Box::new(RuntimeSection), - Box::new(CrossChannelSection), ], } } @@ -202,6 +206,29 @@ impl PromptSection for UserProfileSection { } } +/// Agent profile from ~/.picobot/AGENTS.md. +pub struct AgentProfileSection; + +impl PromptSection for AgentProfileSection { + fn name(&self) -> &str { + "agent_profile" + } + + fn build(&self, _ctx: &PromptContext<'_>) -> String { + let mut output = String::from("## Agent 配置\n\n"); + + if let Some(user_config_dir) = get_user_config_dir() + && let Some(content) = + load_file_from_dir(&user_config_dir, "AGENTS.md", BOOTSTRAP_MAX_CHARS) + { + output.push_str(&content); + return output; + } + + String::new() + } +} + /// Current date and time. pub struct DateTimeSection; diff --git a/src/gateway/mod.rs b/src/gateway/mod.rs index 6e18770..eb15578 100644 --- a/src/gateway/mod.rs +++ b/src/gateway/mod.rs @@ -36,6 +36,9 @@ impl GatewayState { tracing::info!("Using workspace directory: {}", workspace_path.display()); + // Release default AGENTS.md and USER.md to ~/.picobot/ if not exist + ensure_default_config_files(); + // Get provider config for SessionManager let mut provider_config = config.get_provider_config("default")?; // Override workspace_dir with the ensured path @@ -347,3 +350,32 @@ pub async fn run(host: Option, port: Option) -> Result<(), Box