ChappieClient maintains a private transcript and thread ID that grows with each call to send, stream, or response. This accumulated context lets the model remember earlier turns and refer back to them — but it also consumes tokens. Chappie exposes a set of async methods on ChappieClient that let you inspect, reset, restore, and summarize that context at any point, giving you precise control over what the model sees without managing message arrays yourself.
Snapshot the current context
Callcontext() to get a point-in-time copy of the client’s internal state. The returned ChappieClientContext is a plain Codable value — it owns no connection to the live client, so you can store it, archive it to disk, or pass it to another part of your app.
ChappieClientContext fields
ChappieClientContext fields
A UUID string identifying this client instance. Stays the same across context clears unless you resume a different context.
A UUID string used as the prompt cache key for the current conversation thread. Resets when you call
clearContext().The model selected on the client at the time of the snapshot.
The full message history accumulated so far in the current thread.
A compaction summary written either by you or by the model. When non-nil, Chappie prepends it to the next request as a system message so the model has continuity even after
messages has been cleared.The timestamp when this context (or the last clear/resume) was started.
The timestamp of the most recent mutation — turn recorded, model change, compaction, or resume.
A computed shorthand for
messages.count.A local token estimate based on character counts — useful for deciding when to compact. Not a substitute for server-reported usage.
Measure context size
CallcontextSize(contextWindow:) to get a ChappieContextSize snapshot that pairs the local estimate with a known context window size. Pass the model’s actual context window — for example, 272_000 for a 272k-token model — to get remaining-token and percentage-used values.
ChappieContextSize fields
ChappieContextSize fields
The number of messages in the current transcript.
A heuristic token count derived from visible character counts in the stored messages.
The context window size you passed in, or
nil if you called contextSize() without one.contextWindow - estimatedTokens, floored at zero. nil when contextWindow is not set.estimatedTokens / contextWindow × 100, capped at 100. nil when contextWindow is not set or is zero.Clear context
CallclearContext() to wipe the transcript and start a fresh thread. The client assigns a new threadID, clears messages and compactedSummary, and resets createdAt. The next send, stream, or response call starts from a blank slate.
Resume a saved context
Pass a previously snapshottedChappieClientContext back to the client to restore it:
Compact context
Compaction replaces the fullmessages array with a summary, reducing the tokens the model needs to process on the next turn while preserving conversational continuity.
Manual compaction — you write the summary
CallcompactContext(summary:) with a string you compose yourself. Chappie stores it as compactedSummary, clears messages, and prepends the summary as a system message on the next request:
Automatic compaction — the model writes the summary
Call the throwing overloadcompactContext() with no arguments. Chappie sends the current transcript to the model with a built-in compaction prompt, waits for the model’s summary, then applies it:
Parallel conversations need separate clients
ChappieClient serializes turns through an internal coordinator, so calling send or stream concurrently on the same instance queues the calls rather than running them in parallel. More importantly, all turns share the same transcript — interleaving unrelated conversations on one client corrupts the history.