Skip to content
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

feat(agent): Draft of agent group feature #6896

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MKdir98
Copy link
Contributor

@MKdir98 MKdir98 commented Feb 23, 2024

  • Add divider_and_conquer strategy for use in agent members
  • Add AgentMember class
  • Add AgentGroup class
  • Add hire_agent and create_agent and create_task
  • Add test_agent_group as an integration test with VCR
  • Add autogpt_multi_agent.sh file to run autogpt in multi-agent mode

Background

image

In this PR we want to add AgentGroup feature as discussed in #6824.

The base of this PR is the AgentGroup class. This class can create a group of agents like a company. The name of this agent will be AgentMember and it will extend from Agent.

Each AgentGroup has one leader. leader is kind of AgentMember. Each AgentMember can have several AgentMember to do some task for its boss.

Main classes

AgentGroup
leader: AgentMember: This agent will be the head of this group
members: dict[str, AgentMember]: We need to have a list of all members in our tree to find an agent with the ID of that agent
AgentMember
id: str: Unique ID for each member
role: str: The role of the agent in the group
initial_prompt: str: The prompt for creating the agent
boss: Optional['AgentMember']: Boss of the agent
recruiter: Optional['AgentMember']: We can have a recruiter for agents to hire members for them
task_queue: list[Task]: A queue to store tasks for agent
members: list['AgentMember']: We need to have members to assign tasks to them
create_agent: bool: the ability to create an agent for an agent (if this was off and you need an agent, you should tell your boss)
db: AgentDB: For creating a task I need this one
group: 'AgentGroup': For run command, I need this one

Strategies

divide_and_conquer

This strategy is like one_shot strategy with some different. Every agent has a thread to check its task_queue all the time. in each iterate AgentMember loads tasks and its members and gives these values to llm_provider to get a list of commands that we want (unlike one_shot we will have a list of commands). We will have two more commands in the list of commands.

Commands

create_agent

If the create_agent property of an agent is true this agent can create a new agent for an agent.
We need these properties for this action.

  • prompt
  • role
  • boss_id
    After this one, we will have a member for an agent with boss_id id with prompt description.
hire_agent

If the create_agent property of an agent is false and this agent wants a member, it should say to its boss or its recruiter to hire someone for it.

create_task

If they need to create a task for others, they can use this command.
task (str): The description of that task
agent_id (str): The id of the agent will be the owner of this task.
father_task_id (str): The task id that is the cause of this task.

tests

test_agent_group

This test is an integration test that will support all code that we will write. The scenario is a create best shooter game in the world. This test uses VCR for LLM responses. The VCR files have been changed (It is not the direct response of LLM). In this test we'll create an AgentGroup with the CEO as leader and the CEO will have an hr_lead as its member.

How we can run Autogpt in multi-agent mode

autogpt_multi_agent.sh

We can run Autogpt in multi-agent cli mode by this script. It is like autogpt.sh. It has just one more argument and it is member-description. The structure of member-description will be like this. --member-description "{role_name}:{description of this member}:{boolean of can create new agent or no}:{boss_index}:{recruiter_index}". It's just for starting and it will need to get better. An example of running this command and creating a new agent group can be this:

./autogpt_multi_agent.sh --member-description "tech_lead:you will be tech lead of github.com/Significant-Gravitas/AutoGPT project and 
you need to get this project better in github:False::1" --member-description "hr_lead:you will be hr of this team. you need to prepare agents for this work done.:True:0" --me
mber-description "senior_python_developer:you will be developer of this team and you will get issues to get them done:False:0"

Changes 🏗️

We didn't change something in here. We added some classes as we talked about in the Background part.

PR Quality Scorecard ✨

  • Have you used the PR description template?   +2 pts
  • Is your pull request atomic, focusing on a single charge?   +5 pts
  • Have you linked the GitHub issue(s) that this PR addresses?   +5 pts
  • Have you documented your changes clearly and comprehensively?   +5 pts
  • Have you changed or added a feature?   -4 pts
    • Have you added/updated corresponding documentation?   +4 pts
    • Have you added/updated corresponding integration tests?   +5 pts
  • Have you changed the behavior of AutoGPT?   -5 pts
    • Have you also run agbenchmark to verify that these changes do not regress performance?   +10 pts

@MKdir98 MKdir98 requested a review from a team as a code owner February 23, 2024 13:06
Copy link

This PR exceeds the recommended size of 500 lines. Please make sure you are NOT addressing multiple issues with one PR.

Copy link

netlify bot commented Feb 23, 2024

Deploy Preview for auto-gpt-docs ready!

Name Link
🔨 Latest commit 571985a
🔍 Latest deploy log https://app.netlify.com/sites/auto-gpt-docs/deploys/66251d94607b940008634ecd
😎 Deploy Preview https://deploy-preview-6896--auto-gpt-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@MKdir98
Copy link
Contributor Author

MKdir98 commented Feb 23, 2024

This PR needs to be changed. This was just for review.


class AgentGroup:

ceo: AgentMember
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leader and member?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better. I'll change it

@MKdir98
Copy link
Contributor Author

