Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(agent): add communication style setting to profile

Jiang Bohan4df39448bec7
diff --git a/src/agent/async-agent.ts b/src/agent/async-agent.ts
index b95fdc50f2..9c928232eb 100644
--- a/src/agent/async-agent.ts
+++ b/src/agent/async-agent.ts
@@ -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.
diff --git a/src/agent/profile/index.ts b/src/agent/profile/index.ts
index a8c6dd9dd5..b0ce01588c 100644
--- a/src/agent/profile/index.ts
+++ b/src/agent/profile/index.ts
@@ -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;
+ }
+ }
}
diff --git a/src/agent/profile/types.ts b/src/agent/profile/types.ts
index db313ceb1a..f1de243d4d 100644
--- a/src/agent/profile/types.ts
+++ b/src/agent/profile/types.ts
@@ -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 */
diff --git a/src/agent/runner.ts b/src/agent/runner.ts
index 0efda9209e..7acb3709a3 100644
--- a/src/agent/runner.ts
+++ b/src/agent/runner.ts
@@ -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.