Skip to content

Support shinychat history for composed Chatlas clients such as Python Commons #347

Description

@jcheng5

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().

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

pyAffects the Python implementation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions