-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
self-imporving agent description with example code #1013
Draft
qingyun-wu
wants to merge
3
commits into
main
Choose a base branch
from
self-improving-agent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# 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 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") | ||
|
||
# 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 | ||
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 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The description here seems to indicate that the expert verifies an answer right after every problem asked by a user. We can make it more general. The expert agent doesn't necessarily verify every problem. |
||
|
||
```python | ||
# Dev mode with an expert agent (could be an LLM or human) | ||
expert = ExpertAgent("expert") | ||
# 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 | ||
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) | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Describe what happens after the
receive
call.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be more specific, do we want to assume what experience happens after
receive()
? For example, like ChatGPT, like AutoGPT, or neither, or both.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated accordingly.