cutting new version, adding cache_function docs

This commit is contained in:
João Moura
2024-04-02 14:26:22 -03:00
parent 09c8193c8f
commit 33dfcc700b
2 changed files with 37 additions and 1 deletions

View File

@@ -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 LangChains 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/)

View File

@@ -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 <joao@crewai.com>"]
readme = "README.md"