MKdir98 commented Mar 4, 2024

I updated the pull request description. This is a just draft version and needs to be improved.

@MKdir98
Copy link
Contributor Author

MKdir98 commented Mar 4, 2024

One problem I have right now is that we need to have a field as sub_tasks in the AgentTask class. It will store details of sub-tasks created and the status of them. I am going to store sub-tasks in agent_task

Comment on lines 52 to 73
members: list['AgentMember']
create_agent: bool
db: AgentDB
group: 'AgentGroup'
Copy link
Member

@ntindle ntindle Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd clarify how group is conceptually different than members

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a diagram and some description of the difference between them.

@ntindle
Copy link
Member

ntindle commented Mar 9, 2024

One problem I have right now is that we need to have a field as sub_tasks in the AgentTask class. It will store details of sub-tasks created and the status of them. I am going to store sub-tasks in agent_task

Have you read the roadmap items in discussion? I think this mayyy be covered in one?

@MKdir98
Copy link
Contributor Author

MKdir98 commented Mar 10, 2024

One problem I have right now is that we need to have a field as sub_tasks in the AgentTask class. It will store details of sub-tasks created and the status of them. I am going to store sub-tasks in agent_task

Have you read the roadmap items in discussion? I think this mayyy be covered in one?

Could you give me the link of discussion?

@ntindle
Copy link
Member

ntindle commented Mar 13, 2024

#6971

@ntindle
Copy link
Member

ntindle commented Mar 14, 2024

Are these commands enabled? Was trying to test but can't get the llm to execute them lol Commands are not being inserted into the prompt

@MKdir98
Copy link
Contributor Author

MKdir98 commented Mar 14, 2024

Are these commands enabled? Was trying to test but can't get the llm to execute them lol Commands are not being inserted into the prompt

I wrote another sh file to run multi agent mode. But it's not over yet. I am working on it right now.

@MKdir98
Copy link
Contributor Author

MKdir98 commented Mar 14, 2024

I change the proposed action of the agent member.
I added autogpt_multi_agent.sh and a description for that in the pull request description. It's experimental. I can't get good results and commands in my tests. I will record a video if I can for my tests.

./autogpt_multi_agent.sh --member-description "tech_lead:you will be tech lead of github.com/Significant-Gravitas/AutoGPT project and 
you need to get this project better in github:False::1" --member-description "hr_lead:you will be hr of this team. you need to prepare agents for this work done.:True:0" --me
mber-description "senior_python_developer:you will be developer of this team and you will get issues to get them done:False:0"

Copy link
Member

@Pwuts Pwuts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very interesting concept, and decently structured code! Check out my comments on divide_and_conquer.py, there may be something useful in there to get it to work.

@@ -63,7 +65,7 @@ class AgentConfiguration(BaseAgentConfiguration):

