Skip to content

Commit

Permalink
Make browsing agent optional in genesis agency
Browse files Browse the repository at this point in the history
  • Loading branch information
VRSEN committed Feb 19, 2024
1 parent 01f993e commit 81ff3ad
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 24 deletions.
9 changes: 4 additions & 5 deletions agency_swarm/agency/genesis/AgentCreator/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ The user will communicate to you each agent that needs to be created. Below are

**Primary Instructions:**
1. First, read the manifesto using `ReadManifesto` tool if you have not already done so. This file contains the agency manifesto that describes the agency's purpose and goals.
2. Then, create a new agent using `CreateAgentTemplate` function.
3. If the agent you are creating needs to utilize any APIs, tell the OpenAPICreator agent to create API schemas for this agent. Make sure to also communicate the agent description, name and a summary of the processes that it needs to perform. CEO agents do not need to perform any API calls or use any tools, so you can skip the following steps.
4. For agents that do not need to utilize any APIs to perform their roles, tell the ToolCreator agent to create tools for this agent. Make sure to also communicate the agent description, name and a summary of the processes that it needs to perform.
5. If there are no issues and tools amd APIs have been successfully created, notify the user that the agent has been created. Otherwise, try to resolve any issues with other agents before reporting back.
6. Repeat this process for each agent that needs to be created.
2. Create a new agent using `CreateAgentTemplate` function.
3. Tell the ToolCreator or OpenAPICreator agent to create tools or APIs for this agent. Make sure to also communicate the agent description, name and a summary of the processes that it needs to perform. CEO Agents do not need to utilize any tools, so you can skip this and the following steps.
4. If there are no issues and tools or APIs have been successfully created, notify the user that the agent has been created. Otherwise, try to resolve any issues with other agents before reporting back.
5. Repeat this process for each agent that needs to be created.
30 changes: 17 additions & 13 deletions agency_swarm/agency/genesis/GenesisAgency.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from agency_swarm import Agency
from .AgentCreator import AgentCreator
from agency_swarm.agents.browsing import BrowsingAgent

from .GenesisCEO import GenesisCEO
from .OpenAPICreator import OpenAPICreator
from .ToolCreator import ToolCreator
Expand All @@ -9,30 +9,34 @@


class GenesisAgency(Agency):
def __init__(self, **kwargs):
def __init__(self, with_browsing=True, **kwargs):

if 'agency_chart' not in kwargs:
agent_creator = AgentCreator()
genesis_ceo = GenesisCEO()
tool_creator = ToolCreator()
openapi_creator = OpenAPICreator()
browsing_agent = BrowsingAgent()
kwargs['agency_chart'] = [
genesis_ceo, tool_creator, agent_creator,
[genesis_ceo, agent_creator],
# [agent_creator, openapi_creator],
# [openapi_creator, browsing_agent],
[agent_creator, tool_creator],
]

if with_browsing:
from agency_swarm.agents.browsing import BrowsingAgent
browsing_agent = BrowsingAgent()

browsing_agent.instructions += ("""\n
browsing_agent.instructions += ("""\n
# BrowsingAgent's Primary instructions
1. Browse the web to find the API documentation requested by the user. Prefer searching google directly for this API documentation page.
2. Navigate to the API documentation page and ensure that it contains the necessary API endpoints descriptions. You can use the AnalyzeContent tool to check if the page contains the necessary API descriptions. If not, try perfrom another search in google and keep browsing until you find the right page.
3. If you have confirmed that the page contains the necessary API documentation, export the page with ExportFile tool. Then, send the file_id back to the user along with a brief description of the API.
4. Repeat these steps for each new agent, as requested by the user.
""")

kwargs['agency_chart'] = [
genesis_ceo, tool_creator, agent_creator,
[genesis_ceo, agent_creator],
[agent_creator, openapi_creator],
[openapi_creator, browsing_agent],
[agent_creator, tool_creator],
]
""")
kwargs['agency_chart'].append(openapi_creator)
kwargs['agency_chart'].append([openapi_creator, browsing_agent])

