OpenProgram Docs

Composition

Rules plus a registry: features register components, and adding one does not change the framework. Premise: the model is one part inside a program, told its situation and shown only the history it should see.

Layers follow Hermes's stable, context and volatile split. Hermes reaches them through a hard-wired if chain with two registration points; here every component is a registration.

Most stable tools L0 toolset, MCP breakpoint 1 system L0 base, output style, agent instructions breakpoint 2 L1 environment, AGENTS.md, memory … plan mode breakpoint 3 messages L1 history, grows at the end breakpoint 4 L2 this call: not cached
tools
L0 toolset, MCP · breakpoint 1
system
L0 base, output style, agent instructions · breakpoint 2
system
L1 environment, AGENTS.md, memory … plan mode · breakpoint 3
messages
L1 history, grows at the end · breakpoint 4
messages
L2 this call: not cached

A cache view. The model receives continuous text with no layer or breakpoint wording.

The criterion: where the information flows after this call

LayerRuleContent
L0 systemAlways carried; unchanged all sessionIdentity, instructions, tools
L1 sessionKept for what follows; stable prefixProject blocks, memory, history
L2 taskThis call onlyInput, per-call sections

L2 must follow L1 history: placed before it, per-call text would invalidate the large stable prefix behind it.

Registration

@dataclass
class ContextComponent:
    name: str
    layer: Literal["L0", "L1", "L2"]
    order: int                          # more stable = smaller
    build: Callable[[Any], str | None]  # "" / None = absent this time
    condition: Callable[[Any], bool]    # default: always

Each layer: collect, sort by order, drop false conditions, build, join. Unused features cost nothing.

Registered components

A snapshot, not a limit.

L0

OrderComponentAppears when
10base: who the agent is, how it works, when it stops, what it owns, how it reports, what it trusts (context/prompt_assembly/guides/base.md)Always
20output_styleNon-default style
30inline_prompt: the agent's own instructions; wins conflictssystem_prompt set
—Tools and MCP schema, in the request's tool listAlways

L1

OrderComponentAppears when
10environment: OS, shell, working directory, Git repository, remote environment, extra directories, channel formattingAlways
20agents_md: global, then project root down to cwd; 32 KiB shared budgetAny file
30memory: MEMORY.md map, then core. Like environment, agents_md, open_work and capabilities, a movable section: a conversation keeps the text its prompt was recorded with while nothing else in the prompt changes, and a later version rides the turn's message (see L2)Readable, non-empty
35open_work: what the agent still owesAny open
40capabilities: skill index, Program recipe, deferred tool names (up to 80)Any present
90plan_mode: only for a turn with a prompt of its own; the conversation's own turn gets it beside its message (see L2)Plan mode on
—History: the active branchHistory present
AGENTS.md and the base prompt
  • One file name, layered by directory, each file in <agents_md path applies_to>, most general first so the closer file wins. Global is <state>/AGENTS.md; project root is the nearest ancestor of the working directory holding .git, else the working directory alone.
  • Working directory: the turn's bound worktree or project folder, else the default workdir.
  • A file reached later is appended to the first read, write or edit result touching it, once per session (agent_loop._attach_nested_agents_md), keeping the prefix stable.
  • detect_injection_patterns flags files and does not drop them.
  • No per-agent persona files. Instructions are system_prompt; what is learned about the user lives in Memory's Core. Worker startup retires agents/<id>/workspace/: untouched seeds deleted, edited ones appended to system_prompt and moved to workspace/.retired/.
  • One base prompt read whole; a model needing other steering gets its own base prompt, not an appended snippet.
  • Loaded tools are not repeated in text, so loading another does not change the prompt.
  • App chat's channel line points at guides/a2ui.md instead of carrying the 2 KB catalog every turn.

L2

build_system_prompt assembles L0 and L1 only. Programs add L2 with ctx.context(name, build, layer="L2"), registered as <owner>:<name>. build_turn_sections(agent, turn, channel=, tools=) builds them; builders read turn_inputs(); the conversation's own turn sends the text beside its message as the pages section; another turn (a verification, a check-in) appends it to its system prompt after the goal instructions.

A resumed checkpoint keeps its saved prompt.

Everything below rides in front of the turn's user message, in this order, stored on the user node as its turn_context list (context.prompt_assembly.turn_context). Later requests render the same bytes from it. The code that builds a request passes its audience to the render.

