Help:Ephemera Agent/Context Assembly: Difference between revisions

From Encyclopedia Ephemera
Import: Help:Ephemera Agent/Context Assembly
 
Update: task_type_override, custom_pages, create_stub/stub_expansion, routing table
 
Line 8: Line 8:
The pipeline is active when <code>agent.php</code> is deployed on your server. For simple query tasks, it is bypassed entirely via a fast pre-check.
The pipeline is active when <code>agent.php</code> 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 ==
== When Context Assembly Is Bypassed ==
Line 16: Line 19:
* No page creation or editing is required
* No page creation or editing is required
* The user is performing a quick lookup, browse action, or lightweight maintenance task
* The user is performing a quick lookup, browse action, or lightweight maintenance task
== task_type_override ==
The caller may include a <code>task_type_override</code> field in the POST body to bypass the classifier entirely. This is used internally by:
* Stub generation → forces <code>create_stub</code>
* Expand workflow → forces <code>stub_expansion</code>
Custom tooling or scripts can use this parameter to pin any supported task type.
== custom_pages ==
The <code>context_config.custom_pages</code> 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 ==
== Pipeline Steps ==


# '''Load Instructions:Config''' from the wiki to establish runtime parameters
# '''Load Instructions:Config''' from the wiki to establish runtime parameters
# '''Fast pre-check''' (<code>is_obviously_query()</code>) — if the task is clearly read-only (starts with "show", "list", "search", etc. and contains no generative keywords), skip the entire pipeline and route directly to the generator
# '''Fast pre-check''' (<code>is_obviously_query()</code>) — if clearly read-only, skip pipeline and route directly to generator
# '''Planner LLM call''' — classify task type and extract named entities (cheap/fast model)
# '''Planner LLM call''' (or use <code>task_type_override</code>) — classify task type and extract named entities
# '''Load World Bible''' — always first; anchors all generation to the universe
# '''Load World Bible''' — always first; anchors all generation to the universe
# '''Load core instructions''' — Canon Policy, Continuity Rules
# '''Load core instructions''' — Canon Policy, Continuity Rules
# '''Resolve instruction dependency graph''' — BFS traversal of <code>requires</code> links, up to <code>max_depth</code> hops
# '''Resolve instruction dependency graph''' — BFS traversal of <code>requires</code> links, up to <code>max_depth</code> hops
# '''Fetch encyclopedia pages''' — one per named entity
# '''Fetch encyclopedia pages''' — one per named entity + any <code>custom_pages</code>
# '''1-hop link expansion''' — fetch top-k related pages ranked by co-occurrence frequency across seed pages
# '''1-hop link expansion''' — fetch top-k related pages ranked by co-occurrence frequency
# '''Search Sources: namespace''' — top results per entity
# '''Search Sources: namespace''' — top results per entity
# '''Fetch filtered talk sections''' — Reliability Assessment, Bias Analysis, Editorial Notes only (never full talk pages)
# '''Fetch filtered talk sections''' — Reliability Assessment, Bias Analysis, Editorial Notes only
# '''Wikipedia lookup''' — if enabled, fetch the introductory paragraph for each entity from the Wikipedia API
# '''Wikipedia lookup''' — if enabled, fetch introductory paragraph per entity
# '''Deduplicate''' — remove pages that appear in multiple sections
# '''Deduplicate, rank, trim to token budget''' — drop lowest-priority content first (Wikipedia → talk → sources → encyclopedia). Instructions are never trimmed.
# '''Rank by keyword overlap''' — score pages by overlap with the task description using TF-style scoring
# '''Trim to token budget''' — drop lowest-priority content first (Wikipedia → talk → sources → encyclopedia). Instructions are never trimmed.
# '''Serialise''' — assemble into a structured prompt string with section headers
# '''Serialise''' — assemble into a structured prompt string with section headers
== Task Types ==
{| class="wikitable" style="width:100%"
! Type !! Description
|-
| <code>create_encyclopedia_article</code> || Create a new encyclopedia article
|-
| <code>create_stub</code> || Create a minimal stub article (section headers, ~300 words, <nowiki>{{stub}}</nowiki>)
|-
| <code>stub_expansion</code> || Expand a stub into a full article
|-
| <code>create_source</code> || Create an in-universe source document
|-
| <code>edit_page</code> || Edit or update an existing wiki page
|-
| <code>maintenance_report</code> || Produce a maintenance or audit report
|-
| <code>query</code> || Read-only information retrieval
|-
| <code>red_link_generation</code> || Create a page for a detected red link (uses stub instructions when stub mode is active)
|-
| <code>unknown</code> || Could not be determined — defaults to generative path
|}
== Instruction Routing by Task Type ==
{| class="wikitable" style="width:100%"
! Task type !! Instruction pages selected
|-
| <code>create_stub</code>, <code>red_link_generation</code> || <code>Instructions:Create/Stub</code>
|-
| <code>stub_expansion</code> || <code>Instructions:Create/Encyclopedia Article</code>, <code>Instructions:Schema/Encyclopedia Article</code>
|-
| All others || Determined by task type mapping in <code>context.php</code>
|}