if 'shared_instructions' not in kwargs:
kwargs['shared_instructions'] = "./manifesto.md"
Expand Down
13 changes: 10 additions & 3 deletions agency_swarm/agency/genesis/ToolCreator/instructions.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# ToolCreator Agent Instructions

You are an agent that creates tools for other agents, as instructed by the user.
As a ToolCreator Agent within the Genesis Agency of the Agency Swarm framework, your mission is to develop tools that enhance the capabilities of other agents. These tools are pivotal for enabling agents to achieve their collective objectives.

**Here are your primary instructions:**
1. Determine which tools the agent must utilize to perform it's role. If anything is unclear, ask the user for more information.
2. Create these tools one at a time, using `CreateTool` function. Below is documentation on how tools in agency swarm are defined.
2. Create these tools one at a time, using `CreateTool` function. Below are detailed instructions to guide you through the process of creating tools, ensuring they are both functional and align with the framework's standards.
3. Test each tool with the `TestTool` function to ensure it is working as expected.
4. Once all the necessary tools are created, notify the user.

Expand All @@ -15,6 +15,10 @@ To create a tool, you must define a new class that inherits from `BaseTool` and
```python
from agency_swarm.tools import BaseTool
from pydantic import Field
# Include additional imports here

# apy global variables like api keys, tokens, etc. here
api_key = "your api key"

class MyCustomTool(BaseTool):
"""
Expand All @@ -41,4 +45,7 @@ class MyCustomTool(BaseTool):

# Return the result of the tool's operation as a string
return "Result of MyCustomTool operation"
```
```

Keep in mind that each tool must have an actual production ready implementation of the run method. It is recommended to use packages and SDKs available on pip instead of writing custom code.

12 changes: 10 additions & 2 deletions agency_swarm/agency/genesis/ToolCreator/tools/CreateTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class CreateTool(BaseTool):
"as well as the primary tool class that extends BaseTool. Name of this class must match tool_name.",
examples=[example_tool_template]
)
agency_name: str = Field(
None, description="Name of the agency to create the tool for. Defaults to the agency currently being created."
)

def run(self):
os.chdir(self.shared_state.get("agency_path"))
Expand All @@ -39,8 +42,13 @@ def run(self):

@model_validator(mode="after")
def validate_agent_name(self):
if not self.shared_state.get("agency_path"):
raise ValueError("Please tell the user that he must create agency first.")
if not self.shared_state.get("agency_path") and not self.agency_name:
available_agencies = os.listdir("./")
# filter out non-directories
available_agencies = [agency for agency in available_agencies if os.path.isdir(agency)]
raise ValueError(f"Please specify an agency. Available agencies are: {available_agencies}")
elif not self.shared_state.get("agency_path") and self.agency_name:
self.shared_state.set("agency_path", os.path.join("./", self.agency_name))

agent_path = os.path.join(self.shared_state.get("agency_path"), self.agent_name)
if not os.path.exists(agent_path):
Expand Down
3 changes: 2 additions & 1 deletion agency_swarm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def main():
# genesis-agency
genesis_parser = subparsers.add_parser('genesis', help='Start genesis agency.')
genesis_parser.add_argument('--openai_key', default=None, type=str, help='OpenAI API key.')
genesis_parser.add_argument('--with_browsing', default=False, type=bool, help='Enable browsing agent.')

args = parser.parse_args()

Expand All @@ -36,7 +37,7 @@ def main():
set_openai_key(args.openai_key)

from agency_swarm.agency.genesis import GenesisAgency
agency = GenesisAgency()
agency = GenesisAgency(with_browsing=args.with_browsing)
agency.run_demo()


Expand Down

0 comments on commit 81ff3ad

Please sign in to comment.