From 308a8dc925ecc719c5f3fabaa05b301b0e600a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Salda=C3=B1a?= Date: Tue, 3 Dec 2024 10:09:30 -0500 Subject: [PATCH 1/3] Update reset memories command based on the SDK (#1688) Co-authored-by: Brandon Hancock (bhancock_ai) <109994880+bhancockio@users.noreply.github.com> --- docs/quickstart.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/quickstart.mdx b/docs/quickstart.mdx index a78a56182..9ec3170e1 100644 --- a/docs/quickstart.mdx +++ b/docs/quickstart.mdx @@ -349,7 +349,7 @@ Replace `` with the ID of the task you want to replay. If you need to reset the memory of your crew before running it again, you can do so by calling the reset memory feature: ```shell -crewai reset-memory +crewai reset-memories --all ``` This will clear the crew's memory, allowing for a fresh start. From 9e9b945a4662e6cea9f6ca621cac3224a3119622 Mon Sep 17 00:00:00 2001 From: Ola Hungerford Date: Tue, 3 Dec 2024 08:13:06 -0800 Subject: [PATCH 2/3] Update using langchain tools docs (#1664) * Update example of how to use LangChain tools with correct syntax * Use .env * Add Code back --------- Co-authored-by: Brandon Hancock (bhancock_ai) <109994880+bhancockio@users.noreply.github.com> --- docs/concepts/langchain-tools.mdx | 53 +++++++++++++++++++------------ 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/docs/concepts/langchain-tools.mdx b/docs/concepts/langchain-tools.mdx index 538581aee..68a7998a9 100644 --- a/docs/concepts/langchain-tools.mdx +++ b/docs/concepts/langchain-tools.mdx @@ -7,32 +7,45 @@ icon: link ## Using LangChain Tools - CrewAI seamlessly integrates with LangChain’s comprehensive [list of tools](https://python.langchain.com/docs/integrations/tools/), all of which can be used with CrewAI. + CrewAI seamlessly integrates with LangChain's comprehensive [list of tools](https://python.langchain.com/docs/integrations/tools/), all of which can be used with CrewAI. ```python Code import os -from crewai import Agent -from langchain.agents import Tool -from langchain.utilities import GoogleSerperAPIWrapper +from dotenv import load_dotenv +from crewai import Agent, Task, Crew +from crewai.tools import BaseTool +from pydantic import Field +from langchain_community.utilities import GoogleSerperAPIWrapper -# Setup API keys -os.environ["SERPER_API_KEY"] = "Your Key" +# Set up your SERPER_API_KEY key in an .env file, eg: +# SERPER_API_KEY= +load_dotenv() search = GoogleSerperAPIWrapper() -# Create and assign the search tool to an agent -serper_tool = Tool( - name="Intermediate Answer", - func=search.run, - description="Useful for search-based queries", -) +class SearchTool(BaseTool): + name: str = "Search" + description: str = "Useful for search-based queries. Use this to find current information about markets, companies, and trends." + search: GoogleSerperAPIWrapper = Field(default_factory=GoogleSerperAPIWrapper) -agent = Agent( - role='Research Analyst', - goal='Provide up-to-date market analysis', - backstory='An expert analyst with a keen eye for market trends.', - tools=[serper_tool] + def _run(self, query: str) -> str: + """Execute the search query and return results""" + try: + return self.search.run(query) + except Exception as e: + return f"Error performing search: {str(e)}" + +# Create Agents +researcher = Agent( + role='Research Analyst', + goal='Gather current market data and trends', + backstory="""You are an expert research analyst with years of experience in + gathering market intelligence. You're known for your ability to find + relevant and up-to-date market information and present it in a clear, + actionable format.""", + tools=[SearchTool()], + verbose=True ) # rest of the code ... @@ -40,6 +53,6 @@ agent = Agent( ## Conclusion -Tools are pivotal in extending the capabilities of CrewAI agents, enabling them to undertake a broad spectrum of tasks and collaborate effectively. -When building solutions with CrewAI, leverage both custom and existing tools to empower your agents and enhance the AI ecosystem. Consider utilizing error handling, caching mechanisms, -and the flexibility of tool arguments to optimize your agents' performance and capabilities. \ No newline at end of file +Tools are pivotal in extending the capabilities of CrewAI agents, enabling them to undertake a broad spectrum of tasks and collaborate effectively. +When building solutions with CrewAI, leverage both custom and existing tools to empower your agents and enhance the AI ecosystem. Consider utilizing error handling, caching mechanisms, +and the flexibility of tool arguments to optimize your agents' performance and capabilities. From aaf80d1d43a02a9b135743b3e67c2d4cccd16d23 Mon Sep 17 00:00:00 2001 From: "Tom Mahler, PhD" Date: Tue, 3 Dec 2024 19:22:29 +0200 Subject: [PATCH 3/3] [FEATURE] Support for custom path in RAGStorage (#1659) * added path to RAGStorage * added path to short term and entity memory * add path for long_term_storage for completeness --------- Co-authored-by: Brandon Hancock (bhancock_ai) <109994880+bhancockio@users.noreply.github.com> --- src/crewai/memory/entity/entity_memory.py | 3 ++- src/crewai/memory/long_term/long_term_memory.py | 5 +++-- src/crewai/memory/short_term/short_term_memory.py | 4 ++-- src/crewai/memory/storage/rag_storage.py | 5 +++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/crewai/memory/entity/entity_memory.py b/src/crewai/memory/entity/entity_memory.py index 88d33c09a..67c72e927 100644 --- a/src/crewai/memory/entity/entity_memory.py +++ b/src/crewai/memory/entity/entity_memory.py @@ -10,7 +10,7 @@ class EntityMemory(Memory): Inherits from the Memory class. """ - def __init__(self, crew=None, embedder_config=None, storage=None): + def __init__(self, crew=None, embedder_config=None, storage=None, path=None): if hasattr(crew, "memory_config") and crew.memory_config is not None: self.memory_provider = crew.memory_config.get("provider") else: @@ -33,6 +33,7 @@ class EntityMemory(Memory): allow_reset=True, embedder_config=embedder_config, crew=crew, + path=path, ) ) super().__init__(storage) diff --git a/src/crewai/memory/long_term/long_term_memory.py b/src/crewai/memory/long_term/long_term_memory.py index b9c36bdc9..656709ac9 100644 --- a/src/crewai/memory/long_term/long_term_memory.py +++ b/src/crewai/memory/long_term/long_term_memory.py @@ -14,8 +14,9 @@ class LongTermMemory(Memory): LongTermMemoryItem instances. """ - def __init__(self, storage=None): - storage = storage if storage else LTMSQLiteStorage() + def __init__(self, storage=None, path=None): + if not storage: + storage = LTMSQLiteStorage(db_path=path) if path else LTMSQLiteStorage() super().__init__(storage) def save(self, item: LongTermMemoryItem) -> None: # type: ignore # BUG?: Signature of "save" incompatible with supertype "Memory" diff --git a/src/crewai/memory/short_term/short_term_memory.py b/src/crewai/memory/short_term/short_term_memory.py index 67a568d63..4ade7eb93 100644 --- a/src/crewai/memory/short_term/short_term_memory.py +++ b/src/crewai/memory/short_term/short_term_memory.py @@ -13,7 +13,7 @@ class ShortTermMemory(Memory): MemoryItem instances. """ - def __init__(self, crew=None, embedder_config=None, storage=None): + def __init__(self, crew=None, embedder_config=None, storage=None, path=None): if hasattr(crew, "memory_config") and crew.memory_config is not None: self.memory_provider = crew.memory_config.get("provider") else: @@ -32,7 +32,7 @@ class ShortTermMemory(Memory): storage if storage else RAGStorage( - type="short_term", embedder_config=embedder_config, crew=crew + type="short_term", embedder_config=embedder_config, crew=crew, path=path ) ) super().__init__(storage) diff --git a/src/crewai/memory/storage/rag_storage.py b/src/crewai/memory/storage/rag_storage.py index 4023cf558..ded340a19 100644 --- a/src/crewai/memory/storage/rag_storage.py +++ b/src/crewai/memory/storage/rag_storage.py @@ -37,7 +37,7 @@ class RAGStorage(BaseRAGStorage): app: ClientAPI | None = None - def __init__(self, type, allow_reset=True, embedder_config=None, crew=None): + def __init__(self, type, allow_reset=True, embedder_config=None, crew=None, path=None): super().__init__(type, allow_reset, embedder_config, crew) agents = crew.agents if crew else [] agents = [self._sanitize_role(agent.role) for agent in agents] @@ -47,6 +47,7 @@ class RAGStorage(BaseRAGStorage): self.type = type self.allow_reset = allow_reset + self.path = path self._initialize_app() def _set_embedder_config(self): @@ -59,7 +60,7 @@ class RAGStorage(BaseRAGStorage): self._set_embedder_config() chroma_client = chromadb.PersistentClient( - path=f"{db_storage_path()}/{self.type}/{self.agents}", + path=self.path if self.path else f"{db_storage_path()}/{self.type}/{self.agents}", settings=Settings(allow_reset=self.allow_reset), )