Notebooks
C
Cohere
1 Tool Use Basic Reasoning

1 Tool Use Basic Reasoning

guidesnotebooksreasoningcohere-developer-experience

Command A Reasoning - Basic Tool Use Example

Overview

This notebook demonstrates the fundamental concepts of tool use with Cohere's Command A reasoning model. You'll learn how to define tools, make function calls, handle responses, and work with the reasoning traces that show the model's decision-making process.

Contents

  • Setting up basic tool definitions and function mappings
  • Understanding tool schemas and parameter specifications
  • Making your first tool call with reasoning traces
  • Processing tool results and generating responses
  • Working with citations and source attribution
[1]
[3]
[4]
[5]
[10]
[11]
The user is asking for the weather in Toronto. I need to use the available tool 'get_weather' to retrieve this information. The tool requires a 'location' parameter, which the user has provided as Toronto. I'll call the tool with the location set to Toronto. 

[ToolCallV2(id='get_weather_sfnmhqhb8g2p', type='function', function=ToolCallV2Function(name='get_weather', arguments='{"location":"Toronto"}'))]
[12]
[13]
The user asked for the weather in Toronto. I used the get_weather tool with the location parameter set to "Toronto". The tool returned a result indicating a temperature of 20°C. Since the response only includes the temperature, I'll check if there's additional weather information needed. However, based on the tool's output structure, it seems only the temperature is provided. I'll proceed to inform the user of the current temperature in Toronto.
--------------------------------------------------
The temperature in Toronto is 20°C.
[14]
[Citation(start=30, end=35, text='20°C.', sources=[ToolSource(type='tool', id='get_weather_sfnmhqhb8g2p:0', tool_output={'temperature': '20°C'})], content_index=1, type='TEXT_CONTENT')]
[15]
{'role': 'user', 'content': "What's the weather in Toronto?"} 

role='assistant' tool_calls=[ToolCallV2(id='get_weather_sfnmhqhb8g2p', type='function', function=ToolCallV2Function(name='get_weather', arguments='{"location":"Toronto"}'))] tool_plan=None content=[ThinkingAssistantMessageResponseContentItem(value=None, type='thinking', thinking="The user is asking for the weather in Toronto. I need to use the available tool 'get_weather' to retrieve this information. The tool requires a 'location' parameter, which the user has provided as Toronto. I'll call the tool with the location set to Toronto.")] citations=None 

{'role': 'tool', 'tool_call_id': 'get_weather_sfnmhqhb8g2p', 'content': [{'type': 'document', 'document': {'data': '{"temperature": "20\\u00b0C"}'}}]} 

role='assistant' tool_calls=None tool_plan=None content=[ThinkingAssistantMessageResponseContentItem(value=None, type='thinking', thinking='The user asked for the weather in Toronto. I used the get_weather tool with the location parameter set to "Toronto". The tool returned a result indicating a temperature of 20°C. Since the response only includes the temperature, I\'ll check if there\'s additional weather information needed. However, based on the tool\'s output structure, it seems only the temperature is provided. I\'ll proceed to inform the user of the current temperature in Toronto.'), TextAssistantMessageResponseContentItem(type='text', text='The temperature in Toronto is 20°C.')] citations=[Citation(start=30, end=35, text='20°C.', sources=[ToolSource(type='tool', id='get_weather_sfnmhqhb8g2p:0', tool_output={'temperature': '20°C'})], content_index=1, type='TEXT_CONTENT')] 

[ ]
[ ]