Groupchat with Llamaindex agents
Llamaindex agents have the ability to use planning strategies to answer user questions. They can be integrated in Autogen in easy ways
Requirements
! pip install pyautogen
! pip install llama-index
! pip install llama-index-tools-wikipedia
! pip install llama-index-readers-wikipedia
! pip install wikipedia
Set your API Endpoint
import os
import autogen
config_list = [{"model": "gpt-3.5-turbo-0125", "api_key": os.getenv("OPENAI_API_KEY")}]
Set Llamaindex
from llama_index.core import Settings
from llama_index.core.agent import ReActAgent
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI
from llama_index.tools.wikipedia import WikipediaToolSpec
llm = OpenAI(
model="gpt-3.5-turbo-0125",
temperature=0.0,
api_key=os.environ.get("OPENAPI_API_KEY", ""),
)
embed_model = OpenAIEmbedding(
model="text-embedding-ada-002",
temperature=0.0,
api_key=os.environ.get("OPENAPI_API_KEY", ""),
)
Settings.llm = llm
Settings.embed_model = embed_model
# create a react agent to use wikipedia tool
wiki_spec = WikipediaToolSpec()
# Get the search wikipedia tool
wikipedia_tool = wiki_spec.to_tool_list()[1]
location_specialist = ReActAgent.from_tools(tools=[wikipedia_tool], llm=llm, max_iterations=10, verbose=True)
Create agents
In this example, we will create a Llamaindex agent to answer questions fecting data from wikipedia and a user proxy agent.
from llamaindex_conversable_agent import LLamaIndexConversableAgent
llm_config = {
"temperature": 0,
"config_list": config_list,
}
trip_assistant = LLamaIndexConversableAgent(
"trip_specialist",
llama_index_agent=location_specialist,
system_message="You help customers finding more about places they would like to visit. You can use external resources to provide more details as you engage with the customer.",
description="This agents helps customers discover locations to visit, things to do, and other details about a location. It can use external resources to provide more details. This agent helps in finding attractions, history and all that there si to know about a place",
)
user_proxy = autogen.UserProxyAgent(
name="Admin",
human_input_mode="ALWAYS",
code_execution_config=False,
)
Next, let’s set up our group chat.
groupchat = autogen.GroupChat(
agents=[trip_assistant, user_proxy],
messages=[],
max_round=500,
speaker_selection_method="round_robin",
enable_clear_history=True,
)
manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)
chat_result = user_proxy.initiate_chat(
manager,
message="""
What can i find in Tokyo related to Hayao Miyazaki and its moveis like Spirited Away?.
""",
)