Skip to content

Commit

Permalink
add docstrings for crewai module
Browse files Browse the repository at this point in the history
  • Loading branch information
User committed May 28, 2024
1 parent dd3a3e0 commit ef25016
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 10 deletions.
27 changes: 17 additions & 10 deletions motleycrew/agents/crewai/agent_with_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
""" Module description """
from typing import Any, Optional, List

from langchain_core.runnables import RunnableConfig
Expand All @@ -12,12 +13,17 @@


class CrewAIAgentWithConfig(Agent):
"""
Subclass for CrewAI Agent that overrides the execute_task method to include a config parameter.
TODO: get rid of this when https://github.com/joaomdmoura/crewAI/pull/483 is merged.
"""


def __init__(self, *args, **kwargs):
"""Subclass for CrewAI Agent that overrides the execute_task method to include a config parameter.
Args:
*args:
**kwargs:
Todo:
* get rid of this when https://github.com/joaomdmoura/crewAI/pull/483 is merged.
"""
ensure_module_is_installed("crewai")
super(CrewAIAgentWithConfig, self).__init__(*args, **kwargs)

Expand All @@ -31,12 +37,13 @@ def execute_task(
"""Execute a task with the agent.
Args:
task: Task to execute.
context: Context to execute the task in.
tools: Tools to use for the task.
config: Runnable config
task (Any): Task to execute.
context (:obj:'str', optional): Context to execute the task in.
tools: (:obj:'List[Any]', optional): Tools to use for the task.
config (:obj:'RunnableConfig', optional): Runnable config.
Returns:
Output of the agent
Any: Output of the agent
"""
task_prompt = task.prompt()

Expand Down
46 changes: 46 additions & 0 deletions motleycrew/agents/crewai/crewai.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
""" Module description """
from typing import Any, Optional, Sequence

from langchain_core.runnables import RunnableConfig
Expand Down Expand Up @@ -26,6 +27,15 @@ def __init__(
tools: Sequence[MotleySupportedTool] | None = None,
verbose: bool = False,
):
""" Description
Args:
goal (str):
name (:obj:'str', optional):
agent_factory (:obj:'MotleyAgentFactory', optional):
tools (:obj:'Sequence[MotleySupportedTool]', optional:
verbose (bool):
"""
ensure_module_is_installed("crewai")
super().__init__(
description=goal,
Expand All @@ -41,6 +51,16 @@ def invoke(
config: Optional[RunnableConfig] = None,
**kwargs: Any,
) -> Any:
""" Description
Args:
task_dict (dict):
config (:obj:'RunnableConfig', optional):
**kwargs:
Returns:
Any:
"""
self.materialize()

prompt = task_dict.get("prompt")
Expand All @@ -59,9 +79,25 @@ def invoke(

# TODO: what do these do?
def set_cache_handler(self, cache_handler: Any) -> None:
""" Description
Args:
cache_handler (Any):
Returns:
None:
"""
return self.agent.set_cache_handler(cache_handler)

def set_rpm_controller(self, rpm_controller: Any) -> None:
""" Description
Args:
rpm_controller (Any):
Returns:
None:
"""
return self.agent.set_rpm_controller(rpm_controller)

@staticmethod
Expand All @@ -70,6 +106,16 @@ def from_agent(
tools: Sequence[MotleySupportedTool] | None = None,
verbose: bool = False,
) -> "CrewAIMotleyAgentParent":
""" Description
Args:
agent (CrewAIAgentWithConfig):
tools (:obj:'Sequence[MotleySupportedTool]', optional):
verbose (bool):
Returns:
CrewAIMotleyAgentParent:
"""
if tools or agent.tools:
tools = list(tools or []) + list(agent.tools or [])

Expand Down
12 changes: 12 additions & 0 deletions motleycrew/agents/crewai/crewai_agent.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
""" Module description """
from typing import Optional, Any, Sequence

from motleycrew.tools import MotleyTool
Expand All @@ -20,6 +21,17 @@ def __init__(
llm: Optional[Any] = None,
verbose: bool = False,
):
""" Description
Args:
role (str):
goal (str):
backstory (str):
delegation (bool):
tools (:obj:'Sequence[MotleySupportedTool]', optional):
llm (:obj:'Any', optional):
verbose (bool):
"""
if tools is None:
tools = []

Expand Down

0 comments on commit ef25016

Please sign in to comment.