feat(agent): inject user name and role into chat context

This commit is contained in:
yiling
2026-07-27 11:24:48 +08:00
parent b8345f7c46
commit cd3c7f3641
6 changed files with 151 additions and 5 deletions
@@ -17,6 +17,7 @@ export class AgentChatPromptBuilder {
private explicitMention = false
private attachedFiles: string[] = []
private referencedAssets: string[] = []
private userInfo?: { name: string; role: string }
private isContinuation = false
private hasAssetChanged = false
@@ -25,6 +26,13 @@ export class AgentChatPromptBuilder {
this.assetId = assetId
}
withUserInfo(name?: string, role?: string): this {
if (name) {
this.userInfo = { name, role: role || 'user' }
}
return this
}
withContinuation(isContinuation: boolean): this {
this.isContinuation = isContinuation
return this
@@ -178,6 +186,10 @@ export class AgentChatPromptBuilder {
instruction += `\n\nThe user did not explicitly mention you, but is replying in a thread where you are the participant. Let's decide if you should reply or not. If the user is not directly addressing you or doesn't need a response from you, you may choose to not reply. To choose not to reply, respond with exactly and only the text: __NO_REPLY__.`
}
if (this.userInfo) {
instruction += `\n\nUser Info:\nName: ${this.userInfo.name}\nRole: ${this.userInfo.role}`
}
return instruction
}
}