Skip to content

Commit b6ce04e

Browse files
committed
feat: update LLM prompts to return brief+content JSON
Replace _SUMMARY_USER, _CONCEPT_PAGE_USER, and _CONCEPT_UPDATE_USER to request a JSON object with "brief" (one-line summary) and "content" (full Markdown). Add TestParseBriefContent to tests/test_compiler.py.
1 parent 39ae5c5 commit b6ce04e

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

openkb/agent/compiler.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@
4343
Full text:
4444
{content}
4545
46-
Write a summary page for this document in Markdown. Include:
47-
- Key concepts, findings, and ideas
48-
- [[wikilinks]] to concepts that could become cross-document concept pages
46+
Write a summary page for this document in Markdown.
4947
50-
Return ONLY the Markdown content (no frontmatter, no code fences).
48+
Return a JSON object with two keys:
49+
- "brief": A single sentence (under 100 chars) describing the document's main contribution
50+
- "content": The full summary in Markdown. Include key concepts, findings, ideas, \
51+
and [[wikilinks]] to concepts that could become cross-document concept pages
52+
53+
Return ONLY valid JSON, no fences.
5154
"""
5255

5356

@@ -84,10 +87,13 @@
8487
This concept relates to the document "{doc_name}" summarized above.
8588
{update_instruction}
8689
87-
Return ONLY the Markdown content (no frontmatter, no code fences). Include:
88-
- Clear explanation of the concept
89-
- Key details from the source document
90-
- [[wikilinks]] to related concepts and [[summaries/{doc_name}]]
90+
Return a JSON object with two keys:
91+
- "brief": A single sentence (under 100 chars) defining this concept
92+
- "content": The full concept page in Markdown. Include clear explanation, \
93+
key details from the source document, and [[wikilinks]] to related concepts \
94+
and [[summaries/{doc_name}]]
95+
96+
Return ONLY valid JSON, no fences.
9197
"""
9298

9399
_CONCEPT_UPDATE_USER = """\
@@ -101,7 +107,11 @@
101107
information naturally — do not just append. Maintain existing \
102108
[[wikilinks]] and add new ones where appropriate.
103109
104-
Return ONLY the Markdown content (no frontmatter, no code fences).
110+
Return a JSON object with two keys:
111+
- "brief": A single sentence (under 100 chars) defining this concept (may differ from before)
112+
- "content": The rewritten full concept page in Markdown
113+
114+
Return ONLY valid JSON, no fences.
105115
"""
106116

107117
_LONG_DOC_SUMMARY_USER = """\

tests/test_compiler.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ def test_fenced_dict(self):
6161
assert parsed["create"] == []
6262

6363

64+
class TestParseBriefContent:
65+
def test_dict_with_brief_and_content(self):
66+
text = json.dumps({"brief": "A short desc", "content": "# Full page\n\nDetails."})
67+
parsed = _parse_json(text)
68+
assert parsed["brief"] == "A short desc"
69+
assert "# Full page" in parsed["content"]
70+
71+
def test_plain_text_fallback(self):
72+
"""If LLM returns plain text, _parse_json raises — caller handles fallback."""
73+
with pytest.raises((json.JSONDecodeError, ValueError)):
74+
_parse_json("Just plain markdown text without JSON")
75+
76+
6477
class TestWriteSummary:
6578
def test_writes_with_frontmatter(self, tmp_path):
6679
wiki = tmp_path / "wiki"

0 commit comments

Comments
 (0)