ContentDelivered by
DateToday is {weekday}, {month} {day}, {year}. first in the same prefix, not in the system prompt: it changes at midnight with nothing else changing. The user node stores the date it was sent on (current_date), so a conversation that crosses midnight keeps its cached prefix; Codex likewise sends the date in the turn's environment context
When the date goesA turn sends it only when it differs from the last date in the rendered history (Claude Code, Codex, Kimi Code and OpenCode do the same), so the first turn and the first after midnight or a compaction carry it. A runtime.exec model call gets it too (AgentLoopConfig.dated); a workflow role and a host-supplied call do not
Rewind noteAfter the date: how the conversation and the files relate after a rewind. A rewind leaves it pending on the session; it is taken onto the conversation's next message when that message is stored, so a turn that fails and is sent again still carries it
Section updatesNext, one per changed section, each the whole current text replacing the prompt's section and any earlier update: <memory-map-update> for memory, <system-prompt-update section="…"> for the others, and the open Pages
Recorded prompt keptWhen the recorded prompt differs from the new one only in movable sections (turn_context.kept_sections), it is sent again byte for byte. A new shell comes this way, once, in the environment's update; the prompt keeps the first one
Plan mode, Goal, todosAfter the section updates, on the conversation's own turn, decided from what the rendered history shows: the plan-mode note on entering, every fifth turn after (every fifth note full) and once on leaving (plan_mode.note_for)
Goal and todosDecided the same way: the Goal's full note when no full note in view says the same, else a short one with the usage (goal.chat.goal_note); the Goal's todo list after 10 turns without a todo tool. None of them is in the system prompt, so starting a Goal or entering Plan rebuilds nothing
When an update is sentWhen a section differs from what the request shows: the last update of it in the rendered history, or the prompt's section when none is rendered (compacted, clean or bounded history)
Gone or rebuiltA section that is gone gets an update saying it no longer applies; memory turned off is one such update, and the memory leaves the prompt at the first rebuild after a compaction. Any other prompt change rebuilds the prompt with the current sections. A context engine that does not report the last updates it rendered is assumed to show any stored one
Where updates renderOnly in the conversation's own request, the one turn kind that keeps the branch's recorded prompt (loop_runner.owns_conversation_contract), the memory section's too after memory is turned off: history is never taken back. The user node records that (memory_map_notes), so a resumed turn renders exactly what it sent
Where none renderA tool, runtime.exec or Agent method inside the turn, a Goal verification, a check-in, a workflow and a summary render none: their own prompt holds today's sections. The context panel counts updates when the branch's latest turn sent them
Per-turn memory prefetch_inject_memory_prefetch: prefix inside the turn's user message, on a copy made for the request; it stays on that message when the loop adds notes after it, and later turns render it there from the stored node
Run noteJoined after the memory prefetch, in the same prefix. The user node stores it (run_note), so later turns render it there; a turn resumed from a checkpoint renders it from the node and does not add it again
User input and attachmentsThe user message
The App's open browser Pagesapplication:browser:pages, through build_turn_sections, when the browser application is loaded and the turn has Pages or the browser is available; a section update beside the message when the list changes
Situation, output format and contractDesigned; see below

Anything task-scoped in the core goes into the turn's messages, as the prefetch does. Kanban coordination, Nous guidance and Hermes profiles have no counterpart feature, so nothing is registered.

Text of the built components
You are {name} (agent_id={agent_id}), an agent running in OpenProgram on the user's computer.{mentions}
# How you work …
# Finishing work …
# The project is yours …
# How you report …
# What to trust …

<environment>
OS: {os} · Shell: {name} ({path})            # the shell commands run in (the sandbox's when it is on), not the login shell
Working directory: {cwd}
Git repository: {root}                       # when cwd is inside one
Environment: machine {id} ({name}; {shell}) …  # environment on another machine
The chat itself and OpenProgram run on this computer …
Also writable: {dirs}
{channel rule}                               # telegram / discord / slack / wechat / web
</environment>

The channel is the turn's source, passed to build_system_prompt(channel=...). A web turn in a chat bound to a channel conversation gets none, because replies go to that channel as text. Sources with no rule (tui, acp, agent_spawn) add no line. The web rule is the whole of guides/visuals.md; every name it lists must exist in openprogram/interfaces/server/routes/visual-frame.html and apps/web/lib/chat/markdown/visual-frames.ts.

Parent and child: two settings

