Conversation persistence: chat.save() / Chat.load() (+ optional local conversation log)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 48/100
調査の方向性
chatlas/_chat.py の Chat.init と set_turns() から始め、chatlas/_provider.py の Provider.name/model、chatlas/_auto.py の ChatAuto()、および chatlas/_turn.py の Turn の検証を確認します。スコープを絞れる場合に限り、永続化の第 1 フェーズのみを実装します。つまり、認証情報なしで provider のメタデータ、system_prompt、turns を復元する JSON エンベロープです。保存された会話を、自動選択された Chat または呼び出し元から渡された Chat に、同等の状態で読み込めれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Motivation
llm logs every prompt/response/tool-call to a local SQLite DB by default, and it's the tool's single most-praised feature (https://llm.datasette.io/en/stable/logging.html). LangChain/LangGraph ship checkpointers (SQLite/Postgres) for the same reason: conversations outlive a single process. chatlas is most of the way there already — Turn (chatlas/_turn.py) is a pydantic BaseModel with a working JSON round trip (including base64-encoded bytes fields as of the CHANGELOG 0.18.0 fix for ContentPDF.data / thought_signature), and Chat.export() (chatlas/_chat.py) already writes markdown/HTML from turns. What's missing is a first-class way to persist and restore a Chat's state (not just a human-readable export), and, optionally, an llm-style append-only log across sessions.
Proposed approach
Phase 1 — chat.save() / Chat.load()
from chatlas import ChatAnthropic, Chat
chat = ChatAnthropic(system_prompt="You are terse.")
chat.chat("Hello", echo="none")
chat.save("conversation.json")
# Writes: provider name + model (e.g. "anthropic/claude-sonnet-4-6", matching
# the `provider_model` string ChatAuto() already accepts — see chatlas/_auto.py),
# system_prompt, and `[t.model_dump(mode="json") for t in chat.get_turns()]`.
# Option A: reconstruct the provider automatically via ChatAuto
chat2 = Chat.load("conversation.json")
# Option B: caller supplies an already-configured Chat (credentials, base_url,
# custom kwargs_chat aren't always representable as a provider/model string)
chat3 = ChatAnthropic(api_key=os.environ["MY_KEY"])
chat3 = Chat.load("conversation.json", chat=chat3)
Grounded in existing code: Chat.__init__ (chatlas/_chat.py:151) takes a provider: Provider, and Provider.name/Provider.model (chatlas/_provider.py:142,149) already give exactly the two strings ChatAuto()'s provider_model argument expects (chatlas/_auto.py:86, e.g. "anthropic/claude-sonnet-4-0"). set_turns() (chatlas/_chat.py:357) already restores conversation state from a list of Turns, and Turn.model_validate/model_validate_json (chatlas/_turn.py:124,172) already dispatch to UserTurn/SystemTurn/AssistantTurn by role — save/load mostly needs to wrap these existing primitives plus a small metadata envelope (provider/model, system_prompt).
Phase 2 — optional local conversation log (explicitly opt-in, llm-inspired)
chat = ChatOpenAI(log_to="~/.chatlas/history.sqlite") # or JSONL; opt-in only
Appends each completed turn (+ token usage/cost from chatlas/_tokens.py) for later search/audit, independent of any particular Chat instance's lifetime — this is deliberately a separate concern from save/load, which round-trips one conversation.
Alternatives / prior art
- ellmer has direct prior art:
contents_record()/contents_replay()(tidyverse/ellmer#503, #689, #895, #906) serializeTurns (and custom subclasses) to plain R lists and back, and #895 specifically extended this to operate on a list of turns rather than one at a time — the same shape as chatlas'sget_turns()/set_turns(). ellmer#1042 ("public API to switch model/provider on an existing Chat while preserving conversation history") is adjacent: it was resolved withChat$set_model()for same-provider switches, leaving cross-provider switching (relevant toChat.load()reconstructing a provider) as an open gap there too. - ellmer#534 ("Too easy to save chat object, accidentally exposing API key") is a cautionary tale: naive
saveRDS(chat)serialized live credentials. chatlas'sTurn-only JSON persistence avoids this by construction (no API key ever enters aTurn), but this should be called out explicitly in docs forchat.save(). - Reference chatlas#121 ("more export types: dataframe, csv, string") as related: that issue wants
.export()refactored so its string content is accessible without a file side-effect. Achat.save()JSON format is a natural complement (round-trippable) rather than a competitor (human/pipeline-readable) to that work.
Open questions
- Default provider-reconstruction story: should
Chat.load()require the caller to pass a constructedChat/Provider(safer, matches ellmer's credential-safety lesson), or default toChatAuto(provider_model)for convenience, with an explicit opt-in? - Should
kwargs_chatand_standard_model_params(chatlas/_chat.py:176,190) be persisted too, or left to the caller to reapply? - Format: plain JSON (simplest, human-inspectable) vs. something more structured — no evidence yet that anything beyond JSON is needed for phase 1.
- Should phase 2's log schema be designed to also serve chatlas's own future needs (e.g. supporting issue #8-style conversation-size limits by keeping cost/token history outside the live
Chat)?
Drafted from a competitive review of llm / Pydantic AI / LangChain / LiteLLM (July 2026); filed via Claude Code on behalf of @cpsievert.
- 主要言語
- Python
- スター
- 179
- フォーク
- 32
- 平均マージ
- 1日 3時間
- マージ済み PR(30日)
- 10
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
posit-dev/chatlas のほかの issue
-
A streaming text delta that repeats everything streamed so far is missing from the recorded turn対応中かも @cpsievert が 81 日前に担当しました。 オープンai-triage:done Priority: Medium
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
ai-triage:needs-review documentation
難易度 2/5 1〜2日 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 1〜2日 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
ai-triage:done Priority: Low
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
メンテナーはふだん 1 日以内に返信
posit-dev/chatlas の issue をすべて見る
似ている issue
-
bot-triaged module: decompositions module: edge cases module: int overflow module: primTorch oncall: pt2 triage review
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
country:US rating:6 request-theme type:TV SHOW
難易度 1/5 1時間未満 初心者へのやさしさ 65/100
LizardByte/ThemerrDB#10501 · コメント 1 件 ·
-
triage/confirmed
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
agentscope-ai/agentscope#4563 ·
メンテナーはふだん 2 日以内に返信
-
comp/desktop desktop/chat P3 type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
NousResearch/hermes-agent#164451 ·
メンテナーはふだん 1 日以内に返信
-
external integration integration-submission
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
langchain-ai/docs#8426 ·
メンテナーはふだん 1 日以内に返信