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().
For Python only, when using commons with page_chat, the conversation history feature doesn't work; it's always blank.
Python
Commonsdeliberately composes achatlas.Chatrather 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:
Other clients follow the generic
ClientWithTurnspath, which expects JSON-round-trippable turns. Commons therefore falls into the generic path even though its history useschatlas.Turnsemantics.The result is that direct streaming works, but shinychat's conversation history and New Chat support require an application-level adapter that converts:
For example, the desired integration is roughly:
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'scommons_server().Possible directions
Some possible fixes:
chatlas.Turn.commons_server().