<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://ephemerawiki.space/index.php?action=history&amp;feed=atom&amp;title=Help%3AEphemera_Agent%2FContext_Assembly</id>
	<title>Help:Ephemera Agent/Context Assembly - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://ephemerawiki.space/index.php?action=history&amp;feed=atom&amp;title=Help%3AEphemera_Agent%2FContext_Assembly"/>
	<link rel="alternate" type="text/html" href="https://ephemerawiki.space/index.php?title=Help:Ephemera_Agent/Context_Assembly&amp;action=history"/>
	<updated>2026-05-19T11:50:31Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.3</generator>
	<entry>
		<id>https://ephemerawiki.space/index.php?title=Help:Ephemera_Agent/Context_Assembly&amp;diff=695&amp;oldid=prev</id>
		<title>EphemeraAdmin: Update: task_type_override, custom_pages, create_stub/stub_expansion, routing table</title>
		<link rel="alternate" type="text/html" href="https://ephemerawiki.space/index.php?title=Help:Ephemera_Agent/Context_Assembly&amp;diff=695&amp;oldid=prev"/>
		<updated>2026-04-09T19:17:57Z</updated>

		<summary type="html">&lt;p&gt;Update: task_type_override, custom_pages, create_stub/stub_expansion, routing table&lt;/p&gt;
&lt;a href=&quot;https://ephemerawiki.space/index.php?title=Help:Ephemera_Agent/Context_Assembly&amp;amp;diff=695&amp;amp;oldid=10&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>EphemeraAdmin</name></author>
	</entry>
	<entry>
		<id>https://ephemerawiki.space/index.php?title=Help:Ephemera_Agent/Context_Assembly&amp;diff=10&amp;oldid=prev</id>
		<title>EphemeraAdmin: Import: Help:Ephemera Agent/Context Assembly</title>
		<link rel="alternate" type="text/html" href="https://ephemerawiki.space/index.php?title=Help:Ephemera_Agent/Context_Assembly&amp;diff=10&amp;oldid=prev"/>
		<updated>2026-04-01T04:29:34Z</updated>

		<summary type="html">&lt;p&gt;Import: Help:Ephemera Agent/Context Assembly&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{DISPLAYTITLE:Ephemera Agent — Context Assembly}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
Before any generative LLM call, &amp;lt;code&amp;gt;agent.php&amp;lt;/code&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
The pipeline is active when &amp;lt;code&amp;gt;agent.php&amp;lt;/code&amp;gt; is deployed on your server. For simple query tasks, it is bypassed entirely via a fast pre-check.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== When Context Assembly Is Bypassed ==&lt;br /&gt;
&lt;br /&gt;
The system may skip context assembly and call the LLM directly when:&lt;br /&gt;
&lt;br /&gt;
* The task is classified as a simple query&lt;br /&gt;
* No page creation or editing is required&lt;br /&gt;
* The user is performing a quick lookup, browse action, or lightweight maintenance task&lt;br /&gt;
&lt;br /&gt;
== Pipeline Steps ==&lt;br /&gt;
&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Load Instructions:Config&amp;#039;&amp;#039;&amp;#039; from the wiki to establish runtime parameters&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Fast pre-check&amp;#039;&amp;#039;&amp;#039; (&amp;lt;code&amp;gt;is_obviously_query()&amp;lt;/code&amp;gt;) — if the task is clearly read-only (starts with &amp;quot;show&amp;quot;, &amp;quot;list&amp;quot;, &amp;quot;search&amp;quot;, etc. and contains no generative keywords), skip the entire pipeline and route directly to the generator&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Planner LLM call&amp;#039;&amp;#039;&amp;#039; — classify task type and extract named entities (cheap/fast model)&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Load World Bible&amp;#039;&amp;#039;&amp;#039; — always first; anchors all generation to the universe&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Load core instructions&amp;#039;&amp;#039;&amp;#039; — Canon Policy, Continuity Rules&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Resolve instruction dependency graph&amp;#039;&amp;#039;&amp;#039; — BFS traversal of &amp;lt;code&amp;gt;requires&amp;lt;/code&amp;gt; links, up to &amp;lt;code&amp;gt;max_depth&amp;lt;/code&amp;gt; hops&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Fetch encyclopedia pages&amp;#039;&amp;#039;&amp;#039; — one per named entity&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;1-hop link expansion&amp;#039;&amp;#039;&amp;#039; — fetch top-k related pages ranked by co-occurrence frequency across seed pages&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Search Sources: namespace&amp;#039;&amp;#039;&amp;#039; — top results per entity&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Fetch filtered talk sections&amp;#039;&amp;#039;&amp;#039; — Reliability Assessment, Bias Analysis, Editorial Notes only (never full talk pages)&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Wikipedia lookup&amp;#039;&amp;#039;&amp;#039; — if enabled, fetch the introductory paragraph for each entity from the Wikipedia API&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Deduplicate&amp;#039;&amp;#039;&amp;#039; — remove pages that appear in multiple sections&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Rank by keyword overlap&amp;#039;&amp;#039;&amp;#039; — score pages by overlap with the task description using TF-style scoring&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Trim to token budget&amp;#039;&amp;#039;&amp;#039; — drop lowest-priority content first (Wikipedia → talk → sources → encyclopedia). Instructions are never trimmed.&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Serialise&amp;#039;&amp;#039;&amp;#039; — assemble into a structured prompt string with section headers&lt;br /&gt;
&lt;br /&gt;
== Context Prompt Format ==&lt;br /&gt;
&lt;br /&gt;
The assembled context is prepended to the generator&amp;#039;s system prompt in this order:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[INSTRUCTIONS]&lt;br /&gt;
--- Instructions:World Bible ---&lt;br /&gt;
{content}&lt;br /&gt;
--- Instructions:Core/Canon Policy ---&lt;br /&gt;
{content}&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
[ENCYCLOPEDIA CONTEXT]&lt;br /&gt;
--- PageTitle ---&lt;br /&gt;
{content}&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
[SOURCES]&lt;br /&gt;
--- Sources:DocumentTitle ---&lt;br /&gt;
{content}&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
[EDITORIAL NOTES]&lt;br /&gt;
--- Talk: Sources:DocumentTitle ---&lt;br /&gt;
= Reliability Assessment =&lt;br /&gt;
{content}&lt;br /&gt;
= Bias Analysis =&lt;br /&gt;
{content}&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
[REAL-WORLD REFERENCE — Wikipedia]&lt;br /&gt;
Factual real-world information for grounding only.&lt;br /&gt;
Do NOT treat as in-universe canon for Encyclopedia Ephemera.&lt;br /&gt;
--- EntityName ---&lt;br /&gt;
Wikipedia: ArticleTitle&lt;br /&gt;
{intro paragraph}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Task Types ==&lt;br /&gt;
&lt;br /&gt;
The planner model classifies each task into one of these types:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width:100%&amp;quot;&lt;br /&gt;
! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;create_encyclopedia_article&amp;lt;/code&amp;gt; || Create a new encyclopedia article about an entity, event, or concept&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;create_source&amp;lt;/code&amp;gt; || Create an in-universe source document&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;edit_page&amp;lt;/code&amp;gt; || Edit or update an existing wiki page&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;maintenance_report&amp;lt;/code&amp;gt; || Produce a maintenance or audit report&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;query&amp;lt;/code&amp;gt; || Read-only information retrieval&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;batch_operation&amp;lt;/code&amp;gt; || Perform the same operation across multiple pages&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;stub_expansion&amp;lt;/code&amp;gt; || Expand a stub or incomplete article&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;red_link_generation&amp;lt;/code&amp;gt; || Create a page for a detected red link&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;unknown&amp;lt;/code&amp;gt; || Could not be determined — defaults to generative path&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Additional task types can be added via &amp;lt;code&amp;gt;[[Instructions:Config]]&amp;lt;/code&amp;gt; without PHP changes.&lt;br /&gt;
&lt;br /&gt;
== Instruction Dependency Graph ==&lt;br /&gt;
&lt;br /&gt;
Each instruction page declares its dependencies in a &amp;lt;code&amp;gt;requires&amp;lt;/code&amp;gt; metadata field. The pipeline resolves this graph using breadth-first traversal:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;max_depth&amp;#039;&amp;#039;&amp;#039; (default: 2) — stop after this many hops&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;fully_resolve&amp;#039;&amp;#039;&amp;#039; (default: false) — if true, ignore max_depth and resolve the complete graph&lt;br /&gt;
&lt;br /&gt;
Example: selecting &amp;lt;code&amp;gt;Instructions:Create/Source/Interview&amp;lt;/code&amp;gt; automatically also fetches &amp;lt;code&amp;gt;Instructions:Create/Source (Base Workflow)&amp;lt;/code&amp;gt; (depth 1) and &amp;lt;code&amp;gt;Instructions:Core/Continuity Rules&amp;lt;/code&amp;gt; (depth 2).&lt;br /&gt;
&lt;br /&gt;
== Debugging ==&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;▶ CONTEXT&amp;#039;&amp;#039;&amp;#039; panel in the agent log shows what was assembled after each context-aware call. For deeper debugging, the raw &amp;lt;code&amp;gt;context_meta&amp;lt;/code&amp;gt; object is included in every &amp;lt;code&amp;gt;agent.php&amp;lt;/code&amp;gt; response and visible in browser developer tools.&lt;br /&gt;
&lt;br /&gt;
[[Category:Help]]&lt;br /&gt;
[[Category:EphemeraAgent]]&lt;/div&gt;</summary>
		<author><name>EphemeraAdmin</name></author>
	</entry>
</feed>