== Context Prompt Format ==
== Context Prompt Format ==
The assembled context is prepended to the generator's system prompt in this order:


<pre>
<pre>
[INSTRUCTIONS]
[INSTRUCTIONS]
--- Instructions:World Bible ---
--- Instructions:World Bible ---
{content}
--- Instructions:Core/Canon Policy ---
{content}
{content}
...
...
Line 60: Line 106:
--- Talk: Sources:DocumentTitle ---
--- Talk: Sources:DocumentTitle ---
= Reliability Assessment =
= Reliability Assessment =
{content}
= Bias Analysis =
{content}
...
...


[REAL-WORLD REFERENCE — Wikipedia]
[REAL-WORLD REFERENCE — Wikipedia]
Factual real-world information for grounding only.
...
Do NOT treat as in-universe canon for Encyclopedia Ephemera.
--- EntityName ---
Wikipedia: ArticleTitle
{intro paragraph}
</pre>
</pre>
== Task Types ==
The planner model classifies each task into one of these types:
{| class="wikitable" style="width:100%"
! Type !! Description
|-
| <code>create_encyclopedia_article</code> || Create a new encyclopedia article about an entity, event, or concept
|-
| <code>create_source</code> || Create an in-universe source document
|-
| <code>edit_page</code> || Edit or update an existing wiki page
|-
| <code>maintenance_report</code> || Produce a maintenance or audit report
|-
| <code>query</code> || Read-only information retrieval
|-
| <code>batch_operation</code> || Perform the same operation across multiple pages
|-
| <code>stub_expansion</code> || Expand a stub or incomplete article
|-
| <code>red_link_generation</code> || Create a page for a detected red link
|-
| <code>unknown</code> || Could not be determined — defaults to generative path
|}
Additional task types can be added via <code>[[Instructions:Config]]</code> without PHP changes.


== Instruction Dependency Graph ==
== Instruction Dependency Graph ==


Each instruction page declares its dependencies in a <code>requires</code> metadata field. The pipeline resolves this graph using breadth-first traversal:
Each instruction page declares dependencies in a <code>requires</code> metadata field. The pipeline resolves this graph using BFS:


* '''max_depth''' (default: 2) — stop after this many hops
* '''max_depth''' (default: 2) — stop after this many hops
* '''fully_resolve''' (default: false) — if true, ignore max_depth and resolve the complete graph
* '''fully_resolve''' (default: false) — if true, resolve the complete graph
 
Example: selecting <code>Instructions:Create/Source/Interview</code> automatically also fetches <code>Instructions:Create/Source (Base Workflow)</code> (depth 1) and <code>Instructions:Core/Continuity Rules</code> (depth 2).
 
== Debugging ==
 
The '''▶ CONTEXT''' panel in the agent log shows what was assembled after each context-aware call. For deeper debugging, the raw <code>context_meta</code> object is included in every <code>agent.php</code> response and visible in browser developer tools.


[[Category:Help]]
[[Category:Help]]
[[Category:EphemeraAgent]]
[[Category:EphemeraAgent]]

Latest revision as of 19:17, 9 April 2026

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