Help:Ephemera Agent/Context Assembly: Difference between revisions
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 | # '''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 | # '''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 | # '''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 | # '''Fetch filtered talk sections''' — Reliability Assessment, Bias Analysis, Editorial Notes only | ||
# '''Wikipedia lookup''' — if enabled, fetch | # '''Wikipedia lookup''' — if enabled, fetch introductory paragraph per entity | ||
# '''Deduplicate | # '''Deduplicate, rank, 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 == | ||
<pre> | <pre> | ||
[INSTRUCTIONS] | [INSTRUCTIONS] | ||
--- Instructions:World Bible --- | --- Instructions:World Bible --- | ||
{content} | {content} | ||
... | ... | ||
| Line 60: | Line 106: | ||
--- Talk: Sources:DocumentTitle --- | --- Talk: Sources:DocumentTitle --- | ||
= Reliability Assessment = | = Reliability Assessment = | ||
... | ... | ||
[REAL-WORLD REFERENCE — Wikipedia] | [REAL-WORLD REFERENCE — Wikipedia] | ||
... | |||
</pre> | </pre> | ||
== Instruction Dependency Graph == | == Instruction Dependency Graph == | ||
Each instruction page declares | 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, | * '''fully_resolve''' (default: false) — if true, resolve the complete graph | ||
[[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
- Load Instructions:Config from the wiki to establish runtime parameters
- Fast pre-check (
is_obviously_query()) — if clearly read-only, skip pipeline and route directly to generator - Planner LLM call (or use
task_type_override) — classify task type and extract named entities - Load World Bible — always first; anchors all generation to the universe
- Load core instructions — Canon Policy, Continuity Rules
- Resolve instruction dependency graph — BFS traversal of
requireslinks, up tomax_depthhops - Fetch encyclopedia pages — one per named entity + any
custom_pages - 1-hop link expansion — fetch top-k related pages ranked by co-occurrence frequency
- Search Sources: namespace — top results per entity
- Fetch filtered talk sections — Reliability Assessment, Bias Analysis, Editorial Notes only
- Wikipedia lookup — if enabled, fetch introductory paragraph per entity
- Deduplicate, rank, 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
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