Merge branch 'main' of github.com:crewAIInc/crewAI into knowledge

This commit is contained in:
Lorenze Jay
2024-11-18 13:55:32 -08:00
20 changed files with 2632 additions and 17 deletions

View File

@@ -16,7 +16,7 @@ warnings.filterwarnings(
category=UserWarning,
module="pydantic.main",
)
__version__ = "0.79.4"
__version__ = "0.80.0"
__all__ = [
"Agent",
"Crew",

View File

@@ -5,7 +5,7 @@ description = "{{name}} using crewAI"
authors = [{ name = "Your Name", email = "you@example.com" }]
requires-python = ">=3.10,<=3.13"
dependencies = [
"crewai[tools]>=0.79.4,<1.0.0"
"crewai[tools]>=0.80.0,<1.0.0"
]
[project.scripts]

View File

@@ -5,7 +5,7 @@ description = "{{name}} using crewAI"
authors = [{ name = "Your Name", email = "you@example.com" }]
requires-python = ">=3.10,<=3.13"
dependencies = [
"crewai[tools]>=0.79.4,<1.0.0",
"crewai[tools]>=0.80.0,<1.0.0",
]
[project.scripts]

View File

@@ -6,7 +6,7 @@ authors = ["Your Name <you@example.com>"]
[tool.poetry.dependencies]
python = ">=3.10,<=3.13"
crewai = { extras = ["tools"], version = ">=0.79.4,<1.0.0" }
crewai = { extras = ["tools"], version = ">=0.80.0,<1.0.0" }
asyncio = "*"
[tool.poetry.scripts]

View File

@@ -5,7 +5,7 @@ description = "{{name}} using crewAI"
authors = ["Your Name <you@example.com>"]
requires-python = ">=3.10,<=3.13"
dependencies = [
"crewai[tools]>=0.79.4,<1.0.0"
"crewai[tools]>=0.80.0,<1.0.0"
]
[project.scripts]

View File

@@ -5,6 +5,6 @@ description = "Power up your crews with {{folder_name}}"
readme = "README.md"
requires-python = ">=3.10,<=3.13"
dependencies = [
"crewai[tools]>=0.79.4"
"crewai[tools]>=0.80.0"
]

View File

@@ -9,6 +9,8 @@ from .annotations import (
pipeline,
task,
tool,
before_crew,
after_crew,
)
from .crew_base import CrewBase
from .pipeline_base import PipelineBase
@@ -26,4 +28,6 @@ __all__ = [
"llm",
"cache_handler",
"pipeline",
"before_crew",
"after_crew",
]

View File

@@ -5,6 +5,16 @@ from crewai import Crew
from crewai.project.utils import memoize
def before_crew(func):
func.is_before_crew = True
return func
def after_crew(func):
func.is_after_crew = True
return func
def task(func):
func.is_task = True

View File

@@ -34,18 +34,39 @@ def CrewBase(cls: T) -> T:
self.map_all_agent_variables()
self.map_all_task_variables()
# Preserve task and agent information
self._original_tasks = {
# Preserve all decorated functions
self._original_functions = {
name: method
for name, method in cls.__dict__.items()
if hasattr(method, "is_task") and method.is_task
}
self._original_agents = {
name: method
for name, method in cls.__dict__.items()
if hasattr(method, "is_agent") and method.is_agent
if any(
hasattr(method, attr)
for attr in [
"is_task",
"is_agent",
"is_before_crew",
"is_after_crew",
"is_kickoff",
]
)
}
# Store specific function types
self._original_tasks = self._filter_functions(
self._original_functions, "is_task"
)
self._original_agents = self._filter_functions(
self._original_functions, "is_agent"
)
self._before_crew = self._filter_functions(
self._original_functions, "is_before_crew"
)
self._after_crew = self._filter_functions(
self._original_functions, "is_after_crew"
)
self._kickoff = self._filter_functions(
self._original_functions, "is_kickoff"
)
@staticmethod
def load_yaml(config_path: Path):
try:
@@ -192,4 +213,25 @@ def CrewBase(cls: T) -> T:
callback_functions[callback]() for callback in callbacks
]
def kickoff(self, inputs=None):
# Execute before_crew functions and allow them to modify inputs
for _, func in self._before_crew.items():
modified_inputs = func(self, inputs)
if modified_inputs is not None:
inputs = modified_inputs
# Get the crew instance
crew_instance = self.crew()
# Execute the crew's tasks
result = crew_instance.kickoff(inputs=inputs)
# Execute after_crew functions and allow them to modify the output
for _, func in self._after_crew.items():
modified_result = func(self, result)
if modified_result is not None:
result = modified_result
return result
return cast(T, WrappedClass)