Knowledge grounds agents in your own documents, which reduces made-up answers.
Knowledge is reference material agents can search while they work, such as a company handbook, product specs or FAQs. It is CrewAI's built-in RAG: files are split into chunks, embedded, stored in a vector store, and the most relevant chunks are added to the agent's prompt.
Knowledge differs from memory. Knowledge is material you provide up front. Memory is what the crew learns and saves during runs.
Source classes live under crewai.knowledge.source:
StringKnowledgeSource(content="...")for text in code.TextFileKnowledgeSource,PDFKnowledgeSource,CSVKnowledgeSource,ExcelKnowledgeSource,JSONKnowledgeSourcefor files.CrewDoclingSource(needs thedoclingextra) for many document types and web URLs.
File paths are relative to a knowledge/ folder at the project root, so file_paths=["policies.pdf"] means knowledge/policies.pdf.
Attach sources at two levels:
- On a crew (
knowledge_sources=[...]): every agent can use them. - On an agent: only that agent uses them, which keeps prompts smaller and focused.
Embeddings default to an OpenAI model, even if your agents use another provider. Set embedder={"provider": "ollama", "config": {...}} (or another provider) on the crew or agent to change it.
When files change, clear the stored chunks with crewai reset-memories --knowledge so stale text is not retrieved. For large or frequently updated document collections, a dedicated RAG tool or vector database usually scales better than built-in knowledge.
Example
from crewai import Agent, Crew, Task
from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource
from crewai.knowledge.source.text_file_knowledge_source import TextFileKnowledgeSource
policies = TextFileKnowledgeSource(file_paths=["refund_policy.txt"]) # knowledge/refund_policy.txt
facts = StringKnowledgeSource(content="Support hours: Mon-Fri, 9:00-17:00 CET.")
support = Agent(
role="Support agent",
goal="Answer customer questions using company policy only",
backstory="You quote the policy and never invent rules.",
knowledge_sources=[facts], # this agent only
)
task = Task(description="Answer: {question}", expected_output="A short, polite answer.",
agent=support)
crew = Crew(agents=[support], tasks=[task],
knowledge_sources=[policies], # shared by all agents
embedder={"provider": "openai", "config": {"model": "text-embedding-3-small"}})
print(crew.kickoff(inputs={"question": "Can I return an opened item after 20 days?"}).raw)Remember
- Knowledge = your reference documents, retrieved by RAG at run time
- Crew-level sources serve all agents; agent-level sources serve one
- Files live under
knowledge/; reset stored chunks after files change
Watch out for
- Updating a policy file but not resetting knowledge storage, so agents keep quoting the old version.