Skip to content

Commit

Permalink
Merge pull request #191 from bonk1t/dev/apply-ruff
Browse files Browse the repository at this point in the history
Set Up and Apply Pre-Commit Hooks with Ruff
  • Loading branch information
VRSEN authored Dec 3, 2024
2 parents 2349f77 + 3e5cd6e commit dbd0299
Show file tree
Hide file tree
Showing 127 changed files with 3,102 additions and 1,898 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: docs
on:
push:
branches:
- master
- master
- main
permissions:
contents: write
Expand All @@ -23,12 +23,12 @@ jobs:
with:
python-version: "3.10"

- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- run: pip install -r requirements_docs.txt
- run: mkdocs gh-deploy --force
- run: mkdocs gh-deploy --force
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@ cython_debug/
settings.json
.DS_Store
tests/test_agents/
test_agents/
test_agents/
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- id: debug-statements
language_version: python3

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
hooks:
- id: ruff
args: [--fix, --select=I]
- id: ruff-format
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Contributing to Agency Swarm
Each agent or tool you add to Agency Swarm will automatically be available for import by the Genesis Swarm, which will help us create an exponentially larger and smarter system.
Each agent or tool you add to Agency Swarm will automatically be available for import by the Genesis Swarm, which will help us create an exponentially larger and smarter system.

This document provides guidelines for contributing new agents to the framework.

Expand All @@ -23,7 +23,7 @@ agency_swarm/agents/AgentName/

### Creating an Agent

1. Follow the structure below in your `AgentName.py` as a guideline.
1. Follow the structure below in your `AgentName.py` as a guideline.
2. All tools (except schemas) should be imported in `AgentName.py` from the `agency_swarm/tools/...` folder.

```python
Expand All @@ -42,4 +42,4 @@ class AgentName(Agent):

---

Thank you for contributing to Agency Swarm! Your efforts help us build a more robust and versatile framework.
Thank you for contributing to Agency Swarm! Your efforts help us build a more robust and versatile framework.
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Agency Swarm started as a desire and effort of Arsenii Shatokhin (aka VRSEN) to

- **Customizable Agent Roles**: Define roles like CEO, virtual assistant, developer, etc., and customize their functionalities with [Assistants API](https://platform.openai.com/docs/assistants/overview).
- **Full Control Over Prompts**: Avoid conflicts and restrictions of pre-defined prompts, allowing full customization.
- **Tool Creation**: Tools within Agency Swarm are created using [Instructor](https://github.com/jxnl/instructor), which provides a convenient interface and automatic type validation.
- **Tool Creation**: Tools within Agency Swarm are created using [Instructor](https://github.com/jxnl/instructor), which provides a convenient interface and automatic type validation.
- **Efficient Communication**: Agents communicate through a specially designed "send message" tool based on their own descriptions.
- **State Management**: Agency Swarm efficiently manages the state of your assistants on OpenAI, maintaining it in a special `settings.json` file.
- **Deployable in Production**: Agency Swarm is designed to be reliable and easily deployable in production environments.
Expand All @@ -45,45 +45,45 @@ Define your custom tools with [Instructor](https://github.com/jxnl/instructor):
```python
from agency_swarm.tools import BaseTool
from pydantic import Field

class MyCustomTool(BaseTool):
"""
A brief description of what the custom tool does.
A brief description of what the custom tool does.
The docstring should clearly explain the tool's purpose and functionality.
"""

# Define the fields with descriptions using Pydantic Field
example_field: str = Field(
..., description="Description of the example field, explaining its purpose and usage."
)

# Additional fields as required
# ...

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 its task.
Doc string description is not required for this method.
"""

# Your custom tool logic goes here
do_something(self.example_field)

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

or convert from OpenAPI schemas:

```python
from agency_swarm.tools import ToolFactory
# using local file
with open("schemas/your_schema.json") as f:
tools = ToolFactory.from_openapi_schema(
f.read(),
)

# using requests
tools = ToolFactory.from_openapi_schema(
requests.get("https://api.example.com/openapi.json").json(),
Expand All @@ -94,13 +94,13 @@ Define your custom tools with [Instructor](https://github.com/jxnl/instructor):

```python
from agency_swarm import Agent

ceo = Agent(name="CEO",
description="Responsible for client communication, task planning and management.",
instructions="You must converse with other agents to ensure complete task execution.", # can be a file like ./instructions.md
files_folder="./files", # files to be uploaded to OpenAI
schemas_folder="./schemas", # OpenAPI schemas to be converted into tools
tools=[MyCustomTool],
tools=[MyCustomTool],
temperature=0.5, # temperature for the agent
max_prompt_tokens=25000, # max tokens in conversation history
)
Expand All @@ -111,29 +111,29 @@ Define your custom tools with [Instructor](https://github.com/jxnl/instructor):
```bash
agency-swarm import-agent --name "Devid" --destination "./"
```

This will import Devid (Software Developer) Agent locally, including all source code files, so you have full control over your system. Currently, available agents are: `Devid`, `BrowsingAgent`.



4. **Define Agency Communication Flows**:
4. **Define Agency Communication Flows**:
Establish how your agents will communicate with each other.

```python
from agency_swarm import Agency
# if importing from local files
from Developer import Developer
from VirtualAssistant import VirtualAssistant

dev = Developer()
va = VirtualAssistant()

agency = Agency([
ceo, # CEO will be the entry point for communication with the user
[ceo, dev], # CEO can initiate communication with Developer
[ceo, va], # CEO can initiate communication with Virtual Assistant
[dev, va] # Developer can initiate communication with Virtual Assistant
],
],
shared_instructions='agency_manifesto.md', #shared instructions for all agents
temperature=0.5, # default temperature for all agents
max_prompt_tokens=25000 # default max tokens in conversation history
Expand All @@ -142,23 +142,23 @@ Establish how your agents will communicate with each other.

In Agency Swarm, communication flows are directional, meaning they are established from left to right in the agency_chart definition. For instance, in the example above, the CEO can initiate a chat with the developer (dev), and the developer can respond in this chat. However, the developer cannot initiate a chat with the CEO. The developer can initiate a chat with the virtual assistant (va) and assign new tasks.

5. **Run Demo**:
5. **Run Demo**:
Run the demo to see your agents in action!

Web interface:

```python
agency.demo_gradio(height=900)
```

Terminal version:

```python
agency.run_demo()
```

Backend version:

```python
completion_output = agency.get_completion("Please create a new website for our client.")
```
Expand Down Expand Up @@ -213,12 +213,12 @@ When you run the `create-agent-template` command, it creates the following folde
└── AgentName/ # Directory for the specific agent
├── files/ # Directory for files that will be uploaded to openai
├── schemas/ # Directory for OpenAPI schemas to be converted into tools
├── tools/ # Directory for tools to be imported by default.
├── tools/ # Directory for tools to be imported by default.
├── AgentName.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 # Custom tools specific to the agent
```

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.
Expand Down
5 changes: 1 addition & 4 deletions agency_swarm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from .agency import Agency
from .agents import Agent
from .tools import BaseTool
from .util import set_openai_key
from .util import set_openai_client
from .util import get_openai_client
from .util import get_openai_client, llm_validator, set_openai_client, set_openai_key
from .util.streaming import AgencyEventHandler
from .util import llm_validator
Loading

0 comments on commit dbd0299

Please sign in to comment.