A local-first multi-agent app development platform, built on PenguinHarness
Switching the model inside a Session
- Date: 2026-09-16
- Type: feature
- Scope:
core,server,web,cli,docs - PR: #748
A Session could run on only one model: the model reference was fixed when the Session was created, and changing it meant /model, which opens a new conversation. A Session can now switch models in place. The switch compacts the context on the current model first, and only when that compaction completes does the next model context open on the target model, carrying the summary. One Session can therefore run several models over its life. Changing the thinking level still leaves compacting first to the user; a model switch always compacts.
Core
Session.switchModel({ provider, modelId, signal })streams the switch and returns its terminal status. The target is checked against the Project config on disk and its client is constructed before any event, so a missing model or credential is refused without touching the Trace. Switching to the current model does nothing.- The model reference moved from the Session to the model context. Context assembly resolves the entry each context opens on, and
Session.provider/Session.modelIdread the running context'ssession_meta. Subagents spawned after a switch inherit the new model; the image fold andread_file's vision describer follow the current entry; explicit SDK credentials apply only to the model the Session was created with. - A switch always summarizes, whatever
compaction.modesays. Its compaction request is an ordinary one on the current model — the same system prompt, toolset and parameters, one appended user turn — so it extends the prefix the provider has cached. A context with no completed turn has nothing to summarize and switches without a request or a compaction pair: right after a compaction the held summary is carried over; an open context whose first request never completed is left as it is, its pending text carried over in memory and the summary it opened with, if any, written again at the head of the new file; a Session that never ran is re-assembled on the target without writing anything. A switch carries text only: pending images are not carried to the new context. - A switch's compaction is an ordinary
manualcompaction; the next context's Trace file opens as soon as the switch completes, headed by itssession_meta, and that record is also streamed — no OmniMessage field or enum value was added.resumeSessiontherefore lands on the new model from the Trace alone, with the summary pending — and still written on to the next file by another switch made before the first turn completes. A switch interrupted before its new file exists resumes on the model the Session was on, the summary still pending. - A failed or aborted switch leaves the Session on its model.
- The switch's known refusals are thrown as
ModelSwitchRefusedErrorwith areason(model_not_configured,model_unavailable,compaction_not_configured), so a host maps them without reading messages; any other error is a failure.
Server
POST /api/sessions/:sessionId/switch-modelwith{ provider, modelId }. It answers 202 and streams like/compact(statuscompacting), or 200 with the updated Session when the Session had never run. Refusals are 409task_in_progress,compacting,same_model,model_not_configured,model_unavailableandcompaction_not_configured; any other error core throws before its first event answers 500.- The Session row's
provider/model_idbecame the current model: they move as the new context'ssession_metapasses through the stream and are reconciled from the loaded Session. The switch's compaction request is billed to the old model and later requests to the new one. A fork takes its model from the shard it cuts. - The switch is the Session's run from its first step: it can be stopped, and a deletion waits for it, before anything has streamed.
Web
- The model badge of an open conversation became a model picker. Picking another model asks for confirmation (compact and switch, or cancel); an empty conversation switches directly, and right after a compaction or another switch the dialog says nothing is compacted again and only offers "Switch". The picker is disabled while the conversation runs or compacts. The conversation shows the switch as an ordinary compaction row (when there was something to compact) followed by a "Model switched · A → B" marker, derived from two consecutive
session_metarecords, and the page picks up the new model when the switch completes. - A Task's cost estimate is priced on the model the Task ran on, so the rows above a switch keep their figures.
/modelkeeps opening a new conversation on another model; its description, picker, chip and banner now say so.
CLI
penguin chatgained/switch-model <provider> <model_id>; bare/switch-modelprints the current model. The REPL renders the switch's compaction like any other and printsmodel: A → Bwhen it completes.--resumestill rejects model flags and points to/switch-model.