A local-first multi-agent app development platform, built on PenguinHarness
Every model context is assembled whole from the Agent State as it is when it opens
- Date: 2026-08-28
- Type: feature
- Scope:
core,server,web,cli,docs - PR: #539
- Breaking: yes — SDK:
SessionConfig.createLLM/ContextEngineDeps.createLLMbecameopenNextContext,RunOptions.thinkingLeveland the per-round thinking level of the subagent seams are gone,SessionConfig.commandPolicyis a per-context source; HTTP API:POST /tasksand the subagent message no longer takethinkingLevel, and a follow-up recall no longer returns one
A compaction now opens its new model context exactly as a new Session opens its first: everything
under the Agent State is read from disk at that moment — system_config.yaml in full (the prompt
template with its section prompts and toggles, the builtin tool entries and MCP Servers, the
compaction settings, max_turns, the model defaults), AGENTS.md, the vault, the installed
Skills' metadata, the Memory indexes and the schedule roster. An edit made during the old
context — by the model working on its own configuration, or by hand in the Agent settings —
takes effect at the next compaction rather than the next Session. Runtime parameters now fall
into three explicit tiers: strict (system prompt, toolset incl. MCP, compaction settings,
model reference — the request prefix, byte-fixed across a whole Trace file so the provider's
prompt cache holds; the vault, per-tool r/rw permissions and the command policy never
reach the model but are read once per context, on the same rotation schedule), soft (the
thinking level: changeable mid-context, effective from the next request, at the cost of the
provider's cached context — the pickers advise compacting first), and unrestricted (the
approval mode: re-read from the DB per decision, effective immediately).
Details
- Three openers assemble a context the same way: Session creation, a completed compaction (summarize and discard alike), and a resume that finds its latest Trace file closed by a completed compaction. A resume of an open context keeps the prompt its file recorded — the replayed history was produced under that prefix — and takes tools, Environment, vault and run settings from the current Agent State, as before (the Trace records no executable configuration).
- The thinking level is the soft-limited tier — a purely per-request parameter: every LLM
request takes the Session's pinned level — the Web App's in-chat picker, the CLI's
--thinking//thinking, the SDK'sSession.thinkingLevelstate — or, unset, the Agent config'smodel.thinking_levelas read when the context opened. A re-pin applies from the very next LLM request, mid-context included, and nothing is recorded in the Trace; because a change invalidates the provider's cached context, the change points remind the user first (the web picker's menu note, the CLI/thinkingreply) that compacting is recommended. Compaction requests keep the context's opening base — their prefix must stay byte-identical. Nothing rides a run or a task. - Per-tool
r/rwpermissions and the command policy are strict-tier as well:Session.toolPermissionanswers from the running context's toolset (rebuilt at every rotation, MCPpermissionoverrides included), and the command policy is read from.project_config.tomlonce per context open — no approval decision reads a file. The unrestricted tier is the approval mode alone, re-read from the DB on every decision. - Fixed for the Session's lifetime: its id, Workspace, model entry (credentials, window and per-model annotations included), origin, and the Environment's process host — background commands, subagent child sessions and their listeners survive the rotation.
- The Environment is re-equipped for the new context (
Environment.reconfigure): the vault's values go straight into the command environment of every command spawned from then on (processes already running keep the environment they started with). MCP connections are cached by config: a server whose entry is unchanged keeps its live connection and discovered tools — a Session that compacts every turn does not respawn its servers — a removed or changed one is closed, and only new, changed or previously failed servers connect, bracketed by the samemcp_connect_begin/mcp_connect_endpair the first run streams (naming just those servers), followed by the newtool_list_ready; the engine yields them live. - Each Trace file a compaction's rotation opens starts with the
session_metarecording the prompt its context runs with, then the connect pair (if any) and the toolset record;Session.metaMessagefollows the running context. - An Agent State that cannot be assembled when a context opens (a
system_config.yamlthat no longer parses) fails the run with that error and the engine stays on the old context — the same error a new Session would hit; there is no silent fallback. - Agent State loading is one function:
loadAgentState— withinitit is the create-or-load entry (createAgent, provisioning;loadOrInitAgentStateis gone), without it a missing Agent throws, which is what a model context opening mid-session must see. SocreateSessionandresumeSessionread the disk too, and an Agent object held across edits — a self-spawned subagent's, for instance — no longer starts Sessions on its load-time snapshot. - Opening a context is one procedure as well: the first run's bootstrap and the
post-compaction
openNextContextshare the same implementation (connect what is pending, publish the connect pair and the toolset record throughemit, build the LLM), delivered live by the same merge-queue pump on both paths. - The server no longer rebuilds an Agent's cached Session runtimes when its vault is updated: the
new values reach a running Session at its next compaction, the same timing the CLI's
in-process Session has. The Agent settings pages (prompt, runtime, tools and MCP, memory,
schedules, vault, skills), the CLI's
config vault set/removeand the in-chat thinking picker say so where the change is made: new conversations pick a change up right away, running ones after their next compaction.
Compatibility
- SDK:
SessionConfig.createLLMandContextEngineDeps.createLLMare replaced byopenNextContext({ emit }) => OpenedContext | Promise<OpenedContext>, withOpenedContextbeing{ llm, sessionMeta?, maxTurns?, compaction? }; records passed toemitare yielded on the run stream and written at the head of the rotated Trace file, and the engine is the sole author oftoken_usage.session— the LLM reports per-request usage only, andGenerativeModelno longer carries asessionTokensfield. Code that constructsSessionorContextEnginedirectly returns{ llm }where it returned the LLM before; theAgent.createSession/resumeSessionpath needs no change.Environmentgainsreconfigure({ toolConfig, vault })andpendingMcpServerNames(). - SDK:
loadOrInitAgentStateis folded intoloadAgentState— passinit: {}(orinit: { preset }) for the create-or-load behavior; withoutinita missing Agent throws.SessionConfig.bootstrapnow takes{ emit }and returns{ llm }(notoolsormcpfield), publishing its connect pair and toolset record throughemit; theSessionConfig.mcpServersfield is gone — the bootstrap knows what it is connecting. - SDK:
RunOptions.thinkingLevel,SubagentHandle.run'sthinkingLevelandSubagentMessageOptions.thinkingLevelare removed; a host that changed the level per run assignsSession.thinkingLevel = levelinstead — plain state, forwarded into the engine (ContextEngine.setThinkingLevel) and applied from the next LLM request. - SDK:
SessionConfig.commandPolicytakes a source function instead of a static config — the composition layer's source answers with the running context's policy, read from.project_config.tomlonce per context open.Session.toolPermissionkeeps its synchronous signature and answers from the running context's toolset. - HTTP API:
TaskCreateRequest.thinkingLeveland the subagent message'sthinkingLevelare no longer read (a client still sending them is ignored), andRecalledMessageResponseno longer carries one.PATCH /sessions/:id { thinkingLevel }is the way to set a level; it applies from the Session's very next LLM request. - Traces: no format change and nothing to migrate. A Trace file's
session_meta.system_prompthas always been the prompt that file's context ran with; it now differs between the files of one Session when the Agent State changed in between, and a rotated file's head carries the context's connect pair before itstool_list_ready. A reader that took the first file's prompt or toolset as the Session's only one should read the file it is rendering.