From 66006d842e8d4b9a17103b070c3bf07642d9f8af Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Sun, 19 Apr 2026 01:04:19 +0800 Subject: [PATCH] feat(agent): inject project context and sender info into AI chat messages --- libs/agent/chat/service.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/libs/agent/chat/service.rs b/libs/agent/chat/service.rs index d78f3af..0230782 100644 --- a/libs/agent/chat/service.rs +++ b/libs/agent/chat/service.rs @@ -559,6 +559,38 @@ impl ChatService { messages.push(mem.to_system_message()); } + // Inject project context so the AI knows which project it is operating in. + let project_info = format!( + "Current Project:\n{}\nDescription: {}\nPublic: {}", + request.project.display_name, + request.project.description.as_deref().unwrap_or("(none)"), + if request.project.is_public { "yes" } else { "no" } + ); + messages.push(ChatCompletionRequestMessage::System( + ChatCompletionRequestSystemMessage { + content: async_openai::types::chat::ChatCompletionRequestSystemMessageContent::Text(project_info), + ..Default::default() + }, + )); + + // Inject sender info so the AI knows who is asking. + let mut sender_parts = vec![format!("**Sender:** {}", request.sender.username)]; + if let Some(ref display_name) = request.sender.display_name { + sender_parts.push(display_name.clone()); + } + if let Some(ref org) = request.sender.organization { + sender_parts.push(format!("({})", org)); + } + let sender_display = sender_parts.join(" "); + messages.push(ChatCompletionRequestMessage::System( + ChatCompletionRequestSystemMessage { + content: async_openai::types::chat::ChatCompletionRequestSystemMessageContent::Text( + format!("The person sending the next message:\n{}", sender_display), + ), + ..Default::default() + }, + )); + messages.push(ChatCompletionRequestMessage::User( ChatCompletionRequestUserMessage { content: async_openai::types::chat::ChatCompletionRequestUserMessageContent::Text(