SettingControlsDefault
exposeHow much a function shows outward: io, llm, full, hiddenio: identity, input, output. OPENPROGRAM_EXPOSE_DEFAULT overrides it
render_rangeHow much history a call pulls: {callers, subcalls}Unlimited; compacted only over budget

Designed: the call tree and situation

L1 history as one active path of the DAG, rendered as a YAML tree carrying input and output. It grows and releases only at the tail, so the prefix stays cached and size follows call depth, not total calls.

Called thingCalls the model again?In the tree
Agentic functionYesEnters; recurses by this same rule
Plain function or toolNoCollapsed
The inference itself—Not in the tree; its output is the function's output

Structure is cheap, so a finished subtree keeps its function lines; input and output are expensive, so they are released (status: done), and the subtree root keeps its key output. Structure and history stay one block: split, the changing structure block would never hit the cache.

Situation block and output contract
<situation>
You are running INSIDE the agentic function `{fn_name}`.
Job: {fn_doc}
Call path: {call_path}
Position: {program_position}
Your output: {output_contract}

The tool list may include `{fn_name}` itself — do NOT call it (re-entering
causes infinite recursion). Use lower-level tools to do the work directly.
</situation>
FieldSource and example
fn_nameFrame node name
fn_docFirst docstring sentence, frame node metadata
call_pathAlong the caller chain: paper_agent → _pick_stage → literature → seed_surveys
program_positionPassed by the caller, optional: step 1 of the literature stage, next → extract_framework
output_contractOptional. Parsed into a decision: emit one JSON object matching the menu. Deliverable: becomes {artifact} for {consumer}. Passed on: goes to {next_fn} as {param}

Paired tags, so # or code in the content cannot be read as a delimiter. Inserted as the first text block of the call's user message, followed by prefetch, input and any output schema.

Call tree format, step by step

YAML: familiar, cheap, hierarchical by indent, multi-line values in | blocks. Fields: function, input, output, status (running or done), children.

Running _lit_decide, tree at level 3; L0 unchanged afterward:

<call_tree>
- function: paper_agent
  input: "expand LLM-as-Code into an AAAI long paper"
  children:
    - function: _pick_stage
      output: "go to literature"
    - function: literature
      input: "LLM-as-Code → AAAI"
      status: running
      children:
        - function: _lit_decide
          status: running          # you are here
</call_tree>

Running seed_surveys: _lit_decide collapses to its output; arxiv_search and other plain tools stay out:

        - function: _lit_decide
          output: "next step seed_surveys"
        - function: seed_surveys
          status: running          # you are here
          input: "query: LLM agent frameworks surveys …"

Second _pick_stage: literature finished, structure kept, input and output released:

    - function: literature
      output: "framework{name, 4 branches}"
      children:
        - {function: _lit_decide, status: done}
        - {function: seed_surveys, status: done}
        - {function: extract_framework, status: done}
    - function: _pick_stage
      status: running              # you are here

check_novelty, an agentic function nested in idea, recurses to level 5:

    - function: idea
      status: running
      children:
        - function: generate_ideas
          status: running
          children:
            - function: check_novelty
              status: running      # you are here

The memory block

Memory reaches the model twice; a component it cannot name is one it cannot reason about. Details and comparison: Memory introspection.

StateDesignToday
Recall (L2)<memory-context> and the note that this is not new user inputAs designed
Resident (L1, 30)<memory> from fence_core: which subsystem wrote it, its workspace, a budgeted summary, which tools reach the restUses the recall fence
Tool catalogThree memory_* names; schemas stay off the wireBuilt: DEFAULT_TOOLS and DEFERRED_DEFAULT_TOOLS
Backend offNothingAs designed
EmptyOne line: on, holds nothing yet, fills on its ownNothing
Provider raisedOne line: did not load; absence is not evidenceNothing
<environment>Names the harness and its state directoryMachine, working directory, repository

Implementation status

StatusItems
BuiltContextComponent and three registries in context/prompt_assembly/components.py: nine core components, open_work from the conversation package, and Program sections. Conversation and function calls both use render_context (context/session_dag/nodes.py) and render_dag_messages: frame_entry_seq=-1 at top level; otherwise render_range and expose set visibility
Not yetThe YAML call tree: history renders as provider messages. The situation block and output contract; only the depth ceiling guards self-recursion. A cacheable field. Computer-use guidance and a token budget hint. fence_core, the empty and failed lines, and the <environment> harness lines

Component comparison with reference projects

Last updated · 2026-11-25