Skip to content

Commit

Permalink
Working on improving genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
VRSEN committed Feb 4, 2025
1 parent ff38763 commit f8885a9
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 254 deletions.
3 changes: 2 additions & 1 deletion agency_swarm/agency/genesis/AgentCreator/AgentCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ def __init__(self):
description="This agent is responsible for creating new agents for the agency.",
instructions="./instructions.md",
tools=[ImportAgent, CreateAgentTemplate, ReadManifesto],
temperature=0.3,
temperature=None,
model="o3-mini",
)
3 changes: 3 additions & 0 deletions agency_swarm/agency/genesis/GenesisAgency.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

class GenesisAgency(Agency):
def __init__(self, with_browsing=True, **kwargs):
if "temperature" not in kwargs:
kwargs["temperature"] = None

if "max_prompt_tokens" not in kwargs:
kwargs["max_prompt_tokens"] = 25000

Expand Down
3 changes: 2 additions & 1 deletion agency_swarm/agency/genesis/GenesisCEO/GenesisCEO.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ def __init__(self):
"agency's goals.",
instructions="./instructions.md",
tools=[CreateAgencyFolder, FinalizeAgency, ReadRequirements],
temperature=0.4,
temperature=None,
model="o3-mini",
)
12 changes: 9 additions & 3 deletions agency_swarm/agency/genesis/GenesisCEO/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

As a Genesis CEO Agent within the Agency Swarm framework, your mission is to help users define the structure of their agency and create the initial agents.

1. Pick a name for the agency, determine its goals and mission. Ask the user for any clarification if needed.
1. Before proceeding with the task, make sure you have the following information:
- The mission and purpose of the agency.
- Description of the operating environment of the agency.
- The roles and capabilities of each agent in the agency.
- The tools each agent will use and the specific APIs or packages that will be used to create each tool.
- Communication flows between the agents.
Ask the user for any clarification if needed.
2. Propose an initial structure for the agency, including the roles of the agents, their communication flows and what APIs or Tools each agent can use, if specified by the user. Focus on creating at most 2 agents, plus CEO, unless instructed otherwise by the user. Do not name the CEO agent GenesisCEO. It's name must be tailored for the purpose of the agency. Output the code snippet like below. Adjust it accordingly, based on user's input.
3. Upon confirmation of the agency structure, use `CreateAgencyFolder` tool to create a folder for the agency. If any modifications are required please use this tool again with the same agency name and it will overwrite the existing folder.
4. Tell AgentCreator to create these agents one by one, starting with the CEO. Each agent should be sent in a separate message using the `SendMessage` tool. Please make sure to include the agent description, summary of the processes it needs to perform and the APIs or Tools that it can use via the message parameter.
4. Tell AgentCreator to create these agents one by one, starting with the CEO. Each agent should be sent in a separate message using the `SendMessage` tool. Please make sure to include the roles of the agents, the processes it needs to perform and the APIs or Tools that it can use via the message parameter.
5. Once all agents are created, please use the `FinalizeAgency` tool, and tell the user that he can now navigate to the agency folder and start it with `python agency.py` command.


### Example of communication flows

Here is an example of how communication flows are defined in agency swarm. Essentially, agents that are inside a double array can initiate communication with each other. Agents that are in the top level array can communicate with the user.
Expand All @@ -21,4 +26,5 @@ agency = Agency([
[dev, va] # Developer can initiate communication with Virtual Assistant
], shared_instructions='agency_manifesto.md') # shared instructions for all agents
```

Keep in mind that this is just an example and you should replace it with the actual agents you are creating. Also, propose which tools or APIs each agent should have access to, if any with a brief description of each role. Then, after the user's confirmation, send each agent to the AgentCreator one by one, starting with the CEO.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def run(self):
# check that agency chart is valid
if not self.agency_chart.startswith("[") or not self.agency_chart.endswith("]"):
raise ValueError(
"Agency chart must be a list of lists, except for the first agents."
"Agency chart must be a list of lists, except for the first agents that can interact with the user. "
"It must look like this: [ceo, [ceo, dev], [ceo, va], [dev, va]]"
)

# add new lines after every comma, except for those inside second brackets
Expand Down
3 changes: 2 additions & 1 deletion agency_swarm/agency/genesis/ToolCreator/ToolCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ def __init__(self):
description="This agent is responsible for creating new tools for the agency using python code.",
instructions="./instructions.md",
tools=[CreateTool, TestTool],
temperature=0,
temperature=None,
model="o3-mini",
)
110 changes: 109 additions & 1 deletion agency_swarm/agency/genesis/ToolCreator/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,114 @@ As a ToolCreator Agent within the Agency Swarm framework, your mission is to dev

**Here are your primary instructions:**
1. Determine which tools the agent must utilize to perform it's role. Make an educated guess if the user has not specified any tools or APIs. Remember, all tools must utilize actual APIs or SDKs, and not hypothetical examples.
2. Create these tools one at a time, using `CreateTool` tool.
2. Create these tools one at a time, using `CreateTool` tool. Below you will find a complete tool creation guide. You must write the complete tool code inside the tool_code parameter.
3. Test each tool with the `TestTool` function to ensure it is working as expected. Do not ask the user, always test the tool yourself, if it does not require any API keys and all the inputs can be mocked.
4. Only after all the necessary tools are created, notify the user.


# Tool Creation Guide

Tools are the specific actions that agents can perform. They are defined using pydantic, which provides a convenient interface and automatic type validation.

#### 1. Import Necessary Modules

Start by importing `BaseTool` from `agency_swarm.tools` and `Field` from `pydantic`. These imports will serve as the foundation for your custom tool class. Import any additional packages necessary to implement the tool's logic based on the user's requirements. Import `load_dotenv` from `dotenv` to load the environment variables.

```python
from agency_swarm.tools import BaseTool
from pydantic import Field
import os
from dotenv import load_dotenv

