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. 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. 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 4a0e3f8dd..4dcdb6e42 100644 --- a/src/crewai/memory/storage/rag_storage.py +++ b/src/crewai/memory/storage/rag_storage.py @@ -38,7 +38,9 @@ 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] @@ -49,6 +51,7 @@ class RAGStorage(BaseRAGStorage): self.type = type self.allow_reset = allow_reset + self.path = path self._initialize_app() def _set_embedder_config(self): @@ -61,7 +64,7 @@ class RAGStorage(BaseRAGStorage): self._set_embedder_config() chroma_client = chromadb.PersistentClient( - path=self.storage_file_name, + path=self.path if self.path else self.storage_file_name, settings=Settings(allow_reset=self.allow_reset), )