Skip to main content

aster/agents/
identity.rs

1//! Agent 身份配置
2//!
3//! 允许应用层完全控制 Agent 的身份定义,
4//! 而不是使用框架默认的 "aster by Block"。
5
6use serde::Serialize;
7
8/// Agent 身份配置
9///
10/// 应用层通过此结构定义 Agent 的身份信息。
11/// 框架会将身份信息与能力描述分开渲染,确保应用层可以
12/// 完全控制 Agent 的"人设",同时保留框架提供的能力。
13#[derive(Debug, Clone, Serialize)]
14pub struct AgentIdentity {
15    /// Agent 名称(如 "ProxyCast 助手"、"Aster")
16    pub name: String,
17
18    /// 创建者/公司名称(可选)
19    pub creator: Option<String>,
20
21    /// Agent 描述(可选,会显示在身份介绍后)
22    pub description: Option<String>,
23
24    /// 语言偏好(如 "Chinese"、"English")
25    pub language: Option<String>,
26
27    /// 自定义身份提示词(如果设置,会完全替代默认身份模板)
28    pub custom_prompt: Option<String>,
29}
30
31impl Default for AgentIdentity {
32    fn default() -> Self {
33        Self {
34            name: "aster".to_string(),
35            creator: Some("Block".to_string()),
36            description: Some(
37                "aster is being developed as an open-source software project.\n\
38                 aster uses LLM providers with tool calling capability."
39                    .to_string(),
40            ),
41            language: None,
42            custom_prompt: None,
43        }
44    }
45}
46
47impl AgentIdentity {
48    /// 创建新的身份配置
49    pub fn new(name: impl Into<String>) -> Self {
50        Self {
51            name: name.into(),
52            creator: None,
53            description: None,
54            language: None,
55            custom_prompt: None,
56        }
57    }
58
59    /// 设置创建者
60    pub fn with_creator(mut self, creator: impl Into<String>) -> Self {
61        self.creator = Some(creator.into());
62        self
63    }
64
65    /// 设置描述
66    pub fn with_description(mut self, desc: impl Into<String>) -> Self {
67        self.description = Some(desc.into());
68        self
69    }
70
71    /// 设置语言偏好
72    pub fn with_language(mut self, lang: impl Into<String>) -> Self {
73        self.language = Some(lang.into());
74        self
75    }
76
77    /// 设置完全自定义的身份提示词
78    pub fn with_custom_prompt(mut self, prompt: impl Into<String>) -> Self {
79        self.custom_prompt = Some(prompt.into());
80        self
81    }
82}