Principle:AIScientists Dev WorldSeed Gazette Context Building
| Knowledge Sources | |
|---|---|
| Domains | LLM, Content_Generation |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
A scene-agnostic context assembly pipeline that loads run data from the event-sourcing stream, builds a structured LLM context with six sections (scene, characters, actions, timeline, final state, images), and shapes a journalism-style system prompt for newspaper gazette generation.
Description
Gazette generation transforms a completed simulation run into a newspaper-style article. The context builder (`gazette/context.py`) is scene-agnostic: it works with any scene config because it uses the config's own action definitions to format records, not hardcoded action names.
The pipeline:
- Run data loading: `load_run_data()` reads `meta.json`, `config.yaml`, `stream.jsonl` (all event records), and `state_final.json` from the run directory.
- Language detection: `detect_language()` uses a CJK heuristic on the scene description to determine "zh" or "en".
- Context building: `build_context()` assembles six sections:
- SCENE — description, setting, tick/agent counts
- DRAMATIS PERSONAE — agent character cards
- ACTION VOCABULARY — action names with param types
- EVENT TIMELINE — formatted stream records (register, action, dm_call, consequence, whisper)
- FINAL WORLD STATE — entity snapshots
- AVAILABLE IMAGES — entity image slots for the LLM to pick from
- System prompt: `build_system_prompt()` creates journalism-style instructions with inverted pyramid, short paragraphs, quotes, concrete facts, and section requirements.
Action records are formatted using action definitions (not hardcoded): free_text params become quoted speech, entity_ref params become parenthetical targets, and other params become bracketed metadata.
Usage
Use this principle to generate gazette content from completed runs. The gazette API (`POST /api/gazette/generate`) triggers this pipeline. Results are cached per run.
Theoretical Basis
The context builder follows a data-driven formatting pattern:
# Abstract pattern (NOT real implementation)
def build_context(data, language, assets):
parts = []
parts.append(format_scene(data.config))
parts.append(format_characters(data.config.agents))
parts.append(format_actions(data.config.actions))
parts.append(format_timeline(data.records, data.config.actions))
parts.append(format_final_state(data.state_final))
if assets:
parts.append(format_image_slots(assets))
return "\n".join(parts)
The key insight is that action record formatting uses `action_def.params` to classify params into free_text (quoted speech), entity_ref (targets), and other — no hardcoded action names. This makes the gazette work for any scene.