Skip to content

Commit b882ee9

Browse files
committed
fix(compiler): add [[entities/X]] whitelist rule + restore concept-topic guard
Remaining review findings after a7a06ed: - _KNOWN_TARGETS_USER now states the [[entities/Z]] rule, so entity links the LLM is told to write aren't silently stripped as ghosts. - Restore the dropped 'Do NOT create concepts that are just the document topic itself' plan rule to prevent redundant title-mirror concepts.
1 parent a7a06ed commit b882ee9

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

openkb/agent/compiler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
sparse documents.
114114
- Prefer "update" over "create" for any concept or entity already listed above.
115115
- Do NOT create a concept/entity that overlaps an existing one — use "update".
116+
- Do NOT create concepts that are just the document topic itself.
116117
- "related" is lightweight cross-linking only, no content rewrite.
117118
118119
Return ONLY valid JSON, no fences, no explanation.
@@ -127,8 +128,9 @@
127128
Rules for [[wikilinks]] in all subsequent responses:
128129
- For [[concepts/X]]: X must appear in the whitelist above.
129130
- For [[summaries/Y]]: Y must appear in the whitelist above.
131+
- For [[entities/Z]]: Z must appear in the whitelist above.
130132
- Do NOT invent new wikilink targets. If you want to mention a concept \
131-
that is not in the whitelist, write it as plain text without brackets.
133+
or entity that is not in the whitelist, write it as plain text without brackets.
132134
"""
133135

134136
_CONCEPT_PAGE_USER = """\

tests/test_compiler.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,3 +1672,21 @@ def test_schema_declares_entities():
16721672
assert "Entity Page" in AGENTS_MD
16731673
for t in ("person", "organization", "place", "product", "work", "event", "other"):
16741674
assert t in AGENTS_MD
1675+
1676+
1677+
def test_known_targets_prompt_has_entities_rule():
1678+
"""The whitelist message must tell the LLM the [[entities/X]] rule, since
1679+
entity-page prompts instruct writing such links; otherwise entity links
1680+
are generated freely and then stripped as ghosts."""
1681+
from openkb.agent.compiler import _KNOWN_TARGETS_USER
1682+
1683+
assert "[[entities/" in _KNOWN_TARGETS_USER
1684+
1685+
1686+
def test_plan_prompt_keeps_topic_itself_guard():
1687+
"""The concept-plan prompt must retain the guard against creating a concept
1688+
that merely mirrors the document's own topic."""
1689+
from openkb.agent.compiler import _CONCEPTS_PLAN_USER
1690+
1691+
assert "just the document topic itself" in _CONCEPTS_PLAN_USER
1692+

0 commit comments

Comments
 (0)