An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Use appearance language for agent responses https://github.com/siyuan-note/siyuan/issues/17797
Danield291aaf0e15f
diff --git a/kernel/agent/agent.go b/kernel/agent/agent.goindex b9f496db93..aa22d142cd 100644--- a/kernel/agent/agent.go+++ b/kernel/agent/agent.go@@ -64,7 +64,7 @@ const systemPrompt = `You are a SiYuan AI assistant. You help users manage their- Document images: image.list finds local images referenced by a document; call image.analyze on a returned asset path to understand one. image.generate creates a reusable image asset for insertion or other document operations.## Response Guidelines-- Reply in the user's language. When mentioning documents/blocks the user can open, format them as markdown links: [title](siyuan://blocks/<blockID>). Only use block IDs actually returned by a tool call (block.get/get_children/breadcrumb/batch_get/search); never fabricate IDs. For general mentions without a specific block, plain text is fine.+- Reply in the language configured in SiYuan's appearance settings. When mentioning documents/blocks the user can open, format them as markdown links: [title](siyuan://blocks/<blockID>). Only use block IDs actually returned by a tool call (block.get/get_children/breadcrumb/batch_get/search); never fabricate IDs. For general mentions without a specific block, plain text is fine.- Be concise: summarize rather than repeat large content.- For choices (which notebook/document/action), use the question tool — never a plain text list.- Use markdown; for code blocks always specify the language (e.g. python, go); use $...$ for inline and $...$ for block formulas.@@ -1326,6 +1326,10 @@ func finishFrontendWait(callID string, ch chan frontendCallResult) (frontendCall}func buildSystemPrompt(language string, pluginActions []PluginAction) string {+ if kernelModel.Conf != nil && kernelModel.Conf.Appearance != nil && kernelModel.Conf.Appearance.Lang != "" {+ language = kernelModel.Conf.Appearance.Lang+ }+var sb strings.Buildersb.WriteString(systemPrompt)sb.WriteString("\n\n<env>\nWorkspace: ")@@ -1379,7 +1383,7 @@ func buildSystemPrompt(language string, pluginActions []PluginAction) string {sb.WriteString("\n\nReply in ")sb.WriteString(util.I18nTerm(language, "_label"))sb.WriteString(".")- sb.WriteString("\n\nIn the user's language, a daily note is called: ")+ sb.WriteString("\n\nIn the language configured in SiYuan's appearance settings, a daily note is called: ")sb.WriteString(util.I18nTerm(language, "dailyNote"))sb.WriteString(". When the user asks to write or create this, use dailynote.create, not document.create.")return sb.String()diff --git a/kernel/agent/prompt_test.go b/kernel/agent/prompt_test.goindex 530561d0aa..fc3c675edf 100644--- a/kernel/agent/prompt_test.go+++ b/kernel/agent/prompt_test.go@@ -9,8 +9,14 @@package agentimport (+ "path/filepath"+ "runtime""strings""testing"++ kernelConf "github.com/siyuan-note/siyuan/kernel/conf"+ kernelModel "github.com/siyuan-note/siyuan/kernel/model"+ "github.com/siyuan-note/siyuan/kernel/util")func TestTurnContextStaysInUserMessage(t *testing.T) {@@ -57,6 +63,31 @@ func TestSystemPromptSortsPluginActions(t *testing.T) {}}+func TestSystemPromptUsesAppearanceLanguage(t *testing.T) {+ originalConf := kernelModel.Conf+ originalWorkingDir := util.WorkingDir+ kernelModel.Conf = kernelModel.NewAppConf()+ kernelModel.Conf.Appearance = kernelConf.NewAppearance()+ kernelModel.Conf.Appearance.Lang = "zh-CN"+ _, filename, _, _ := runtime.Caller(0)+ util.WorkingDir = filepath.Join(filepath.Dir(filename), "..", "..", "app")+ t.Cleanup(func() {+ kernelModel.Conf = originalConf+ util.WorkingDir = originalWorkingDir+ })++ prompt := buildSystemPrompt("en", nil)+ if !strings.Contains(prompt, "Reply in the language configured in SiYuan's appearance settings.") {+ t.Fatalf("appearance language instruction is missing from system prompt: %q", prompt)+ }+ if !strings.Contains(prompt, "Reply in 简体中文.") {+ t.Fatalf("appearance language is missing from system prompt: %q", prompt)+ }+ if strings.Contains(prompt, "Reply in English.") {+ t.Fatalf("request language leaked into system prompt: %q", prompt)+ }+}+func TestCheckpointMessagesKeepHistoricalTurnContexts(t *testing.T) {checkpoint := []AgentMessage{newAgentUserMessage("first question", "user-1", nil, EditorContext{ActiveDocID: "doc-a"}),