From 33dfcc700beaf1dfdb4fa8852f1e8d611a198015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Tue, 2 Apr 2024 14:26:22 -0300 Subject: [PATCH] cutting new version, adding cache_function docs --- docs/core-concepts/Tools.md | 36 ++++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/docs/core-concepts/Tools.md b/docs/core-concepts/Tools.md index 7060c5b0d0..3909f1279e 100644 --- a/docs/core-concepts/Tools.md +++ b/docs/core-concepts/Tools.md @@ -195,6 +195,42 @@ agent = Agent( ) ``` +### Custom Caching Mechanism +Tools now can have an optinal attribute called `cache_function`, this cache function +can be use to fine control when to cache and when not to cache a tool retuls. +Good example my be a tool responsible for getting values from securities where +you are okay to cache treasury value but not stock values. + +```python +from crewai_tools import tool + + @tool + def multiplcation_tool(first_number: int, second_number: int) -> str: + """Useful for when you need to multiply two numbers together.""" + return first_number * second_number + + def cache_func(args, result): + # The cache function will receive: + # - arguments passed to the tool + # - the result of the tool + # + # In this case we only cache the resutl if it's multiple of 2 + cache = result % 2 == 0 + return cache + + multiplcation_tool.cache_function = cache_func + + + writer1 = Agent( + role="Writer", + goal="You write lesssons of math for kids.", + backstory="You're an expert in writting and you love to teach kids but you know nothing of math.", + tools=[multiplcation_tool], + allow_delegation=False, + ) + #... +``` + ## Using LangChain Tools !!! info "LangChain Integration" CrewAI seamlessly integrates with LangChain’s comprehensive toolkit for search-based queries and more, here are the available built-in tools that are offered by Langchain [LangChain Toolkit](https://python.langchain.com/docs/integrations/tools/) diff --git a/pyproject.toml b/pyproject.toml index 68da12e918..5d75a69d06 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "crewai" -version = "0.27.0rc0" +version = "0.27.0rc1" description = "Cutting-edge framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks." authors = ["Joao Moura "] readme = "README.md"