← Back to list

AutoGen — Cohere Integration

Integrating AutoGen with Cohere API

Steve Zebib in oracle-saas-paas · 2024-12-14 00:46 · 1 claps · 1.5 min read
#autogen #cohere #oracle-cloud #gen-ai-tools
Open on Medium ↗
Wiki topics: AGT · AI Agents AI · AI · General

AutoGen — Cohere Integration

Overview

This article explains how to use AutoGen with Cohere, an alternative to the default OpenAI integration. This includes setup instructions and an example to showcase AutoGen’s features with Cohere.

Setup

Cohere

Environment

The following configuration is used in this example:

  • Conda for Mac
  • Python 3.10 (compatible with AutoGen Cohere library 0.2.39)

The following is a script to setup the env and install packages:

conda create -n autogenDev python=3.10    
conda activate autogenDev
pip install 'autogen-agentchat[cohere]==0.2.39'

Sample

In this example, we’ll utilize the group chat multi-agent design pattern. We will create a group chat with the following:

User Prompt: “I want to learn more about AutoGen”

Agents:

  • User Proxy Agent: Agent who will initiate the chat using the user prompt.
  • Assistant Agent (Basic): Agent with basic knowledge about AutoGen.
  • Assistant Agent (Professional): Agent with advanced knowledge about AutoGen and potential use cases.

Code

Create a Python script (e.g. sample.py) and copy/paste the following:

from autogen import AssistantAgent, UserProxyAgent, GroupChat, GroupChatManager

# Prompts
userPrompt="I want to learn more about AutoGen."
basicAssistantAgentPrompt="You are a helpful AI assistant with basic knowledge of AutoGen."
professionalAssistantAgentPrompt="You are a helpful AI assistant with advanced knowledge of AutoGen and its use cases. Analyze response by Basic_Assistant_Agent and provide more information."

# Cohere config
config_list = [
    {
        "model": "command-r-plus-08-2024",
        "api_key": "<COHERE_API_KEY>",
        "api_type": "cohere",
    }
]

# Create user proxy agent
user_proxy_agent = UserProxyAgent(
    name="User_Proxy_Agent",
    llm_config={"config_list": config_list},
    code_execution_config=False,
    human_input_mode="NEVER",
    max_consecutive_auto_reply=1,
)

# Create the basic assistant agent
basic_assistant_agent = AssistantAgent(
    name="Basic_Assistant_Agent",
    llm_config={"config_list": config_list},
    system_message=basicAssistantAgentPrompt,
    max_consecutive_auto_reply=1
)

# Create the professional assistant agent
professional_assistant_agent = AssistantAgent(
    name="Professional_Assistant_Agent",
    llm_config={"config_list": config_list},
    system_message=professionalAssistantAgentPrompt,
    max_consecutive_auto_reply=1,
)

# Create a group chat between all agents
groupChat = GroupChat(
    agents=[user_proxy_agent, basic_assistant_agent, professional_assistant_agent],
    messages=[],
    max_round=3,
)

groupChatManager = GroupChatManager(
    groupchat=groupChat,
    llm_config={"config_list": config_list}
)

# Initiate the chat using the User Proxy Agent and pass the user prompt
chat_result = user_proxy_agent.initiate_chat(
    groupChatManager,
    message=userPrompt
)

Run

Run the Python script (e.g. sample.py) in terminal:

python sample.py

The following is the final output returned by both the Basic Assistant Agent and Professional Assistant Agent:

Demo Output

Demo Output

References


메타데이터
post_id
31c561be81f8
slug
autogen-with-cohere-31c561be81f8
url
https://medium.com/oracle-saas-paas/autogen-with-cohere-31c561be81f8
canonical_url
https://medium.com/oracle-saas-paas/autogen-with-cohere-31c561be81f8
author_url
https://medium.com/@mzebib
status
ok
fetched_at
2026-06-11 15:16:29