feat(agent): add communication style setting to profile

- Add AgentStyle type with 6 preset options (professional, friendly, etc.)
- Add getStyle/setStyle methods to ProfileManager
- Update soul.md template to include style section
- Add reloadSystemPrompt support for style changes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Jiang Bohan 2026-02-04 14:42:23 +08:00
parent 1dc7539018
commit 4df39448be
4 changed files with 96 additions and 0 deletions

View file

@ -177,6 +177,20 @@ export class AsyncAgent {
this.agent.setUserContent(content);
}
/**
* Get agent communication style from profile config.
*/
getAgentStyle(): string | undefined {
return this.agent.getAgentStyle();
}
/**
* Update agent communication style in profile config.
*/
setAgentStyle(style: string): void {
this.agent.setAgentStyle(style);
}
/**
* Reload profile from disk and rebuild system prompt.
* Call this after updating profile files to apply changes immediately.

View file

@ -297,4 +297,60 @@ export class ProfileManager {
this.profile.user = content;
}
}
/** 获取 Agent 风格 */
getStyle(): string | undefined {
const profile = this.getProfile();
return profile?.config?.style;
}
/** 更新 Agent 风格 */
updateStyle(style: string): void {
const profile = this.getOrCreateProfile(false);
const currentConfig = profile.config ?? {};
const newConfig: ProfileConfig = {
...currentConfig,
style: style as ProfileConfig["style"],
};
profile.config = newConfig;
this.profile = profile;
writeProfileConfig(this.profileId, newConfig, { baseDir: this.baseDir });
// Also update soul.md to include the style
this.updateSoulWithStyle(style);
}
/** 更新 soul.md确保包含 Agent 风格 */
private updateSoulWithStyle(style: string): void {
const profile = this.getOrCreateProfile(true);
let soulContent = profile.soul ?? DEFAULT_TEMPLATES.soul;
// 替换 soul.md 中的 Style 字段
// 匹配 "- **Style:** xxx" 格式
const stylePattern = /- \*\*Style:\*\* .*/;
const newStyleLine = `- **Style:** ${style}`;
if (stylePattern.test(soulContent)) {
soulContent = soulContent.replace(stylePattern, newStyleLine);
} else {
// 如果没有找到 Style 字段,在 Identity 部分的 Role 后添加
const rolePattern = /(- \*\*Role:\*\* .*)/;
if (rolePattern.test(soulContent)) {
soulContent = soulContent.replace(rolePattern, `$1\n${newStyleLine}`);
} else {
// 如果没有 Role尝试在 Name 后添加
const namePattern = /(- \*\*Name:\*\* .*)/;
if (namePattern.test(soulContent)) {
soulContent = soulContent.replace(namePattern, `$1\n${newStyleLine}`);
}
}
}
// 保存更新后的 soul.md
writeProfileFile(this.profileId, PROFILE_FILES.soul, soulContent, { baseDir: this.baseDir });
// 更新缓存
if (this.profile) {
this.profile.soul = soulContent;
}
}
}

View file

@ -13,10 +13,22 @@ export const PROFILE_FILES = {
config: "config.json",
} as const;
/** Available style options for agent personality */
export const AGENT_STYLES = [
"concise", // 简洁直接
"warm", // 温暖友好
"playful", // 轻松活泼
"professional", // 专业正式
] as const;
export type AgentStyle = (typeof AGENT_STYLES)[number];
/** Profile config.json structure */
export interface ProfileConfig {
/** Agent display name */
name?: string;
/** Agent communication style */
style?: AgentStyle;
/** Tools policy configuration */
tools?: ToolsConfig;
/** Default LLM provider */

View file

@ -564,6 +564,20 @@ export class Agent {
this.profile?.updateUserContent(content);
}
/**
* Get agent communication style from profile config.
*/
getAgentStyle(): string | undefined {
return this.profile?.getStyle();
}
/**
* Update agent communication style in profile config.
*/
setAgentStyle(style: string): void {
this.profile?.updateStyle(style);
}
/**
* Reload profile from disk and rebuild system prompt.
* Call this after updating profile files to apply changes immediately.