From 72ec21795fc6f013083f3d95990819bf22020bb2 Mon Sep 17 00:00:00 2001 From: Qingyun Wu Date: Wed, 26 Apr 2023 19:33:23 +0000 Subject: [PATCH 1/3] agent-description --- test/autogen/self_improve_agent.md | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/autogen/self_improve_agent.md diff --git a/test/autogen/self_improve_agent.md b/test/autogen/self_improve_agent.md new file mode 100644 index 0000000000..4ab3052ef8 --- /dev/null +++ b/test/autogen/self_improve_agent.md @@ -0,0 +1,49 @@ +# Self-Improving API Agent +This code describes a scenario where an API agent is designed to self-improve +and interact with a user. The API agent tries to answer a given question using the provided API or suggests a new API if the existing one is not suitable. + +The code is divided into two modes: User mode and Dev mode. The user mode provides a basic interaction between the API agent and the user agent, while the Dev mode involves an expert agent for verifying the correctness of the answers provided by the API agent. + +## User mode +In User mode, the API agent receives a question and an API to use for answering the question. It attempts to answer the question or create new APIs if the provided API cannot answer the question. + +```python +# An API agent that performs self-improvement by default +api_agent = APIAgent("api_agent", self_improve=True) + +# Question and API to use for answering the question +question = "What if we must go from node 1 to node 2?" +api = "change_dist" +user_prompt = "answer question: {question}, with api: {api}".format(question=question, api=api) + +# User mode +# The API agent tries to create new APIs if the provided API cannot answer the provided question. +user = Agent("user") +api_agent.receive(user_prompt, user) +``` + +## Dev mode +In Dev mode, the expert agent verifies the correctness of the answer provided by the API agent. The process continues in a loop until the expert agent is satisfied with the answer (the verification returns "correct"). Once the expert agent is satisfied, the API agent has successfully answered the question. + +```python +# Dev mode with an expert agent (could be an LLM or human) +expert = ExpertAgent("expert") +# If the expert agent is satisfied with the answer (the verification returns "correct"), the loop ends, +# and the API agent has successfully answered the question. +expert_feedback = None +while expert_feedback != "correct": + prompt = user_prompt + "Expert verification: " + expert_feedback + answer, new_api_suggested = api_agent.receive(prompt, expert) + + result = { + "question": question, + "api": api if not new_api_suggested else new_api_suggested, + "answer": answer, + "expert_feedback": expert_feedback + } + dev_prompt = "Verify the correctness of the answer. question: {question}, answer: {answer}.\ + The api used to get the answer is {api}".format(**result) + + # The expert agent provides feedback + expert_feedback = expert.receive(dev_prompt, api_agent) +``` From 695429a00beb24f07d5f4ea816c8fb6f86306e2b Mon Sep 17 00:00:00 2001 From: Qingyun Wu Date: Thu, 27 Apr 2023 12:43:29 -0400 Subject: [PATCH 2/3] update user code based on discussion --- test/autogen/self_improve_agent.md | 32 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/test/autogen/self_improve_agent.md b/test/autogen/self_improve_agent.md index 4ab3052ef8..e058fa1e3a 100644 --- a/test/autogen/self_improve_agent.md +++ b/test/autogen/self_improve_agent.md @@ -5,31 +5,35 @@ and interact with a user. The API agent tries to answer a given question using t The code is divided into two modes: User mode and Dev mode. The user mode provides a basic interaction between the API agent and the user agent, while the Dev mode involves an expert agent for verifying the correctness of the answers provided by the API agent. ## User mode -In User mode, the API agent receives a question and an API to use for answering the question. It attempts to answer the question or create new APIs if the provided API cannot answer the question. +In User mode, the API agent use `receive` the function call to receive questions from users and answer the questions. It attempts to answer the question with existing apis and will try to add new apis if the question cannot be answered by existing ones properly. ```python # An API agent that performs self-improvement by default -api_agent = APIAgent("api_agent", self_improve=True) - -# Question and API to use for answering the question -question = "What if we must go from node 1 to node 2?" -api = "change_dist" -user_prompt = "answer question: {question}, with api: {api}".format(question=question, api=api) +api_agent = APIAgent("api_agent", self_improve=True, api="api.json") # User mode -# The API agent tries to create new APIs if the provided API cannot answer the provided question. -user = Agent("user") -api_agent.receive(user_prompt, user) +user = HumanAgent("human user") +# Question from the user +question = "What if we must go from node 1 to node 2?" +# the api_agent will send the answer to user +api_agent.receive(question, user) ``` ## Dev mode -In Dev mode, the expert agent verifies the correctness of the answer provided by the API agent. The process continues in a loop until the expert agent is satisfied with the answer (the verification returns "correct"). Once the expert agent is satisfied, the API agent has successfully answered the question. +In Dev mode, the expert agent verifies the correctness of the answer provided by the API agent. The process continues until the expert agent is satisfied with the answer (the verification returns "correct") or an interaction number upper limit is reached. Once the expert agent is satisfied, the API agent has successfully answered the question. ```python # Dev mode with an expert agent (could be an LLM or human) expert = ExpertAgent("expert") -# If the expert agent is satisfied with the answer (the verification returns "correct"), the loop ends, -# and the API agent has successfully answered the question. +# The api agent shall communicate with the expert +api_agent.receive(question, expert) +``` + + +The code below is the old code for the self-improving API agent. It is not used anymore. + + +```python expert_feedback = None while expert_feedback != "correct": prompt = user_prompt + "Expert verification: " + expert_feedback @@ -37,7 +41,7 @@ while expert_feedback != "correct": result = { "question": question, - "api": api if not new_api_suggested else new_api_suggested, + # "api": api if not new_api_suggested else new_api_suggested, "answer": answer, "expert_feedback": expert_feedback } From 8a74230bfff35ecfeb8d0698a468e2ab6fccaf59 Mon Sep 17 00:00:00 2001 From: Qingyun Wu Date: Sun, 30 Apr 2023 16:52:42 +0000 Subject: [PATCH 3/3] add user experience options --- test/autogen/self_improve_agent.md | 50 +++++++++++++----------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/test/autogen/self_improve_agent.md b/test/autogen/self_improve_agent.md index e058fa1e3a..0f90db87af 100644 --- a/test/autogen/self_improve_agent.md +++ b/test/autogen/self_improve_agent.md @@ -1,53 +1,45 @@ -# Self-Improving API Agent -This code describes a scenario where an API agent is designed to self-improve -and interact with a user. The API agent tries to answer a given question using the provided API or suggests a new API if the existing one is not suitable. +# Self-Improving Agent +This code describes a scenario where an agent (SIAgent) is designed to be able to interact with a user and self-improve. -The code is divided into two modes: User mode and Dev mode. The user mode provides a basic interaction between the API agent and the user agent, while the Dev mode involves an expert agent for verifying the correctness of the answers provided by the API agent. +The code is divided into two modes: User mode and Dev mode. The user mode provides a basic interaction between the SIAgent and the user agent, while the Dev mode involves an expert agent for verifying the correctness of the answers provided by a SIAgent. ## User mode -In User mode, the API agent use `receive` the function call to receive questions from users and answer the questions. It attempts to answer the question with existing apis and will try to add new apis if the question cannot be answered by existing ones properly. +In User mode, the SIAgent use `receive` the function call to receive questions from users and answer the questions. It attempts to answer the question with existing apis and will try to add new apis if the question cannot be answered by existing ones properly. ```python -# An API agent that performs self-improvement by default -api_agent = APIAgent("api_agent", self_improve=True, api="api.json") +# An SIAgent that performs self-improvement by default +api_agent =SIAgent("api_agent", self_improve=True, context="api.json") # User mode user = HumanAgent("human user") # Question from the user question = "What if we must go from node 1 to node 2?" -# the api_agent will send the answer to user +# the api_agent will communicate with the user api_agent.receive(question, user) +# the api_agent will either answer the question (with the existing api or newly created api), or ask for more information from the user (e.g., to clarify the question) ``` ## Dev mode -In Dev mode, the expert agent verifies the correctness of the answer provided by the API agent. The process continues until the expert agent is satisfied with the answer (the verification returns "correct") or an interaction number upper limit is reached. Once the expert agent is satisfied, the API agent has successfully answered the question. +In Dev mode, the expert agent verifies the correctness of the answer provided by the SIAgent. The process continues until the expert agent is satisfied with the answer (the verification returns "correct") or an interaction number upper limit is reached. Once the expert agent is satisfied, the SIAgent has successfully answered the question. ```python # Dev mode with an expert agent (could be an LLM or human) expert = ExpertAgent("expert") -# The api agent shall communicate with the expert +# The SIAgent shall communicate with the expert api_agent.receive(question, expert) ``` +## User experience after the receive function call +To answer the question +"Describe what happens after the receive call +To be more specific, do we want to assume what experience happens after receive()? For example, like ChatGPT, like AutoGPT, or neither, or both." -The code below is the old code for the self-improving API agent. It is not used anymore. +Option 1: ChatGPT +Conversation between the user and an SiAgent similar to the conversation between the user and ChatGPT. +Option 2: autoGPT +An SIAgent show the progress of the task execution and have pre-defined messages to ask for more information (or permission to continue) from the user -```python -expert_feedback = None -while expert_feedback != "correct": - prompt = user_prompt + "Expert verification: " + expert_feedback - answer, new_api_suggested = api_agent.receive(prompt, expert) - - result = { - "question": question, - # "api": api if not new_api_suggested else new_api_suggested, - "answer": answer, - "expert_feedback": expert_feedback - } - dev_prompt = "Verify the correctness of the answer. question: {question}, answer: {answer}.\ - The api used to get the answer is {api}".format(**result) - - # The expert agent provides feedback - expert_feedback = expert.receive(dev_prompt, api_agent) -``` +Option 3: branching conversation model + +The SIAgent initiates multiple conversation sessions or threads, allowing for diverse paths to be considered simultaneously. Agent B then has the option to selectively engage with one or more of these threads, leading to a potentially rich and varied conversation. As the conversation progresses, it can continue to branch out as new responses or subthreads are introduced, creating a dynamic and non-linear dialogue structure.