MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / _compile_concepts

Function _compile_concepts

openkb/agent/compiler.py:1571–2173  ·  view source on GitHub ↗

Shared Steps 2-4: concepts plan → generate/update → index. Uses ``_CONCEPTS_PLAN_USER`` to get a plan with create/update/related actions, then executes each action type accordingly. Concept bodies are generated in memory, scrubbed of unresolved wikilinks, and only then written to di

(
    wiki_dir: Path,
    kb_dir: Path,
    model: str,
    system_msg: dict,
    doc_msg: dict,
    summary: str,
    doc_name: str,
    max_concurrency: int,
    doc_brief: str = "",
    doc_type: str = "short",
    rewrite_summary: bool = False,
    entity_types: list[str] | None = None,
)

Source from the content-addressed store, hash-verified

1569
1570
1571async def _compile_concepts(
1572 wiki_dir: Path,
1573 kb_dir: Path,
1574 model: str,
1575 system_msg: dict,
1576 doc_msg: dict,
1577 summary: str,
1578 doc_name: str,
1579 max_concurrency: int,
1580 doc_brief: str = "",
1581 doc_type: str = "short",
1582 rewrite_summary: bool = False,
1583 entity_types: list[str] | None = None,
1584) -> None:
1585 """Shared Steps 2-4: concepts plan → generate/update → index.
1586
1587 Uses ``_CONCEPTS_PLAN_USER`` to get a plan with create/update/related
1588 actions, then executes each action type accordingly. Concept bodies are
1589 generated in memory, scrubbed of unresolved wikilinks, and only then
1590 written to disk. When ``rewrite_summary=True`` (short-doc path), the
1591 summary is rewritten by the LLM after concepts are finalized so its
1592 wikilinks reflect the actual concept pages on disk.
1593 """
1594 source_file = f"summaries/{doc_name}.md"
1595
1596 # Effective entity types for this compile (config-driven; defaults to the
1597 # canonical enum when unset, keeping behavior byte-identical to today).
1598 if entity_types is None:
1599 entity_types = list(_ENTITY_TYPE_LIST)
1600 types_str = ", ".join(entity_types)
1601 valid_types = frozenset(entity_types)
1602
1603 # --- Step 2: Get concepts plan (A cached) ---
1604 concept_briefs = _read_concept_briefs(wiki_dir)
1605 entity_briefs = _read_entity_briefs(wiki_dir)
1606
1607 # Second cache breakpoint: end of the assistant summary message. Covers
1608 # (system + doc + summary) for the plan call and every concept call.
1609 summary_msg = {"role": "assistant", "content": _cached_text(summary)}
1610
1611 plan_raw = _llm_call(
1612 model,
1613 [
1614 system_msg,
1615 doc_msg,
1616 summary_msg,
1617 {
1618 "role": "user",
1619 "content": _CONCEPTS_PLAN_USER.format(
1620 concept_briefs=concept_briefs,
1621 entity_briefs=entity_briefs,
1622 ).replace("__ENTITY_TYPES__", types_str),
1623 },
1624 ],
1625 "concepts-plan",
1626 response_format=_JSON_RESPONSE_FORMAT,
1627 )
1628

Calls 15

strip_ghost_wikilinksFunction · 0.90
_read_concept_briefsFunction · 0.85
_read_entity_briefsFunction · 0.85
_cached_textFunction · 0.85
_llm_callFunction · 0.85
_parse_jsonFunction · 0.85
_update_indexFunction · 0.85
_filter_concept_itemsFunction · 0.85
_filter_related_slugsFunction · 0.85
_parse_entities_planFunction · 0.85