Skip to main content

cobito

pypi python

Turn a Slack thread into a conversation for your AI agent, and stream the agent's reply back into the thread.

cobito is the Slack side of an agent bot, kept apart from how the bot calls its model or agent. It streams a reply of any length with Slack's chat streaming, shows tool calls as tasks in the reply, marks the post being worked on, and makes a conversation smaller when the agent cannot take it.

Install

pip install cobito

cobito is asynchronous and works with slack-sdk's AsyncWebClient, as Bolt's AsyncApp hands it to listeners.

Usage

Streaming a reply

RotatingChatStream has the append/stop surface of slack-sdk's AsyncChatStream. When a message nears Slack's length limit, the reply moves on to a new message in the same thread at a paragraph break, so no table or code block is cut in two.

from cobito import RotatingChatStream, ToolUse, tool_chunks

stream = RotatingChatStream(
    client,
    channel=channel_id,
    thread_ts=thread_ts,
    recipient_team_id=team_id,
    recipient_user_id=user_id,
    buffer_size=256,
)
await stream.append(chunks=tool_chunks(started=ToolUse(name="search", tool_use_id="t1")))
await stream.append(chunks=tool_chunks(completed=ToolUse(name="search", tool_use_id="t1")))
await stream.append(markdown_text="Here is what I found.")
await stream.stop()

The stream opens on its first append, so a reply that fails before it has anything to show leaves no empty message behind. On shutdown, close_open_streams(markdown_text=...) closes every reply still streaming, with a note saying why.

Marking the post being worked on

from cobito import WaitingReaction

waiting = WaitingReaction(client, channel_id=channel_id, message_ts=message_ts)
await waiting.add()
try:
    ...  # reply
finally:
    await waiting.clear()

Both calls are best-effort: without the reactions:write scope the post goes unmarked.

Resending a conversation that is too long

When the agent fails before sending anything back, the conversation may have been more than its model takes. Send it once more as it was, then drop the oldest turns with drop_older_turns, a tenth on the first try and twice as many on each try after. The newest turn is always kept, and a turn keeps a question together with the bot's replies to it.

from cobito import apply_history_cut, drop_older_turns, history_cut_metadata

EVENT_TYPE = "my_bot_history"

replies = apply_history_cut(replies, bot_user_id=bot_user_id, event_type=EVENT_TYPE)
sent = replies
resent_unchanged = False
dropping_tries = 0
while True:
    cut = history_cut_metadata(sent[0]["ts"], event_type=EVENT_TYPE)
    try:
        await reply_with(sent, metadata=cut if dropping_tries else None)
        break
    except AgentFailedBeforeReplying:
        if not resent_unchanged:
            resent_unchanged = True
            continue
        dropping_tries += 1
        shorter = drop_older_turns(
            replies, bot_user_id=bot_user_id, attempt=dropping_tries
        )
        if shorter is None:
            raise
        sent = shorter

history_cut_metadata goes on the reply as message metadata (stop(metadata=...)), and apply_history_cut reads it back from the thread, so the next turn starts from what fitted. Read the thread with conversations.replies(include_all_metadata=True) for the metadata to be there. The event type is yours to name; a cut recorded under another type is ignored.

API

Name What it does
RotatingChatStream A streamed reply that continues in a new message when one fills up
close_open_streams(markdown_text=) Close every reply still streaming, for shutdown
note_after_reply(text) Set a note off from the reply it is appended to
ToolUse, tool_chunks(completed=, started=, error=) The chunks that show a tool call starting and finishing
PLAN_TITLE The heading over the tool calls
WaitingReaction, WAITING_REACTION The reaction on the post being worked on
history_cut_metadata(oldest_ts, event_type=) The message metadata recording where a conversation was cut
apply_history_cut(replies, bot_user_id=, event_type=) Keep the replies from the last recorded cut
drop_older_turns(replies, bot_user_id=, attempt=) Drop the oldest turns for one try

License

MIT

Metadata

Release files for cobito 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cobito 0.1.0
File Size Uploaded Provenance Actions
cobito-0.1.0.tar.gz 19.4 kB With provenance Details for cobito-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cobito 0.1.0
File Interpreter ABI Platform Actions
cobito-0.1.0-py3-none-any.whl Python 3 none any Details for cobito-0.1.0-py3-none-any.whl

Total release size: 35.0 kB

Release files / cobito-0.1.0.tar.gz

Download URL cobito-0.1.0.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5c846609792e9e99b1cac734a1e02b3992ded431747b65650d1640be1c9a2039
BLAKE2b-256 checksum
How to use checksums
8a8d08b894240d44e1422fe5aa9a08ef76ec0bf58f6f28584c9250bed8df6e6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / cobito-0.1.0-py3-none-any.whl

Download URL cobito-0.1.0-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8489ba8f4a9e13e6355a63541a8a161e3023675532d0233e2d47f3434fad2409
BLAKE2b-256 checksum
How to use checksums
fb19a1383e2342acd43a37625a9947fe1b08aff8712137d09a152609108786b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Security for cobito 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cobito-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page