Help:Ephemera Agent/Context Assembly

From Encyclopedia Ephemera

Overview

Before any generative LLM call, agent.php assembles a structured context package from the wiki. This ensures the generator model has access to relevant canon, instructions, and evidence without needing to make additional API calls during generation.

The pipeline is active when agent.php is deployed on your server. For simple query tasks, it is bypassed entirely via a fast pre-check.

Inspecting Assembled Context

After each context-aware agent run, the CONTEXT tab (third button in the header bar) shows which pages were included, their section groupings, and token counts. Each page is clickable — it loads in the Browser tab. See Help:Ephemera Agent/Context Tab.

When Context Assembly Is Bypassed

The system may skip context assembly and call the LLM directly when:

  • The task is classified as a simple query
  • No page creation or editing is required
  • The user is performing a quick lookup, browse action, or lightweight maintenance task

task_type_override

The caller may include a task_type_override field in the POST body to bypass the classifier entirely. This is used internally by:

  • Stub generation → forces create_stub
  • Expand workflow → forces stub_expansion

Custom tooling or scripts can use this parameter to pin any supported task type.

custom_pages

The context_config.custom_pages array (list of page titles) forces additional pages into the encyclopedia context bucket, regardless of what the classifier selects. These are the pages added via the + CONTEXT button in the browser toolbar or the Custom Pages section of the Context tab.

Pipeline Steps

  1. Load Instructions:Config from the wiki to establish runtime parameters
  2. Fast pre-check (is_obviously_query()) — if clearly read-only, skip pipeline and route directly to generator
  3. Planner LLM call (or use task_type_override) — classify task type and extract named entities
  4. Load World Bible — always first; anchors all generation to the universe
  5. Load core instructions — Canon Policy, Continuity Rules
  6. Resolve instruction dependency graph — BFS traversal of requires links, up to max_depth hops
  7. Fetch encyclopedia pages — one per named entity + any custom_pages
  8. 1-hop link expansion — fetch top-k related pages ranked by co-occurrence frequency
  9. Search Sources: namespace — top results per entity
  10. Fetch filtered talk sections — Reliability Assessment, Bias Analysis, Editorial Notes only
  11. Wikipedia lookup — if enabled, fetch introductory paragraph per entity
  12. Deduplicate, rank, trim to token budget — drop lowest-priority content first (Wikipedia → talk → sources → encyclopedia). Instructions are never trimmed.
  13. Serialise — assemble into a structured prompt string with section headers

Task Types

Type Description
create_encyclopedia_article Create a new encyclopedia article
create_stub Create a minimal stub article (section headers, ~300 words, {{stub}})
stub_expansion Expand a stub into a full article
create_source Create an in-universe source document
edit_page Edit or update an existing wiki page
maintenance_report Produce a maintenance or audit report
query Read-only information retrieval
red_link_generation Create a page for a detected red link (uses stub instructions when stub mode is active)
unknown Could not be determined — defaults to generative path

Instruction Routing by Task Type

Task type Instruction pages selected
create_stub, red_link_generation Instructions:Create/Stub
stub_expansion Instructions:Create/Encyclopedia Article, Instructions:Schema/Encyclopedia Article
All others Determined by task type mapping in context.php

Context Prompt Format

[INSTRUCTIONS]
--- Instructions:World Bible ---
{content}
...

[ENCYCLOPEDIA CONTEXT]
--- PageTitle ---
{content}
...

[SOURCES]
--- Sources:DocumentTitle ---
{content}
...

[EDITORIAL NOTES]
--- Talk: Sources:DocumentTitle ---
= Reliability Assessment =
...

[REAL-WORLD REFERENCE — Wikipedia]
...

Instruction Dependency Graph

Each instruction page declares dependencies in a requires metadata field. The pipeline resolves this graph using BFS:

  • max_depth (default: 2) — stop after this many hops
  • fully_resolve (default: false) — if true, resolve the complete graph