Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve agent block-reference anchor text guidance https://github.com/siyuan-note/siyuan/issues/18854

Daniel6aca631718ae
diff --git a/kernel/agent/agent.go b/kernel/agent/agent.go
index 67c557bd65..cc75603230 100644
--- a/kernel/agent/agent.go
+++ b/kernel/agent/agent.go
@@ -78,7 +78,7 @@ const systemPrompt = `You are a SiYuan AI assistant. You help users manage their
## Formatting
- Inline formatting uses standard markdown: **bold**, *italic*, ~~strikethrough~~, ==mark==, and "code" (backticks).
-- Block references in markdown must use ((<blockID> "<anchor text>")); never use [[<blockID>]], which is not block-reference syntax.
+- In markdown written to SiYuan blocks, block references must include anchor text. Use ((<blockID> "<static anchor text>")) for fixed text, or ((<blockID> '<dynamic anchor text>')) for text that follows the target block's content. Never use ((<blockID>)) or [[<blockID>]]. These forms are for note content; in chat responses use [title](siyuan://blocks/<blockID>).
- For text styling that markdown cannot express (color, background, font size), use SiYuan text marks.
The syntax requires a leading data-type="text" attribute — WITHOUT it the HTML is escaped and shown as literal text:
- Text color: <span data-type="text" style="color: #ff0000;">red text</span>
diff --git a/kernel/agent/prompt_test.go b/kernel/agent/prompt_test.go
index d145f24e48..928f51c00f 100644
--- a/kernel/agent/prompt_test.go
+++ b/kernel/agent/prompt_test.go
@@ -48,11 +48,21 @@ func TestTurnContextStaysInUserMessage(t *testing.T) {
}
func TestSystemPromptDocumentsBlockReferenceSyntax(t *testing.T) {
- if !strings.Contains(systemPrompt, `((<blockID> "<anchor text>"))`) {
- t.Fatal("system prompt is missing the SiYuan block-reference syntax")
+ if !strings.Contains(systemPrompt, `((<blockID> "<static anchor text>"))`) {
+ t.Fatal("system prompt is missing the static SiYuan block-reference syntax")
}
- if !strings.Contains(systemPrompt, `never use [[<blockID>]]`) {
- t.Fatal("system prompt does not reject bracketed block IDs")
+ if !strings.Contains(systemPrompt, `((<blockID> '<dynamic anchor text>'))`) {
+ t.Fatal("system prompt is missing the dynamic SiYuan block-reference syntax")
+ }
+ if !strings.Contains(systemPrompt, `for fixed text`) ||
+ !strings.Contains(systemPrompt, `for text that follows the target block's content`) {
+ t.Fatal("system prompt does not explain static and dynamic block-reference behavior")
+ }
+ if !strings.Contains(systemPrompt, `Never use ((<blockID>)) or [[<blockID>]]`) {
+ t.Fatal("system prompt does not reject block references without anchor text or bracketed block IDs")
+ }
+ if !strings.Contains(systemPrompt, `in chat responses use [title](siyuan://blocks/<blockID>)`) {
+ t.Fatal("system prompt does not distinguish note-content block references from chat-response links")
}
}