Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:AIScientists Dev WorldSeed Gazette Context Building

From Leeroopedia
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:

  1. Run data loading: `load_run_data()` reads `meta.json`, `config.yaml`, `stream.jsonl` (all event records), and `state_final.json` from the run directory.
  2. Language detection: `detect_language()` uses a CJK heuristic on the scene description to determine "zh" or "en".
  3. Context building: `build_context()` assembles six sections:
    1. SCENE — description, setting, tick/agent counts
    2. DRAMATIS PERSONAE — agent character cards
    3. ACTION VOCABULARY — action names with param types
    4. EVENT TIMELINE — formatted stream records (register, action, dm_call, consequence, whisper)
    5. FINAL WORLD STATE — entity snapshots
    6. AVAILABLE IMAGES — entity image slots for the LLM to pick from
  4. 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.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment