An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: AI Agent https://github.com/siyuan-note/siyuan/issues/17797
Daniel73a35dae6475
diff --git a/kernel/agent/agent.go b/kernel/agent/agent.goindex fcd9293889..7320b3a2ad 100644--- a/kernel/agent/agent.go+++ b/kernel/agent/agent.go@@ -64,6 +64,19 @@ const systemPrompt = `You are a SiYuan AI assistant. You help users manage their- Use markdown formatting for readability: bullet points, headings, code blocks for technical content.- Do not fabricate information. If you don't know something or can't find it in the user's notes, say so honestly instead of making up an answer. Search and verify before claiming facts.+## SiYuan User Guide+- SiYuan has a built-in user guide notebook that documents all supported features.+ Notebook IDs by language:+ - 简体中文: "20210808180117-czj9bvb"+ - 繁體中文: "20211226090932-5lcq56f"+ - 日本語: "20240530133126-axarxgx"+ - English and other languages: "20210808180117-6v0mkxr"+- When a user asks whether SiYuan supports a feature or how to use a feature:+ 1. Use notebook.open to open the appropriate user guide notebook for the user's language.+ 2. Use search.fulltext to search the user guide for relevant documentation.+ 3. If found, cite the content. If not found, honestly tell the user the feature may not be supported.+- Do NOT invent features or UI workflows. The user guide is the authoritative source for SiYuan capabilities.+## Todo Tracking- For multi-step tasks (3+ distinct steps), use the todo_write tool to create a structured task list before starting work. This helps the user see your progress.- Each call replaces the entire list. Include all tasks, marking each with the correct status.diff --git a/kernel/mcp/tools/notebook.go b/kernel/mcp/tools/notebook.goindex 0f80010eee..f3c0f36f02 100644--- a/kernel/mcp/tools/notebook.go+++ b/kernel/mcp/tools/notebook.go@@ -19,18 +19,20 @@ package toolsimport ("fmt""strings"+ "time""github.com/siyuan-note/siyuan/kernel/model"+ "github.com/siyuan-note/siyuan/kernel/sql")var NotebookTool = &Tool{Name: "notebook",- Description: "Notebook management for SiYuan.\n- list: List all notebooks.\n- create: Create a notebook. Requires: name.\n- rename: Rename a notebook. Requires: id, name.\n- remove: Remove a notebook. Requires: id.",+ Description: "Notebook management for SiYuan.\n- list: List all notebooks.\n- open: Open a notebook. Requires: id.\n- close: Close a notebook. Requires: id.\n- create: Create a notebook. Requires: name.\n- rename: Rename a notebook. Requires: id, name.\n- remove: Remove a notebook. Requires: id.",InputSchema: ToolSchema{Type: "object",Properties: map[string]Property{- "action": {Type: "string", Description: "Operation", Enum: []string{"list", "create", "rename", "remove"}},- "id": {Type: "string", Description: "Notebook ID (for rename, remove)"},+ "action": {Type: "string", Description: "Operation", Enum: []string{"list", "open", "close", "create", "rename", "remove"}},+ "id": {Type: "string", Description: "Notebook ID (for open, close, rename, remove)"},"name": {Type: "string", Description: "Notebook name (for create, rename)"},},Required: []string{"action"},@@ -47,6 +49,10 @@ func notebookHandler(args map[string]interface{}) (CallToolResult, error) {switch action {case "list":return notebookList(args)+ case "open":+ return notebookOpen(args)+ case "close":+ return notebookClose(args)case "create":return notebookCreate(args)case "rename":@@ -55,7 +61,7 @@ func notebookHandler(args map[string]interface{}) (CallToolResult, error) {return notebookRemove(args)}return CallToolResult{- Content: []ContentItem{{Type: "text", Text: "unknown action '" + action + "', expected one of: [list, create, rename, remove]"}},+ Content: []ContentItem{{Type: "text", Text: "unknown action '" + action + "', expected one of: [list, open, close, create, rename, remove]"}},IsError: true,}, nil}@@ -114,3 +120,32 @@ func notebookRemove(args map[string]interface{}) (CallToolResult, error) {return CallToolResult{Content: []ContentItem{{Type: "text", Text: "notebook removed: " + id}}}, nil}++func notebookOpen(args map[string]interface{}) (CallToolResult, error) {+ id, _ := args["id"].(string)+ if id == "" {+ return CallToolResult{Content: []ContentItem{{Type: "text", Text: "id is required"}}, IsError: true}, nil+ }++ _, err := model.Mount(id)+ if err != nil {+ return CallToolResult{Content: []ContentItem{{Type: "text", Text: "open notebook failed: " + err.Error()}}, IsError: true}, nil+ }++ if model.IsUserGuide(id) {+ time.Sleep(7 * time.Second)+ sql.FlushQueue()+ }++ return CallToolResult{Content: []ContentItem{{Type: "text", Text: "notebook opened: " + id}}}, nil+}++func notebookClose(args map[string]interface{}) (CallToolResult, error) {+ id, _ := args["id"].(string)+ if id == "" {+ return CallToolResult{Content: []ContentItem{{Type: "text", Text: "id is required"}}, IsError: true}, nil+ }++ model.Unmount(id)+ return CallToolResult{Content: []ContentItem{{Type: "text", Text: "notebook closed: " + id}}}, nil+}