CrewAI Knowledge (original) (raw)

Last Updated : 14 Apr, 2026

Knowledge in CrewAI enables agents to reference explicit facts when performing tasks. Knowledge sources provide structured or unstructured information, allowing agents to answer questions accurately, provide support, and generate content based on real-world data. This helps tailor agents to specific domains, ensuring reliability and context-aware interactions.

Exploring Available Knowledge Sources

CrewAI supports multiple knowledge sources to supply agents with factual information from different formats. To explore all available sources and their documentation, the help() function can be used.

Python `

import crewai help(crewai.knowledge.source)

`

**Output:

crewai_knowledge

Available Knowledge Sources

Understanding Knowledge Sources

CrewAI offers multiple knowledge sources to feed information to agents. Each is suited for different types of data and use cases.

1. base_file_knowledge_source

Base class for knowledge sources that read from files. It provides a foundation for other file-based sources.

file_source = BaseFileKnowledgeSource( file_path="sample_data.txt", chunk_size=2000, split_method="sentence" )

`

**Note: We will demonstrate a full example implementation towards the end of the article.

2. base_knowledge_source

Generic base class for creating custom knowledge sources. Useful when building specialized sources.

custom_source = BaseKnowledgeSource( name="custom_source", verbose=True )

`

3. crew_docling_source

Integrates knowledge from Crew’s internal Docling system. Ideal for agents that reuse Crew documentation.

docling_source = CrewDoclingSource( doc_id="doc_12345", verbose=True )

`

4. csv_knowledge_source

Loads knowledge from CSV files making it suitable for tabular data.

csv_source = CSVKnowledgeSource( file_path="Sample_data.csv", delimiter=",", encoding="utf-8", verbose=True )

`

5. excel_knowledge_source

Loads knowledge from Excel spreadsheets, supporting structured business or research data.

excel_source = ExcelKnowledgeSource( file_path="sample_data.xlsx", sheet_name="Sheet1", encoding="utf-8", verbose=True )

`

6. json_knowledge_source

Loads knowledge from JSON files, ideal for hierarchical or structured data.

json_source = JSONKnowledgeSource( file_path="sample_data.json", encoding="utf-8", verbose=True )

`

7. pdf_knowledge_source

Loads knowledge from PDF documents. Suitable for reports, manuals and research papers.

pdf_source = PDFKnowledgeSource( file_paths=["sample_data.pdf"], chunk_size=4000, chunk_overlap=200 )

`

8. string_knowledge_source

Loads knowledge from a string of text. Useful for small snippets or predefined facts.

string_source = StringKnowledgeSource( content="Our product, the XPS 13, has a storage capacity of 512GB SSD.", verbose=True )

`

9. text_file_knowledge_source

Loads knowledge from plain text files. Ideal for notes, documentation or FAQs in text format.

text_source = TextFileKnowledgeSource( file_path="sample_data.txt", encoding="utf-8", verbose=True )

`

These knowledge sources allow you to feed structured or unstructured information from multiple formats, making your agents capable of handling multiple domains effectively.

Creating an Agent with StringKnowledgeSource

We will be implementing a CrewAI agent that can answer questions about a product using a string knowledge source.

from crewai import Agent, Task, Crew from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource

import os os.environ['OPENAI_API_KEY'] = "Your_API_Key"

content = "Our product, the XPS 13, has a storage capacity of 512GB SSD." string_source = StringKnowledgeSource(content=content)

support_agent = Agent( role="Technical Support Specialist", goal="Provide accurate product information and support.", backstory="You are a good support specialist", knowledge_sources=[string_source] )

support_task = Task( description="Answer the customer's question about product specifications.", expected_output="A clear answer to the customer's query based on the knowledge source.", agent=support_agent )

crew = Crew( agents=[support_agent], tasks=[support_task] )

result = crew.kickoff(inputs={"question": "What is the storage capacity of the XPS 13?"}) print(result)

`

**Output:

"Our product, the XPS 13, has a storage capacity of 512GB SSD."