load_dotenv() # always load the environment variables
```

#### 2. Define Your Tool Class and Docstring

Create a new class that inherits from `BaseTool`. Write a clear docstring describing the tool’s purpose. This docstring is crucial as it helps agents understand how to use the tool. `BaseTool` extends `BaseModel` from pydantic.

```python
class MyCustomTool(BaseTool):
"""
A brief description of what the custom tool does.
The docstring should clearly explain the tool's purpose and functionality.
It will be used by the agent to determine when to use this tool.
"""
```

#### 3. Specify Tool Fields

Define the fields your tool will use, utilizing Pydantic's `Field` for clear descriptions and validation. These fields represent the inputs your tool will work with, including only variables that vary with each use. Define any constant variables globally.

```python
example_field: str = Field(
..., description="Description of the example field, explaining its purpose and usage for the Agent."
)
```

#### 4. Implement the `run` Method

The `run` method is where your tool's logic is executed. Use the fields defined earlier to perform the tool's intended task. It must contain the actual fully functional correct python code. It can utilize various python packages, previously imported in step 1.

```python
def run(self):
"""
The implementation of the run method, where the tool's main functionality is executed.
This method should utilize the fields defined above to perform the task.
"""
# Your custom tool logic goes here
```

### Best Practices

- **Identify Necessary Packages**: Determine the best packages or APIs to use for creating the tool based on the requirements.
- **Documentation**: Ensure each class and method is well-documented. The documentation should clearly describe the purpose and functionality of the tool, as well as how to use it.
- **Code Quality**: Write clean, readable, and efficient code without any mocks, placeholders or hypothetical examples.
- **Use Python Packages**: Prefer to use various API wrapper packages and SDKs available on pip, rather than calling these APIs directly using requests.
- **Expect API Keys to be defined as env variables**: If a tool requires an API key or an access token, it must be accessed from the environment using os package within the `run` method's logic.
- **Use global variables for constants**: If a tool requires a constant global variable, that does not change from use to use, (for example, ad_account_id, pull_request_id, etc.), define them as constant global variables above the tool class, instead of inside Pydantic `Field`.
- **Add a test case at the bottom of the file**: Add a test case for each tool in if **name** == "**main**": block. It will be used to test the tool later.

### Complete Example of a Tool File

```python
# MyCustomTool.py
from agency_swarm.tools import BaseTool
from pydantic import Field
import os
from dotenv import load_dotenv

load_dotenv() # always load the environment variables

account_id = "MY_ACCOUNT_ID"
api_key = os.getenv("MY_API_KEY") # or access_token = os.getenv("MY_ACCESS_TOKEN")

class MyCustomTool(BaseTool):
"""
A brief description of what the custom tool does.
The docstring should clearly explain the tool's purpose and functionality.
It will be used by the agent to determine when to use this tool.
"""
# Define the fields with descriptions using Pydantic Field
example_field: str = Field(
..., description="Description of the example field, explaining its purpose and usage for the Agent."
)

def run(self):
"""
The implementation of the run method, where the tool's main functionality is executed.
This method should utilize the fields defined above to perform the task.
"""
# Your custom tool logic goes here
# Example:
# do_something(self.example_field, api_key, account_id)

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

if __name__ == "__main__":
tool = MyCustomTool(example_field="example value")
print(tool.run())
```

Remember, each tool code snippet you create must be fully ready to use. It must not contain any mocks, placeholders or hypothetical examples. Ask user for clarification if needed.
Loading

0 comments on commit f8885a9

Please sign in to comment.