For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DASHBOARDPLAYGROUNDDOCSCOMMUNITYLOG IN
Guides and conceptsAPI ReferenceRelease NotesLLMUCookbooks
Guides and conceptsAPI ReferenceRelease NotesLLMUCookbooks
    • Cookbooks
    • Agent API Calls
    • Short-Term Memory Handling for Agents
    • Agentic Multi-Stage RAG with Cohere Tools API
    • Agentic RAG for PDFs with mixed data
    • Analysis of Form 10-K/10-Q Using Cohere and RAG
    • Analyzing Hacker News with Six Language Understanding Methods
    • Article Recommender with Text Embedding Classification Extraction
    • Multi-Step Tool Use
    • Basic RAG
    • Basic Semantic Search
    • Basic Tool Use
    • Calendar Agent with Native Multi Step Tool
    • Chunking Strategies
    • Creating a QA Bot From Technical Documentation
    • Financial CSV Agent with Native Multi-Step Cohere API
    • Financial CSV Agent with Langchain
    • Migrating away from create_csv_agent in langchain-cohere
    • A Data Analyst Agent Built with Cohere and Langchain
    • Advanced Document Parsing For Enterprises
    • End-to-end RAG using Elasticsearch and Cohere
    • Semantic Search with Cohere Embed Jobs and Pinecone serverless Solution
    • Semantic Search with Cohere Embed Jobs
    • Fueling Generative Content with Keyword Research
    • Grounded Summarization Using Command R
    • Hello World! Meet Language AI
    • Long Form General Strategies
    • Migrating Monolithic Prompts to Command-R with RAG
    • Multilingual Search with Cohere and Langchain
    • PDF Extractor with Native Multi Step Tool Use
    • Pondr, Fostering Connection through Good Conversation
    • Deep Dive Into RAG Evaluation
    • RAG With Chat Embed and Rerank via Pinecone
    • Demo of Rerank
    • SQL Agent
    • Summarization Evals
    • Text Classification Using Embeddings
    • Topic Modeling AI Papers
    • Wikipedia Semantic Search with Cohere + Weaviate
    • Wikipedia Semantic Search with Cohere Embedding Archives
    • Build Chatbots That Know Your Business with MongoDB and Cohere
    • Finetuning on Cohere's Platform
    • Deploy your finetuned model on AWS Marketplace
    • Finetuning on AWS Sagemaker
    • SQL Agent with Cohere and LangChain (i-5O Case Study)
    • Introduction to Aya Vision
    • Retrieval Evaluation with LLM-as-a-Judge via Pydantic AI
    • Document Translation with Command A Translate
LogoLogodocs
DASHBOARDPLAYGROUNDDOCSCOMMUNITYLOG IN

Calendar Agent with Native Multi Step Tool

Was this page helpful?
Edit this page
Previous

Effective Chunking Strategies for RAG

Next
Built with
Back to Cookbooks
Open in GitHub

In the example below, we demonstrate how to use the cohere Chat API with the list_calendar_events and create_calendar_event tools to book appointments. Booking the correct appointment requires the model to first check for an available slot by listing existing events, reasoning about the correct slot to book the new appointment and then finally invoking the right tool to create the calendar event. To learn more about Tool Use, read the official multi-step tool use guide.

PYTHON
1# !pip install cohere==5.5.3
PYTHON
1# Instantiate the Cohere client
2
3import cohere
4import os
5
6COHERE_API_KEY = os.environ["COHERE_API_KEY"]
7co = cohere.Client(api_key=COHERE_API_KEY)
PYTHON
1# Define the tools
2
3import json
4
5def list_calendar_events(date: str):
6 events = '[{"start": "14:00", "end": "15:00"}, {"start": "15:00", "end": "16:00"}, {"start": "17:00", "end": "18:00"}]'
7 print(f"Listing events: {events}")
8 return events
9
10def create_calendar_event(date: str, time: str, duration: int):
11 print(f"Creating a {duration} hour long event at {time} on {date}")
12 return True
13
14list_calendar_events_tool = {
15 "name": "list_calendar_events",
16 "description": "returns a list of calendar events for the specified date, including the start time and end time for each event",
17 "parameter_definitions": {
18 "date": {
19 "description": "the date to list events for, formatted as mm/dd/yy",
20 "type": "str",
21 "required": True
22 }
23 }
24}
25
26create_calendar_event_tool = {
27 "name": "create_calendar_event_tool",
28 "description": "creates a calendar event of the specified duration at the specified time and date",
29 "parameter_definitions": {
30 "date": {
31 "description": "the date on which the event starts, formatted as mm/dd/yy",
32 "type": "str",
33 "required": True
34 },
35 "time": {
36 "description": "the time of the event, formatted using 24h military time formatting",
37 "type": "str",
38 "required": True
39 },
40 "duration": {
41 "description": "the number of hours the event lasts for",
42 "type": "float",
43 "required": True
44 }
45 }
46}
47
48# helper function for routing to the correct tool
49def invoke_tool(tool_call: cohere.ToolCall):
50 if tool_call.name == list_calendar_events_tool["name"]:
51 date = tool_call.parameters["date"]
52 return [{
53 "events": list_calendar_events(date)
54 }]
55 elif tool_call.name == create_calendar_event_tool["name"]:
56 date = tool_call.parameters["date"]
57 time = tool_call.parameters["time"]
58 duration = tool_call.parameters["duration"]
59
60 return [{
61 "is_success": create_calendar_event(date, time, duration)
62 }]
63 else:
64 raise f"Unknown tool name '{tool_call.name}'"
PYTHON
1# Check what tools the model wants to use and how to use them
2res = co.chat(
3 model="command-a-03-2025",
4 preamble="Today is Thursday, may 23, 2024",
5 message="book an hour long appointment for the first available free slot after 3pm",
6 force_single_step=False,
7 tools=[list_calendar_events_tool, create_calendar_event_tool])
8
9while res.tool_calls:
10 print(res.text) # This will be an observation and a plan with next steps
11
12 # invoke the recommended tools
13 tool_results = []
14 for call in res.tool_calls:
15 tool_results.append({"call": call, "outputs": invoke_tool(call)})
16
17 # send back the tool results
18 res = co.chat(
19 model="command-a-03-2025",
20 chat_history=res.chat_history,
21 message="",
22 force_single_step=False,
23 tools=[list_calendar_events_tool, create_calendar_event_tool],
24 tool_results=tool_results,
25 )
26
27print(res.text) # print the final answer
Output
I will check the user's calendar for today after 3pm and book an hour-long appointment in the first available slot.
Listing events: [{"start": "14:00", "end": "15:00"}, {"start": "15:00", "end": "16:00"}, {"start": "17:00", "end": "18:00"}]
The user has events scheduled from 2pm to 4pm and from 5pm to 6pm. I will book an hour-long appointment from 4pm to 5pm.
Creating a 1 hour long event at 16:00 on 05/23/2024
I've booked an hour-long appointment for you today from 4pm to 5pm.