From 23276cbd76df264e3758a93cefc88c039b407a53 Mon Sep 17 00:00:00 2001 From: Lorenze Jay Date: Tue, 19 Nov 2024 18:31:09 -0800 Subject: [PATCH] adding docs --- docs/concepts/knowledge.mdx | 91 +++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 docs/concepts/knowledge.mdx diff --git a/docs/concepts/knowledge.mdx b/docs/concepts/knowledge.mdx new file mode 100644 index 000000000..1acd006ca --- /dev/null +++ b/docs/concepts/knowledge.mdx @@ -0,0 +1,91 @@ +--- +title: Knowledge +description: What is knowledge in CrewAI and how to use it. +icon: book +--- + +# Using Knowledge in CrewAI + +## Introduction + +The Knowledge class in CrewAI provides a powerful way to manage and query knowledge sources for your AI agents. This guide will show you how to implement knowledge management in your CrewAI projects. +Additionally, we have specific tools for generate knowledge sources for strings, text files, PDF's, and Spreadsheets. You can expand on any source type by extending the `KnowledgeSource` class. + +## Basic Implementation + +Here's a simple example of how to use the Knowledge class: + +```python +from crewai import Agent, Task, Crew, Knowledge, Process, LLM +from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource + +# Create a knowledge source +content = "Users name is John. He is 30 years old and lives in San Francisco." +string_source = StringKnowledgeSource( + content=content, metadata={"preference": "personal"} +) + +# Create a knowledge store with a list of sources and metadata +knowledge = Knowledge(sources=[string_source], metadata={"preference": "personal"}) +llm = LLM(model="gpt-4o-mini", temperature=0) + # Create an agent with the knowledge store +agent = Agent( + role="About User", + goal="You know everything about the user.", + backstory="""You are a master at understanding people and their preferences.""", + verbose=True, + allow_delegation=False, + llm=llm, +) +task = Task( + description="Answer the following questions about the user: {question}", + expected_output="An answer to the question.", + agent=agent, +) + +crew = Crew( + agents=[agent], + tasks=[task], + verbose=True, + process=Process.sequential, + knowledge=True, # Enable knowledge +) + +result = crew.kickoff(inputs={"question": "What city does John live in and how old is he?"}) +``` + +## Additionally: +You can add more sources as well as not need to re-declare the knowledge store every kickoff. +If you had sources from previous runs, you no longer need to declare the knowledge store. + +```python +from crewai import Agent, Task, Crew, Process, LLM +from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource + +# Create a knowledge store with a list of sources and metadata +llm = LLM(model="gpt-4o-mini", temperature=0) + # Create an agent with the knowledge store +agent = Agent( + role="About User", + goal="You know everything about the user.", + backstory="""You are a master at understanding people and their preferences.""", + verbose=True, + allow_delegation=False, + llm=llm, +) +task = Task( + description="Answer the following questions about the user: {question}", + expected_output="An answer to the question.", + agent=agent, +) + +crew = Crew( + agents=[agent], + tasks=[task], + verbose=True, + process=Process.sequential, + knowledge=True, # Enable knowledge +) + +result = crew.kickoff(inputs={"question": "What city does John live in and how old is he?"}) +```