class AgentSettings(BaseAgentSettings):
config: AgentConfiguration = Field(default_factory=AgentConfiguration)
prompt_config: OneShotAgentPromptConfiguration = Field(
prompt_config: SystemConfiguration = Field(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please specify the specific types that are valid here, not just the base class

@@ -84,7 +86,7 @@ class Agent(
description=__doc__,
)

prompt_strategy: OneShotAgentPromptStrategy
prompt_strategy: PromptStrategy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same request as above

autogpts/autogpt/autogpt/agents/agent_group.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/agents/agent_group.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/agents/agent_group.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/commands/create_agent.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/commands/hire_agent.py Outdated Show resolved Hide resolved
autogpts/forge/forge/sdk/db.py Outdated Show resolved Hide resolved
@MKdir98
Copy link
Contributor Author

MKdir98 commented Mar 16, 2024

If I change llm response to xml, I will get better result? (I'm getting so non-json result in my tests)
I think we have an issue for this one too.
@ntindle @Pwuts

@MKdir98 MKdir98 force-pushed the feat/add-agent-group branch 2 times, most recently from cd78676 to c3d2edc Compare March 18, 2024 16:02
@github-actions github-actions bot added the conflicts Automatically applied to PRs with merge conflicts label Mar 20, 2024
Copy link

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

@github-actions github-actions bot removed the Forge label Apr 2, 2024
@MKdir98
Copy link
Contributor Author

MKdir98 commented Apr 6, 2024

For support multi-agent, you commented this Does this have to be in the Forge DB? I suggest storing this kind of state in the AgentSettings (or subclass) object, which can be serialized and stored, together with the other state of the agent. and I try to not save tasks in DB. But when I wanted to use benchmark over it, it seemed agbenchmark used uuid of that task to load it from DB. Do you have any advice for me about what should I do? @Pwuts

Copy link
Contributor

@kcze kcze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting and potentially worth merging!

We're working on Component-based Agents (this linked PR doesn't move code to the forge yet - it'll be done in a separate PR) which may be merged any day now. It's going to make the forge more effective and easier to build Agents. Given that, this PR will need a refactor (let me know if you need help, can be on Discord @kcze). I recommend you have a look at the Component Agents PR and linked docs.

Please use black, isort, flake8 to fix linting (docs).

Comment on lines 133 to 134
self.id = str(uuid.uuid4())
settings.agent_id = self.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates two sources of truth for agent_id and so a potential for errors. If you want to have self.id better make it a @property of AgentMember. The same applies to the role (settings.ai_profile.ai_role).

Comment on lines +68 to +89
id: str
role: str
initial_prompt: str
boss: Optional["AgentMember"]
recruiter: Optional["AgentMember"]
tasks: list["AgentTask"]
members: list["AgentMember"]
create_agent: bool
group: "AgentGroup"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be better to move what possible to AgentMemberSettings. AgentMember may be tricky to de/serialize (circular deps in pydantic?) @Pwuts

autogpts/autogpt/autogpt/agents/agent_member.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/app/main.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/commands/create_task.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/agents/agent_group.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/agents/agent_member.py Outdated Show resolved Hide resolved
@kcze
Copy link
Contributor

kcze commented Apr 20, 2024

If I change llm response to xml, I will get better result? (I'm getting so non-json result in my tests)

This is out of scope for this PR and I doubt you will get better results at least on OpenAI which is optimized for json.

... But when I wanted to use benchmark over it, it seemed agbenchmark used uuid of that task to load it from DB. Do you have any advice for me about what should I do?

I wouldn't worry about DB for now; don't change it. Just make sure to store all data that the agent needs in AgentSettings (see #6896 (comment)).

@MKdir98
Copy link
Contributor Author

MKdir98 commented Apr 21, 2024

This is interesting and potentially worth merging!

We're working on Component-based Agents (this linked PR doesn't move code to the forge yet - it'll be done in a separate PR) which may be merged any day now. It's going to make the forge more effective and easier to build Agents. Given that, this PR will need a refactor (let me know if you need help, can be on Discord @kcze). I recommend you have a look at the Component Agents PR and linked docs.

Please use black, isort, flake8 to fix linting (docs).

Thank you @kcze for your great review. I'll check them as soon as I can.

@MKdir98
Copy link
Contributor Author

MKdir98 commented Apr 21, 2024

This is out of scope for this PR and I doubt you will get better results at least on OpenAI which is optimized for json.

Yes, you are right.

I wouldn't worry about DB for now; don't change it. Just make sure to store all data that the agent needs in AgentSettings (see #6896 (comment)).

Yeah. I found it recently. I will fix this one too for benchmark.

* Add `divider_and_conquer` strategy for using in agent members
* Add `AgentMember` class
* Add `AgentGroup` class
* Add `hire_agent` and `create_agent` and `create_task`
* Add `test_agent_group` as an intergration test with VCR
* Add `AgentTaskStatus` for flow of doing tasks
* Add `autogpt_multi_agent.sh` file to run autogpt in multi agent mode
@Swiftyos
Copy link
Contributor

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

PR Review

⏱️ Estimated effort to review [1-5]

4, because the PR introduces a complex new feature with multiple new classes and methods across several files. The changes involve intricate logic for agent management and task handling, which requires careful consideration to ensure correctness and maintainability.

🧪 Relevant tests

Yes

🔍 Possible issues

Possible Bug: The method create_task in AgentMember class does not handle exceptions properly. If an exception occurs, it only logs the error without any further handling, which might lead to unmanaged task states or failures in task creation without proper rollback or user notification.

Design Concern: The AgentGroup class tightly couples member management and task handling, which might make it difficult to extend or modify the behavior of agent groups without affecting task management.

🔒 Security concerns

No

Code feedback:
relevant fileautogpts/autogpt/autogpt/agents/agent_member.py
suggestion      

Consider implementing exception handling in the create_task method to manage task state properly in case of errors. This could include rolling back changes, notifying the user, or retrying task creation. [important]

relevant lineexcept Exception as e:

relevant fileautogpts/autogpt/autogpt/agents/agent_group.py
suggestion      

Refactor the AgentGroup class to separate concerns between member management and task handling. This could involve creating separate classes or methods that handle these concerns independently, improving modularity and maintainability. [important]

relevant lineclass AgentGroup:

relevant fileautogpts/autogpt/autogpt/agents/agent_member.py
suggestion      

Add validation for the role, initial_prompt, and boss_id parameters in the create_agent_member function to ensure they meet expected formats or conditions before processing. This can prevent issues related to invalid data being used in agent creation. [medium]

relevant lineasync def create_agent_member(

relevant fileautogpts/autogpt/autogpt/agents/agent_member.py
suggestion      

Optimize the get_list_of_all_your_team_members method by using a more efficient data structure or algorithm to handle large numbers of members, as the current recursive method could lead to performance issues with large agent trees. [medium]

relevant linedef get_list_of_all_your_team_members(self) -> list["AgentMember"]:


✨ Review tool usage guide:

Overview:
The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

  • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
/review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
[pr_reviewer]
some_config1=...
some_config2=...

See the review usage page for a comprehensive guide on using this tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoGPT Agent conflicts Automatically applied to PRs with merge conflicts size/xl
Projects
Status: 🚧 Needs work
Development

Successfully merging this pull request may close these issues.

None yet

6 participants