adding meomization to crewai project annotations

This commit is contained in:
João Moura
2024-05-03 00:49:25 -03:00
parent 2edc88e0a1
commit b264ebabc0
2 changed files with 49 additions and 0 deletions

View File

@@ -1,14 +1,28 @@
tasks_order = []
def memoize(func):
cache = {}
def memoized_func(*args, **kwargs):
key = (args, tuple(kwargs.items()))
if key not in cache:
cache[key] = func(*args, **kwargs)
return cache[key]
return memoized_func
def task(func):
func.is_task = True
tasks_order.append(func.__name__)
func = memoize(func)
return func
def agent(func):
func.is_agent = True
func = memoize(func)
return func