keel
Context

Overview

Build the model’s input from named sections with visible budgets and contents.

Context · ordered sections
System
sys.time · identity · tenancy · rules
Instructions
prompt · skill.0 … skill.n
Tools
tool.<id> · allowed descriptions
State views
render.<block> · reader output
Conversation
history · current user brief
{ id: "render.profile",
  text: "User prefers concise answers.",
  budgetTokens: 128, usedTokens: 8 }
Inspect each source separately before it becomes model input.

Context is the information supplied to an agent's model for a turn. Keel assembles it from named sections: the current time, the app's ambient sections, framework rules, instructions, tools, state views, history, and the current request.

State is what the application remembers. Context is the view of that information, plus instructions and conversation, that the model receives. A model step cannot use a stored value merely because it exists in a block.

Why use sections?

With a single concatenated prompt, it can be difficult to tell which source made a request too large or exposed an unintended detail. Named sections make that input inspectable. Each records its text, budget, and estimated size, so you can trace the input back to its source.

Untracked text
prompt + data
+ history + …
one large string
which source grew?
Keel sections
"prompt"
"render.profile"
"history"
text + budget + usage
→ opening fit check
Named sections make the input traceable; the opening fit check uses their estimated sizes.

The opening fit check applies two conditions: the assembled estimate plus the output reserve must fit the chain's declared window, and the assembled estimate alone must fit the declared input allocation. It refuses an oversized opening request before any model call. It is not exact provider tokenization; each later request is re-estimated as the transcript grows.

Rules by design

  1. Known assembly order

    The runtime assembles system information, instructions, tools, state views, history, and the request.

    system → prompt → skills
    → tools → state → conversation
  2. Explicit state views

    Read declarations select named readers and their budgets; stored objects are not automatically model input.

    block → reader → text
    "render.profile"
  3. Access-filtered tools

    Tool access is checked during assembly and checked again at execution.

    allowed → expose tool
    barred → omit + refuse calls
  4. Visible size overruns

    State renders can be clipped with a notice. Other section overruns produce warnings without clipping.

    render too large → clip + warn
    prompt too large → warn
  5. Fit before every request

    The estimated input plus output reserve must fit the chain window, including growing tool results and recovery text.

    context + reserve ≤ window
    otherwise → fit-overflow

Work with context

GuideWhat you'll learn
Assembling contextFollow the section order and configure instructions and skills.
State and tool viewsRender state deliberately and filter available tools.
History and transcriptsSeparate previous messages from work happening inside the current turn.
Budgets and fitDeclare allocations and understand clipping, warnings, and per-request fit checks.

Next: Assembling context.