-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(agents): Add CrewAI agent support and tests (#148)
* feat(agents): Add CrewAI agent support and tests Signed-off-by: Nigel Jones <[email protected]> * interim test update Signed-off-by: Nigel Jones <[email protected]> * interim test update Signed-off-by: Nigel Jones <[email protected]> * interim test update Signed-off-by: Nigel Jones <[email protected]> * interim update Signed-off-by: Nigel Jones <[email protected]> * feat(internal): Add unit test automation Signed-off-by: Nigel Jones <[email protected]> * Fix github actions Signed-off-by: Nigel Jones <[email protected]> * Fix github actions Signed-off-by: Nigel Jones <[email protected]> * github action .yml -> .yaml Signed-off-by: Nigel Jones <[email protected]> * updates to github action Signed-off-by: Nigel Jones <[email protected]> * Additional updates of import to base module Signed-off-by: Nigel Jones <[email protected]> * Correct location of tests directory Signed-off-by: Nigel Jones <[email protected]> * Enable stdout for pytest Signed-off-by: Nigel Jones <[email protected]> * Remove unneeded bee test from crewai test yaml Signed-off-by: Nigel Jones <[email protected]> * Explicitly check test output Signed-off-by: Nigel Jones <[email protected]> * Use single quotes for branch names for trigger Signed-off-by: Nigel Jones <[email protected]> * remove vscode configuration Signed-off-by: Nigel Jones <[email protected]> --------- Signed-off-by: Nigel Jones <[email protected]>
- Loading branch information
Showing
16 changed files
with
346 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Bee-Hive Tests | ||
|
||
on: | ||
push: | ||
branches: [ 'main' ] | ||
pull_request: | ||
branches: [ 'main' ] | ||
|
||
jobs: | ||
run-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
- name: Setup poetry | ||
run: | | ||
pipx ensurepath | ||
echo "$HOME/.local/bin" >> "$GITHUB_PATH" | ||
pipx install poetry | ||
poetry self add poetry-plugin-shell | ||
- name: Install dependencies | ||
run: | | ||
cd bee-hive | ||
poetry install | ||
- name: Run unit tests | ||
run: | | ||
cd bee-hive | ||
poetry run pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,3 +170,5 @@ cython_debug/ | |
/examples/**/agent_store.json | ||
/bee-hive/agent_store.json | ||
|
||
# VScode | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
from enum import Enum | ||
from typing import Callable, Type, Union | ||
from bee_hive.bee_agent import BeeAgent | ||
from bee_hive.crewai_agent import CrewAIAgent | ||
|
||
class AgentFramework(Enum): | ||
"""Enumeration of supported frameworks""" | ||
BEE = "bee" | ||
CREWAI = "crewai" | ||
|
||
class AgentFactory: | ||
"""Factory class for handling agent frameworks""" | ||
@staticmethod | ||
def create_agent(framework: AgentFramework) -> Callable[..., Union[BeeAgent, CrewAIAgent]]: | ||
"""Create an instance of the specified agent framework. | ||
Args: | ||
framework (AgentFramework): The framework to create. Must be a valid enum value. | ||
Returns: | ||
A new instance of the corresponding agent class. | ||
""" | ||
factories = { | ||
AgentFramework.BEE: BeeAgent, | ||
AgentFramework.CREWAI: CrewAIAgent | ||
} | ||
|
||
if framework not in factories: | ||
raise ValueError(f"Unknown framework: {framework}") | ||
|
||
return factories[framework] | ||
|
||
@classmethod | ||
def get_factory(cls, framework: str) -> Callable[..., Union[BeeAgent, CrewAIAgent]]: | ||
"""Get a factory function for the specified agent type.""" | ||
return cls.create_agent(framework) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
import importlib | ||
|
||
from bee_hive.agent import Agent | ||
|
||
class CrewAIAgent(Agent): | ||
""" | ||
CrewAIAgent extends the Agent class to load and run a specific CrewAI agent. | ||
""" | ||
def __init__(self, agent: dict) -> str: | ||
""" | ||
Initializes the workflow for the specified agent. | ||
The executable code must be within $PYTHONPATH. | ||
Args: | ||
agent_name (dict): Agent Configuration | ||
Raises: | ||
Exception: If the agent cannot be loaded, an exception is raised with an error message. | ||
""" | ||
|
||
super().__init__(agent) | ||
|
||
# TODO: Add additional properties later. for now using naming: | ||
# <directory>.<filename>.<class>.<method> ie | ||
# test.crewai_test.ColdWeatherCrew.activity_crew | ||
|
||
try: | ||
partial_agent_name, method_name = self.agent_name.rsplit(".", 1) | ||
module_name, class_name = partial_agent_name.rsplit(".", 1) | ||
my_module = importlib.import_module(module_name) | ||
# Get the class object | ||
self.crew_agent_class = getattr(my_module, class_name) | ||
# Instantiate the class | ||
self.instance = self.crew_agent_class() | ||
self.method_name = method_name | ||
except Exception as e: | ||
print(f"Failed to load agent {self.agent_name}: {e}") | ||
raise(e) | ||
|
||
|
||
def run(self, prompt: str) -> str: | ||
""" | ||
Executes the CrewAI agent with the given prompt. The agent's `kickoff` method is called with the input. | ||
Args: | ||
prompt (str): The input to be processed by the agent. | ||
Returns: | ||
Any: The output from the agent's `kickoff` method. | ||
Raises: | ||
Exception: If there is an error in retrieving or executing the agent's method. | ||
""" | ||
print(f"Running CrewAI agent: {self.agent_name} with prompt: {prompt}") | ||
|
||
try: | ||
method = getattr(self.instance, self.method_name) | ||
output = method().kickoff(prompt) | ||
return output | ||
|
||
except Exception as e: | ||
print(f"Failed to kickoff crew agent: {self.agent_name}: {e}") | ||
raise(e) | ||
|
||
def run_streaming(self, prompt) ->str: | ||
""" | ||
Streams the execution of the CrewAI agent with the given prompt. | ||
This is NOT YET IMPLEMENTED | ||
Args: | ||
prompt (str): The input prompt to be processed by the CrewAI agent. | ||
Raises: | ||
NotImplementedError: Indicates that the CrewAI agent execution logic is not yet implemented. | ||
""" | ||
print(f"Running CrewAI agent (streaming): {self.agent_name} with prompt: {prompt}") | ||
|
||
raise NotImplementedError("CrewAI agent execution logic not implemented yet") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.