Skip to content

Instruction Layer

chimera.core.instruction builds system prompts from composable layers instead of a single monolithic string. Each layer can be independently added, enabled, disabled, or reordered by priority. Inspired by Codex’s personality + instruction + project doc system.

ClassDescription
InstructionLayerComposable prompt builder with priority-ordered layers
LayerA single layer with name, content, priority, and enabled
from chimera.core.instruction import InstructionLayer
il = InstructionLayer()
il.add("base", "You are a coding assistant.", priority=100)
il.add("personality", "Be concise. No fluff.", priority=90)
il.add("project", "This project uses Python 3.12 and pytest.", priority=50)
prompt_text = il.render()
# Layers are joined in priority order (highest first)
il.disable("personality") # Temporarily turn off a layer
il.enable("personality") # Re-enable it
il.remove("project") # Remove entirely (returns True/False)

render() supports {variable} replacement:

il.add("greeting", "Hello {user_name}, working on {project}.", priority=80)
text = il.render(user_name="Alice", project="chimera")
il.add_from_file("project", "~/my-project/AGENT.md", priority=50)
il.add_from_directory("~/.chimera/instructions/", priority_start=40)
# General coding agent with optional project context
il = InstructionLayer.coding_agent(project_context="Uses Flask + PostgreSQL")
# Code reviewer
il = InstructionLayer.reviewer()

Use to_prompt() to get a Chimera Prompt object for use with an agent:

prompt = il.to_prompt(user_name="Alice")
from chimera.core.instruction import InstructionLayer, Layer