<?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%2FLogging_%26_Training_Data</id>
	<title>Help:Ephemera Agent/Logging &amp; Training Data - 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%2FLogging_%26_Training_Data"/>
	<link rel="alternate" type="text/html" href="https://ephemerawiki.space/index.php?title=Help:Ephemera_Agent/Logging_%26_Training_Data&amp;action=history"/>
	<updated>2026-05-19T11:03:04Z</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/Logging_%26_Training_Data&amp;diff=697&amp;oldid=prev</id>
		<title>EphemeraAdmin: Add logging &amp; training data documentation (implemented 2026-04-22)</title>
		<link rel="alternate" type="text/html" href="https://ephemerawiki.space/index.php?title=Help:Ephemera_Agent/Logging_%26_Training_Data&amp;diff=697&amp;oldid=prev"/>
		<updated>2026-04-23T02:16:33Z</updated>

		<summary type="html">&lt;p&gt;Add logging &amp;amp; training data documentation (implemented 2026-04-22)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{DISPLAYTITLE:Ephemera Agent — Logging &amp;amp; Training Data}}&lt;br /&gt;
__TOC__&lt;br /&gt;
Every agent call is recorded in full to a MariaDB table (&amp;lt;code&amp;gt;ephemera_agent_log&amp;lt;/code&amp;gt;). This serves three purposes: operational auditability, debugging, and accumulation of real training data for eventual fine-tuning.&lt;br /&gt;
&lt;br /&gt;
== Database Table ==&lt;br /&gt;
&lt;br /&gt;
The log table lives in the same MariaDB instance as MediaWiki (database: &amp;lt;code&amp;gt;ephemera&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE ephemera_agent_log (&lt;br /&gt;
   id                 BIGINT       NOT NULL AUTO_INCREMENT PRIMARY KEY,&lt;br /&gt;
   session_id         VARCHAR(64)  NOT NULL,&lt;br /&gt;
   timestamp          DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,&lt;br /&gt;
   mode               VARCHAR(32),&lt;br /&gt;
   provider           VARCHAR(32),&lt;br /&gt;
   model              VARCHAR(128),&lt;br /&gt;
   system_prompt      LONGTEXT,&lt;br /&gt;
   context_assembled  LONGTEXT,&lt;br /&gt;
   user_turn          LONGTEXT,&lt;br /&gt;
   response           LONGTEXT,&lt;br /&gt;
   tool_calls         JSON,&lt;br /&gt;
   target_page        VARCHAR(512),&lt;br /&gt;
   outcome            ENUM(&amp;#039;used&amp;#039;,&amp;#039;modified&amp;#039;,&amp;#039;rejected&amp;#039;,&amp;#039;pending&amp;#039;) DEFAULT &amp;#039;pending&amp;#039;,&lt;br /&gt;
   training_flag      TINYINT      NOT NULL DEFAULT 0,&lt;br /&gt;
   notes              TEXT&lt;br /&gt;
 );&lt;br /&gt;
&lt;br /&gt;
=== Field Reference ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field !! Notes&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;session_id&amp;lt;/code&amp;gt; || Generated per request via &amp;lt;code&amp;gt;uniqid()&amp;lt;/code&amp;gt;; groups related calls in one job&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mode&amp;lt;/code&amp;gt; || Classified task type (e.g. &amp;lt;code&amp;gt;create_encyclopedia_article&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;query&amp;lt;/code&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;provider&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;model&amp;lt;/code&amp;gt; || LLM provider and exact model name used for the generator call&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;system_prompt&amp;lt;/code&amp;gt; || Full augmented system prompt including assembled context&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;context_assembled&amp;lt;/code&amp;gt; || Raw context string passed to the model&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;user_turn&amp;lt;/code&amp;gt; || The task string submitted by the user&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;response&amp;lt;/code&amp;gt; || Full raw JSON response from the generator&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;tool_calls&amp;lt;/code&amp;gt; || Extracted tool use blocks (Anthropic and OpenAI formats both handled)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;target_page&amp;lt;/code&amp;gt; || First classified entity, used as the likely target wiki page&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;outcome&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;pending&amp;lt;/code&amp;gt; by default; manually set to &amp;lt;code&amp;gt;used&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;modified&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;rejected&amp;lt;/code&amp;gt; after review&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;training_flag&amp;lt;/code&amp;gt; || 0 = unassessed, 1 = good training candidate, −1 = exclude&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;notes&amp;lt;/code&amp;gt; || Human annotation field&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== How Logging Works ==&lt;br /&gt;
&lt;br /&gt;
Logging is implemented in &amp;lt;code&amp;gt;agent.php&amp;lt;/code&amp;gt;. After the generator LLM call completes and the response is decoded, &amp;lt;code&amp;gt;log_agent_call()&amp;lt;/code&amp;gt; writes one row per agent invocation. A PDO connection with &amp;lt;code&amp;gt;ERRMODE_SILENT&amp;lt;/code&amp;gt; is used so a database failure never surfaces to the user or breaks a task.&lt;br /&gt;
&lt;br /&gt;
The call to &amp;lt;code&amp;gt;extract_tool_calls()&amp;lt;/code&amp;gt; handles both Anthropic-style &amp;lt;code&amp;gt;content&amp;lt;/code&amp;gt; blocks and OpenAI-style &amp;lt;code&amp;gt;choices[].message.tool_calls&amp;lt;/code&amp;gt; arrays.&lt;br /&gt;
&lt;br /&gt;
Logging happens in &amp;lt;code&amp;gt;agent.php&amp;lt;/code&amp;gt; only — direct calls through &amp;lt;code&amp;gt;llm-proxy.php&amp;lt;/code&amp;gt; are not logged.&lt;br /&gt;
&lt;br /&gt;
== Querying Logs ==&lt;br /&gt;
&lt;br /&gt;
Connect to MariaDB as the &amp;lt;code&amp;gt;ephemera&amp;lt;/code&amp;gt; user:&lt;br /&gt;
&lt;br /&gt;
 mysql -u ephemera -p ephemera&lt;br /&gt;
&lt;br /&gt;
Useful queries:&lt;br /&gt;
&lt;br /&gt;
 -- Most recent calls&lt;br /&gt;
 SELECT id, timestamp, mode, model, target_page, outcome&lt;br /&gt;
 FROM ephemera_agent_log ORDER BY id DESC LIMIT 20;&lt;br /&gt;
&lt;br /&gt;
 -- All unassessed rows&lt;br /&gt;
 SELECT id, timestamp, mode, target_page FROM ephemera_agent_log&lt;br /&gt;
 WHERE training_flag = 0 ORDER BY id DESC;&lt;br /&gt;
&lt;br /&gt;
 -- Flag a row as a good training example&lt;br /&gt;
 UPDATE ephemera_agent_log SET training_flag = 1, outcome = &amp;#039;used&amp;#039;&lt;br /&gt;
 WHERE id = &amp;lt;id&amp;gt;;&lt;br /&gt;
&lt;br /&gt;
== Passive Quality Signal ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;target_page&amp;lt;/code&amp;gt; field enables a useful training signal: by joining &amp;lt;code&amp;gt;ephemera_agent_log&amp;lt;/code&amp;gt; against MediaWiki&amp;#039;s &amp;lt;code&amp;gt;revision&amp;lt;/code&amp;gt; table, it is possible to diff what the agent wrote against subsequent human edits — capturing corrections as negative examples and unchanged output as positive signal.&lt;br /&gt;
&lt;br /&gt;
== Retention Policy (Planned) ==&lt;br /&gt;
&lt;br /&gt;
* Unflagged rows: eligible for pruning after a defined retention window (placeholder: 90 days)&lt;br /&gt;
* Rows with &amp;lt;code&amp;gt;training_flag = 1&amp;lt;/code&amp;gt;: archived to JSONL before pruning&lt;br /&gt;
* Rows with &amp;lt;code&amp;gt;training_flag = −1&amp;lt;/code&amp;gt;: pruned immediately on next cleanup pass&lt;br /&gt;
* Session summaries: preserved indefinitely in the &amp;lt;code&amp;gt;Logs:&amp;lt;/code&amp;gt; namespace (not yet implemented)&lt;br /&gt;
&lt;br /&gt;
== Fine-Tuning Roadmap ==&lt;br /&gt;
&lt;br /&gt;
Fine-tuning is not planned until the system is mature and good data has accumulated naturally.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Target !! Use Case !! Timeline&lt;br /&gt;
|-&lt;br /&gt;
| Format/structure LoRA || Reliable MediaWiki markup and template output || Medium-term&lt;br /&gt;
|-&lt;br /&gt;
| Domain knowledge LoRA || System-specific knowledge in weights || Long-term&lt;br /&gt;
|-&lt;br /&gt;
| Worldbuilding LoRA || Ephemera universe knowledge (separate agent) || Long-term&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Fireworks supports LoRA fine-tuning and serves fine-tuned models at base model prices.&lt;br /&gt;
&lt;br /&gt;
[[Category:Help]]&lt;br /&gt;
[[Category:EphemeraAgent]]&lt;/div&gt;</summary>
		<author><name>EphemeraAdmin</name></author>
	</entry>
</feed>