Retrieval-Augmented Generation (RAG) has become the standard for grounding Large Language Models in proprietary data. However, traditional RAG pipelines are often linear and rigid. They retrieve once, generate once, and stop. Complex business questions rarely follow this simple pattern; they require decomposition, verification, and the ability to call external tools to fill knowledge gaps. This is where **Agentic RAG** comes in.
Cohere’s Command R+ is specifically engineered for this purpose. Unlike its smaller sibling, Command R, the "Plus" variant is optimized for multi-turn conversations, complex reasoning, and structured tool use. In this guide, we will explore how to architect an agentic RAG system using Command R+, focusing on its native support for function calling and its ability to handle long-context retrieval.
Why Command R+ for Agentic Workflows?
Agentic systems need two key capabilities from the LLM:
- Instruction Following: The model must strictly adhere to tool definitions and output formats.
- Reasoning Depth: The model needs to decide when to retrieve, what to retrieve, and how to synthesize results before calling a tool or generating a final answer.
Command R+ excels in both. It is fine-tuned on high-quality instruction data that includes complex, multi-step tool usage examples. This means you spend less time prompting "be strict with your JSON output" and more time building robust retrieval logic.
Architecting the Loop
An agentic RAG loop typically follows this cycle:
User Query → LLM Reasoning → Tool Call (Search/Function) → LLM Integration → Repeat or Final Answer
The key difference from static RAG is the Repeating step. If the initial retrieval result is insufficient, the agent should be able to refine the query or call a different tool.
Implementation: Python with Cohere SDK
Below is a practical example using the Cohere Python SDK. We define a simple "web search" tool and allow Command R+ to invoke it if it deems local knowledge insufficient.
import cohere
client = cohere.ClientClient("YOUR_API_KEY")
# Define the tools the agent can use
tools = [
{
"name": "web_search",
"description": "Search the web for real-time information when the local document store is outdated or insufficient.",
"parameter_definitions": {
"query": {
"type": "string",
"description": "The search query string"
},
"num_results": {
"type": "integer",
"description": "Number of results to return",
"default": 5
}
}
}
]
# The user's complex query
message = "What is the latest pricing update for AWS EC2 instances in the eu-west-1 region?"
# Initialize chat history
chat_history = []
def run_agent():
response = client.chat(
model="command-r-plus",
message=message,
tools=tools,
chat_history=chat_history
)
# Check if the model wants to call a tool
if response.tool_calls:
for tool_call in response.tool_calls:
# In a real app, you would execute the actual search here
# For this demo, we simulate a result
simulated_result = {
"query": tool_call.parameters["query"],
"results": ["Latest AWS Blog: EC2 pricing updated on 10/24/2023..."]
}
# Append the tool result to history
chat_history.append({
"role": "TOOL",
"tool_name": tool_call.tool_name,
"content": simulated_result
})
# Re-call the model to synthesize the tool result
final_response = client.chat(
model="command-r-plus",
message="Please summarize the tool results into a coherent answer.",
chat_history=chat_history,
tools=tools
)
return final_response.text
else:
# No tool needed, return direct answer
return response.text
print(run_agent())
Best Practices for Multi-Step Reasoning
- Keep Tool Descriptions Precise: Command R+ relies heavily on the
descriptionfield of your tools. Ambiguous descriptions lead to hallucinated tool calls. Use clear, action-oriented language. - Leverage System Prompts: While not strictly necessary, a system prompt can help guide the agent’s "personality." For example: "You are a helpful assistant that prioritizes accuracy. Only use tools when you are uncertain."
- Handle Failures Gracefully: If a tool call fails (e.g., API timeout), catch the exception, append an error message to the chat history, and let the LLM decide whether to retry or apologize to the user. Command R+ is robust enough to handle these edge cases without breaking the loop.
Conclusion
Implementing Agentic RAG transforms static retrieval pipelines into dynamic, reasoning-based systems. By leveraging Cohere’s Command R+, developers can build agents that not only fetch data but also decide when to fetch it, how to refine their search, and how to synthesize multiple sources of truth. Start with simple tool definitions, test your loops rigorously, and scale your complexity as you gain confidence in the model’s reasoning capabilities. The future of enterprise AI isn’t just retrieval—it’s action.