Skip to content

A programming framework for agentic AI

add a verbose flag to print more information of runtime (#717)

Ian26f6e0cfb2db
diff --git a/autogen/agentchat/contrib/gpt_assistant_agent.py b/autogen/agentchat/contrib/gpt_assistant_agent.py
index 0d1ef4875..2fd431e99 100644
--- a/autogen/agentchat/contrib/gpt_assistant_agent.py
+++ b/autogen/agentchat/contrib/gpt_assistant_agent.py
@@ -26,6 +26,7 @@ class GPTAssistantAgent(ConversableAgent):
instructions: Optional[str] = None,
llm_config: Optional[Union[Dict, bool]] = None,
overwrite_instructions: bool = False,
+ **kwargs,
):
"""
Args:
@@ -45,6 +46,9 @@ class GPTAssistantAgent(ConversableAgent):
or build your own tools using Function calling. ref https://platform.openai.com/docs/assistants/tools
- file_ids: files used by retrieval in run
overwrite_instructions (bool): whether to overwrite the instructions of an existing assistant.
+ kwargs (dict): Additional configuration options for the agent.
+ - verbose (bool): If set to True, enables more detailed output from the assistant thread.
+ - Other kwargs: Except verbose, others are passed directly to ConversableAgent.
"""
# Use AutoGen OpenAIWrapper to create a client
oai_wrapper = OpenAIWrapper(**llm_config)
@@ -100,11 +104,9 @@ class GPTAssistantAgent(ConversableAgent):
"overwrite_instructions is False. Provided instructions will be used without permanently modifying the assistant in the API."
)
+ self._verbose = kwargs.pop("verbose", False)
super().__init__(
- name=name,
- system_message=instructions,
- human_input_mode="NEVER",
- llm_config=llm_config,
+ name=name, system_message=instructions, human_input_mode="NEVER", llm_config=llm_config, **kwargs
)
# lazily create threads
@@ -209,7 +211,7 @@ class GPTAssistantAgent(ConversableAgent):
actions = []
for tool_call in run.required_action.submit_tool_outputs.tool_calls:
function = tool_call.function
- is_exec_success, tool_response = self.execute_function(function.dict())
+ is_exec_success, tool_response = self.execute_function(function.dict(), self._verbose)
tool_response["metadata"] = {
"tool_call_id": tool_call.id,
"run_id": run.id,
diff --git a/autogen/agentchat/conversable_agent.py b/autogen/agentchat/conversable_agent.py
index 449e1d13d..7a268823a 100644
--- a/autogen/agentchat/conversable_agent.py
+++ b/autogen/agentchat/conversable_agent.py
@@ -1144,7 +1144,7 @@ class ConversableAgent(Agent):
result.append(char)
return "".join(result)
- def execute_function(self, func_call) -> Tuple[bool, Dict[str, str]]:
+ def execute_function(self, func_call, verbose: bool = False) -> Tuple[bool, Dict[str, str]]:
"""Execute a function call and return the result.
Override this function to modify the way to execute a function call.
@@ -1184,6 +1184,12 @@ class ConversableAgent(Agent):
else:
content = f"Error: Function {func_name} not found."
+ if verbose:
+ print(
+ colored(f"\nInput arguments: {arguments}\nOutput:\n{content}", "magenta"),
+ flush=True,
+ )
+
return is_exec_success, {
"name": func_name,
"role": "function",
diff --git a/notebook/agentchat_oai_assistant_function_call.ipynb b/notebook/agentchat_oai_assistant_function_call.ipynb
index b9d230a59..1d73866d9 100644
--- a/notebook/agentchat_oai_assistant_function_call.ipynb
+++ b/notebook/agentchat_oai_assistant_function_call.ipynb
@@ -43,7 +43,7 @@
},
{
"cell_type": "code",
- "execution_count": 21,
+ "execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@@ -104,7 +104,7 @@
"\n",
" if answer.get('error', None) is not None:\n",
" report_components.append(f\"Error: {answer['error']}\")\n",
- " return \"\\n\\n\".join(report_components)"
+ " return \"\\n\\n\".join(report_components) + \"\\n\\n\""
]
},
{
@@ -118,7 +118,7 @@
},
{
"cell_type": "code",
- "execution_count": 22,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@@ -147,6 +147,7 @@
" \"Please carefully read the context of the conversation to identify the current analysis question or problem that needs addressing.\"\n",
" ),\n",
" llm_config=llm_config,\n",
+ " verbose=True,\n",
")\n",
"oss_analyst.register_function(\n",
" function_map={\n",
@@ -166,7 +167,7 @@
},
{
"cell_type": "code",
- "execution_count": 23,
+ "execution_count": 3,
"metadata": {},
"outputs": [
{
@@ -180,20 +181,42 @@
"--------------------------------------------------------------------------------\n",
"\u001b[35m\n",
">>>>>>>> EXECUTING FUNCTION ossinsight_data_api...\u001b[0m\n",
+ "\u001b[35m\n",
+ "Input arguments: {'question': 'Who are the top 10 developers with the most followers on GitHub?'}\n",
+ "Output:\n",
+ "Question: Who are the top 10 developers with the most followers on GitHub?\n",
+ "\n",
+ "querySQL: SELECT `login` AS `user_login`, `followers` AS `followers` FROM `github_users` ORDER BY `followers` DESC LIMIT 10\n",
+ "\n",
+ "Result:\n",
+ " {'followers': 166730, 'user_login': 'torvalds'}\n",
+ " {'followers': 86239, 'user_login': 'yyx990803'}\n",
+ " {'followers': 77611, 'user_login': 'gaearon'}\n",
+ " {'followers': 72668, 'user_login': 'ruanyf'}\n",
+ " {'followers': 65415, 'user_login': 'JakeWharton'}\n",
+ " {'followers': 60972, 'user_login': 'peng-zhihui'}\n",
+ " {'followers': 58172, 'user_login': 'bradtraversy'}\n",
+ " {'followers': 52143, 'user_login': 'gustavoguanabara'}\n",
+ " {'followers': 51542, 'user_login': 'sindresorhus'}\n",
+ " {'followers': 49621, 'user_login': 'tj'}\n",
+ "\n",
+ "\u001b[0m\n",
"\u001b[33mOSS Analyst\u001b[0m (to user_proxy):\n",
"\n",
- "The top 10 developers on GitHub with the most followers are:\n",
+ "The top 10 developers with the most followers on GitHub are as follows:\n",
+ "\n",
+ "1. `torvalds` with 166,730 followers\n",
+ "2. `yyx990803` with 86,239 followers\n",
+ "3. `gaearon` with 77,611 followers\n",
+ "4. `ruanyf` with 72,668 followers\n",
+ "5. `JakeWharton` with 65,415 followers\n",
+ "6. `peng-zhihui` with 60,972 followers\n",
+ "7. `bradtraversy` with 58,172 followers\n",
+ "8. `gustavoguanabara` with 52,143 followers\n",
+ "9. `sindresorhus` with 51,542 followers\n",
+ "10. `tj` with 49,621 followers\n",
"\n",
- "1. Linus Torvalds (`torvalds`) with 166,730 followers.\n",
- "2. Evan You (`yyx990803`) with 86,239 followers.\n",
- "3. Dan Abramov (`gaearon`) with 77,611 followers.\n",
- "4. Ruan YiFeng (`ruanyf`) with 72,668 followers.\n",
- "5. Jake Wharton (`JakeWharton`) with 65,415 followers.\n",
- "6. Peng Zhihui (`peng-zhihui`) with 60,972 followers.\n",
- "7. Brad Traversy (`bradtraversy`) with 58,172 followers.\n",
- "8. Gustavo Guanabara (`gustavoguanabara`) with 52,143 followers.\n",
- "9. Sindre Sorhus (`sindresorhus`) with 51,542 followers.\n",
- "10. TJ Holowaychuk (`tj`) with 49,621 followers.\n",
+ "These figures indicate the number of followers these developers had at the time of the analysis.\n",
"\n",
"\n",
"--------------------------------------------------------------------------------\n",
@@ -204,7 +227,7 @@
"--------------------------------------------------------------------------------\n",
"\u001b[33mOSS Analyst\u001b[0m (to user_proxy):\n",
"\n",
- "It seems like there is no question or further instructions provided in your last response. How may I assist you further with open source project analysis or any other inquiries you might have?\n",
+ "It seems you haven't entered a question or a request. Could you please provide more details or specify how I can assist you further?\n",
"\n",
"\n",
"--------------------------------------------------------------------------------\n"