Skip to content

Commit

Permalink
Merge branch 'tool-factory'
Browse files Browse the repository at this point in the history
  • Loading branch information
VRSEN committed Dec 5, 2023
2 parents f32725d + a54e1c6 commit 9e19c7d
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,10 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/*
tests/test_agent/*
tests/test_files/lorem_ipsum_file-ZTGySImlnQ7EyHDOlw1COhpM.txt
tests/test_files/lorem_ipsum_file-ZTGySImlnQ7EyHDOlw1COhpM.txt
tests/agency_manifesto.md
tests/agency_manifesto.txt
tests/settings.json
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ from agency_swarm.tools import ToolFactory
LangchainTool = ToolFactory.from_langchain_tool(YouTubeSearchTool)
```

or

```python
from langchain.agents import load_tools

tools = load_tools(
["arxiv", "human"],
)

tools = ToolFactory.from_langchain_tools(tools)
```


3. **Define Agent Roles**: Start by defining the roles of your agents. For example, a CEO agent for managing tasks and a developer agent for executing tasks.

Expand Down Expand Up @@ -120,6 +132,34 @@ or get completion from the agency:
agency.get_completion("Please create a new website for our client.")
```

## Creating Agent Templates Locally (CLI)

This CLI command simplifies the process of creating a structured environment for each agent.

#### **Command Syntax:**

```bash
agency-swarm create-agent-template --name "AgentName" --description "Agent Description" [--path "/path/to/directory"] [--use_txt]
```

### Folder Structure

When you run the `create-agent-template` command, it creates the following folder structure for your agent:

```
/your-specified-path/
├── agency_manifesto.md or .txt # Agency's guiding principles (created if not exists)
└── agent_name/ # Directory for the specific agent
├── agent_name.py # The main agent class file
├── __init__.py # Initializes the agent folder as a Python package
├── instructions.md or .txt # Instruction document for the agent
├── tools.py # Tools specific to the agent
├── files/ # Directory for additional resources
```

This structure ensures that each agent has its dedicated space with all necessary files to start working on its specific tasks. The `tools.py` can be customized to include tools and functionalities specific to the agent's role.

## Future Enhancements

- Asynchronous communication and task handling.
Expand Down
26 changes: 26 additions & 0 deletions agency_swarm/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import argparse

from agency_swarm.util import create_agent_template


def main():
parser = argparse.ArgumentParser(description='Create agent template.')

subparsers = parser.add_subparsers(dest='create_template', help='Create agent template.')
subparsers.required = True

create_parser = subparsers.add_parser('create-agent-template', help='Create agent template folder locally.')
create_parser.add_argument('--path', type=str, default="./", help='Path to create agent folder.')
create_parser.add_argument('--use_txt', action='store_true', default=False,
help='Use txt instead of md for instructions and manifesto.')
create_parser.add_argument('--name', type=str, help='Name of agent.')
create_parser.add_argument('--description', type=str, help='Description of agent.')

args = parser.parse_args()

if args.create_template == "create-agent-template":
create_agent_template(args.name, args.description, args.path, args.use_txt)


if __name__ == "__main__":
main()
13 changes: 13 additions & 0 deletions agency_swarm/tools/tool_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@

class ToolFactory:

@staticmethod
def from_langchain_tools(tools: List):
"""
Converts a list of langchain tools into a list of BaseTools.
:param tools: A list of langchain tools.
:return: A list of BaseTools.
"""
converted_tools = []
for tool in tools:
converted_tools.append(ToolFactory.from_langchain_tool(tool))

return converted_tools

@staticmethod
def from_langchain_tool(tool):
"""
Expand Down
9 changes: 5 additions & 4 deletions agency_swarm/util/create_agent_template.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os


def create_agent_template(path="./", use_txt=False):
agent_name = input("Enter agent name: ")
agent_description = input("Enter agent description: ")
def create_agent_template(agent_name=None, agent_description=None, path="./", use_txt=False):
if not agent_name:
agent_name = input("Enter agent name: ")
if not agent_description:
agent_description = input("Enter agent description: ")

# create manifesto if it doesn't exist
agency_manifesto = "agency_manifesto.md" if not use_txt else "agency_manifesto.txt"
Expand Down Expand Up @@ -80,4 +82,3 @@ def run(self):
\"\"\"Enter your code for tool execution here.\"\"\"
pass
"""

21 changes: 12 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
requirements = f.read().splitlines()

setup(
name='agency-swarm', # Replace with your package's name
version='0.1.0', # Initial version of your package
author='VRSEN', # Replace with your name
author_email='arseny9795@gmail.com', # Replace with your email address
description='Create your own agency with an agent swarms.', # Provide a short description
long_description=open('README.md').read(), # Long description read from the README.md
long_description_content_type='text/markdown', # Content type of the long description
url='https://github.com/VRSEN/agency-swarm', # Replace with the URL of your package's repository
packages=find_packages(), # Automatically find all packages and subpackages
name='agency-swarm',
version='0.1.0',
author='VRSEN',
author_email='arseny9795@gmail.com',
description='Replace your own agency with an agent swarm.',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
url='https://github.com/VRSEN/agency-swarm',
packages=find_packages(),
install_requires=requirements,
classifiers=[
# Classifiers help users find your project by categorizing it
Expand All @@ -26,5 +26,8 @@
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
],
entry_points = {
'console_scripts': ['agency-swarm=agency_swarm.cli:main'],
},
python_requires='>=3.7', # Specify the Python version requirements
)

0 comments on commit 9e19c7d

Please sign in to comment.