Description
import autogen
import logging
from virus_agent import VirusAgent
from text2sql_agent import GoldenEyesAgent
from autogen import ConversableAgent
from autogen import config_list_from_json
from autogen import register_function
from typing import Annotated
config_list = config_list_from_json(env_or_file="./autogent/config.json")
llm_config = {
"timeout": 600,
"cache_seed": 42,
"config_list": config_list,
"temperature": 0,
}
ReAct_prompt = """
Answer the following questions as best you can. You have access to tools provided.
Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take
Action Input: the input to the action
Observation: the result of the action
... (this process can repeat multiple times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Begin!
Question: {input}
"""
def react_prompt_message(sender, recipient, context):
return ReAct_prompt.format(input=context["question"])
Let's first define the assistant agent that suggests tool calls.
assistant = ConversableAgent(
name="Assistant",
system_message="You are a helpful assistant.",
llm_config=llm_config,
)
The user proxy agent is used for interacting with the assistant agent
and executes tool calls.
user_proxy = ConversableAgent(
name="User",
llm_config=False,
is_termination_msg=lambda msg: msg.get("content") is not None and "TERMINATE" in msg["content"],
human_input_mode="ALWAYS",
)
Register the calculator function to the two agents.
register_function(
query_xxxx,
caller=assistant, # The assistant agent can suggest calls to the calculator.
executor=user_proxy, # The user proxy agent can execute the calculator calls.
name="query_xxxx", # By default, the function name is used as the tool name.
description="分析助手", # A description of the tool.
)
register_function(
query_xxxxx,
caller=assistant, # The assistant agent can suggest calls to the calculator.
executor=user_proxy, # The user proxy agent can execute the calculator calls.
name="query_xxxx", # By default, the function name is used as the tool name.
description="问答助手", # A description of the tool.
)
query = """
xxxx
"""
chat_result = user_proxy.initiate_chat(
assistant, message=react_prompt_message, question=query)
print(chat_result)