posit-dev / posit-dev/commons

Support shinychat history for composed Chatlas clients such as Python Commons

Open
#347 0 comments 0 reactions 1 assignee View on GitHub

@jat255 is already working on this.

Since Sep 14, 2026.

py
Dominant language
Python
Stars
44
Forks
1
Avg merge
1d 7h
Merged PRs (30d)
142

Description

For Python only, when using commons with page_chat, the conversation history feature doesn't work; it's always blank.

Python Commons deliberately composes a chatlas.Chat rather than subclassing it. It exposes Chatlas-compatible behavior:

  • stream_async(...)
  • get_turns() -> list[chatlas.Turn]
  • set_turns(Sequence[chatlas.Turn])

This allows shinychat to stream from a Commons agent directly.

However, shinychat recognizes Chatlas turn history using a nominal check equivalent to:

isinstance(client, chatlas.Chat)

Other clients follow the generic ClientWithTurns path, which expects JSON-round-trippable turns. Commons therefore falls into the generic path even though its history uses chatlas.Turn semantics.

The result is that direct streaming works, but shinychat's conversation history and New Chat support require an application-level adapter that converts:

chatlas.Turn <-> JSON dictionaries

For example, the desired integration is roughly:

agent = Commons(...)
chat = shinychat.Chat("chat", client=agent)
ui = shinychat.page_chat("chat", history=True)

without needing a wrapper solely for history serialization.

History restoration also needs to call Commons.queue_restore_reminder(), similar to the hook installed by R's commons_server().

Possible directions

Some possible fixes:

  • Have shinychat or chatlas define an explicit protocol or capability for clients whose history uses chatlas.Turn.
  • Give clients explicit JSON history serialization/deserialization methods.
  • Standardize one history representation across shinychat clients.
  • Add a Python integration helper analogous to R's commons_server().

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.