- Home
- Skills
- Rshvr
- Unofficial Cohere Best Practices
- Cohere Python Sdk
cohere-python-sdk_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-python-sdk- SKILL.md7.8 KB
Overview
This skill is an unofficial reference and best-practices guide for using Cohere's native Python SDK with Command models, embeddings, reranking, streaming, structured outputs, RAG, and tool-based agents. It focuses on practical examples, client setup, and patterns for robust production usage. Use it to speed up development when building Python applications that call Cohere APIs for chat, tool calling, or retrieval-augmented generation.
How this skill works
The skill documents common SDK flows: initializing sync and async clients, issuing chat requests, enabling streaming, and configuring parameters like temperature, top-p, and max tokens. It explains how to define and execute tools (function calling), integrate multi-step agent patterns, enforce structured JSON outputs or JSON Schema, and pass documents for RAG. Also covered are reasoning controls, safety modes, streaming event handling, and basic error handling patterns.
When to use it
- Building conversational assistants with Cohere Command models in Python.
- Implementing tool use or function-calling workflows where the model triggers external code.
- Streaming large model responses to a UI or CLI with incremental updates.
- Producing machine-readable outputs using JSON mode or JSON Schema enforcement.
- Implementing retrieval-augmented generation (RAG) with document citations and embeddings.
Best practices
- Initialize clients via environment variables for secure key management; use custom base_url for private deployments.
- Prefer streaming for lower perceived latency and to surface intermediate tool plans or calls.
- Wrap tool execution loop: detect tool_calls, run local functions, append tool outputs as tool messages, then call chat again.
- Use response_format with json_schema for strict outputs and strict_tools to avoid parameter hallucinations.
- Control reasoning (thinking) to balance latency vs. complex multi-step problem solving.
- Catch ApiError and general exceptions; surface status_code and body for observability.
Example use cases
- Chatbot that calls external APIs (weather, calendar) via defined tools and returns structured results.
- Document Q&A system where user queries are answered from ingested documents with citations (RAG).
- Interactive code assistant that streams incremental code suggestions and uses tool plans for test execution.
- Data extraction pipeline that enforces JSON Schema to populate structured records from free text.
- High-throughput embedding and reranking pipeline for semantic search and relevance tuning.
FAQ
Set tool_choice to "REQUIRED" when calling chat so the model must emit a tool_call rather than answering directly.
How can I ensure machine-readable output?
Use response_format with type "json_object" and optionally provide json_schema; combine with strict_tools to prevent hallucinated params.