- Home
- Skills
- Rshvr
- Unofficial Cohere Best Practices
- Cohere Streaming
cohere-streaming_skill
0
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill rshvr/unofficial-cohere-best-practices --skill cohere-streaming- SKILL.md5.7 KB
Overview
This skill documents a practical reference for Cohere streaming across real-time text generation, tool use events, and retrieval-augmented generation (RAG) citations. It consolidates event type handling, async streaming patterns, full-response collection, tool call flows, and error handling into concise examples. Use it to implement production-ready streaming chat UIs and agent tool integrations with Cohere APIs.
How this skill works
The skill demonstrates iterating over co.chat_stream (sync and async) to receive discrete stream events such as content-delta, message-start, and message-end. It shows how to assemble partial content chunks into a complete response, surface tool planning and tool-call events, and capture citation-generation events when providing RAG sources. Examples include safe streaming wrappers with API error handling and simple hooks for token-level UI updates.
When to use it
- Building a real-time chat interface that renders tokens as they arrive.
- Implementing agents that call external tools and must stream planning and tool-call activity.
- Capturing RAG citations in-stream and displaying source metadata alongside text.
- Collecting the complete generated response while showing partial output to users.
- Handling streaming in asynchronous Python applications or event loops.
Best practices
- Listen for all event types (message-start, content-delta, content-end, message-end) to maintain correct UI state and final response capture.
- Accumulate content-delta chunks in a list and join them at message-end to avoid lost tokens or ordering issues.
- Expose token-level callbacks (on_token) for low-latency UI updates and an on_complete callback for post-processing.
- Handle tool-plan-delta, tool-call-start/delta/end to show plan and arguments, and to execute tool calls deterministically.
- Wrap streaming in try/except to catch ApiError and unexpected exceptions and to provide graceful user feedback.
Example use cases
- A chat app that streams model responses token-by-token and shows a typing indicator during message-start.
- An agent that streams its instrumented plan, then makes tool calls while streaming tool-call events to a diagnostic pane.
- A RAG-enabled assistant that shows inline citations as citation-generation events arrive and lists sources at completion.
- An async web server endpoint that returns streamed SSE or websocket messages using async_co.chat_stream.
- A CLI tool that prints incremental output and recovers from stream interruptions with a safe_stream wrapper.
FAQ
Collect content-delta chunks into a list during the stream and use the message-end event's response field for the final structured object.
Can I stream tool calls and capture their arguments?
Yes. Monitor tool-plan-delta, tool-call-start, tool-call-delta, and tool-call-end events to observe planning text and generated tool-call arguments in real time.