This notebook shows an example of the GPTAssistantAgent
with retrieval augmented generation. GPTAssistantAgent
is an experimental AutoGen agent class that leverages the OpenAI Assistant API for conversational capabilities, working with
UserProxyAgent
in AutoGen.
import logging
import os
from autogen import UserProxyAgent, config_list_from_json
from autogen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent
logger = logging.getLogger(__name__)
logger.setLevel(logging.WARNING)
assistant_id = os.environ.get("ASSISTANT_ID", None)
config_list = config_list_from_json("OAI_CONFIG_LIST")
llm_config = {
"config_list": config_list,
"assistant_id": assistant_id,
"tools": [{"type": "retrieval"}],
"file_ids": ["file-CmlT0YKLB3ZCdHmslF9FOv69"]
# add id of an existing file in your openai account
# in this case I added the implementation of conversable_agent.py
}
gpt_assistant = GPTAssistantAgent(
name="assistant", instructions="You are adapt at question answering", llm_config=llm_config
)
user_proxy = UserProxyAgent(
name="user_proxy",
code_execution_config=False,
is_termination_msg=lambda msg: "TERMINATE" in msg["content"],
human_input_mode="ALWAYS",
)
user_proxy.initiate_chat(gpt_assistant, message="What is the name of the class of agents I gave you?")
gpt_assistant.delete_assistant()
assistant_id was None, creating a new assistant
user_proxy (to assistant): What is the name of the class of agents I gave you? -------------------------------------------------------------------------------- assistant (to user_proxy): The class of agents provided in the file is called `ConversableAgent`. -------------------------------------------------------------------------------- user_proxy (to assistant): What does it do? -------------------------------------------------------------------------------- assistant (to user_proxy): The `ConversableAgent` class is designed as a generic conversable agent that can be configured to act either as an assistant or user proxy. When it receives a message, it automatically generates and sends a reply unless the message is a termination message. It features a method to initiate a chat with another agent and can have its auto-reply behavior adjusted by overriding the `generate_reply` method. Here are some specific functionalities and mechanisms included in the `ConversableAgent` class: - It can process received messages and decide whether or not a reply is necessary or requested. - It can reset consecutive auto-reply counters and clear chat history when starting a new conversation. - It allows initiating chats either synchronously or asynchronously with the ability to pass context information and control chattiness. - It has the ability to register reply functions with specific triggers and order them based on preference. - The class supports setting a maximum number of consecutive auto-replies, after which it can prompt for human input based on configured criteria (e.g., always, on termination, or never). - The auto-reply trigger mechanism can be finely controlled by associating reply functions with triggers such as instances of particular classes, specific strings, or custom callable conditions. This class provides an extensible framework for creating bots or agents that can interact in a chat-like context, with custom behavior that developers can tailor to specific applications. -------------------------------------------------------------------------------- >>>>>>>> NO HUMAN INPUT RECEIVED. >>>>>>>> USING AUTO REPLY... user_proxy (to assistant): -------------------------------------------------------------------------------- assistant (to user_proxy): It seems that your request was incomplete. Could you please provide more information or clarify your request? --------------------------------------------------------------------------------
Permanently deleting assistant...