I ran the demo of “knowledge” from official website and could not get the expected output.
Virtual environment info:
requires-python = “>=3.12”
dependencies = [
“crewai==0.121.0”,
“crewai-tools>=0.45.0”,
“python-dotenv>=1.1.0”,
]
Here is the code I’m using:
from crewai import Agent, Task, Crew, Process, LLM
from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource
content = "Users name is John. He is 30 years old and lives in San Francisco."
string_source = StringKnowledgeSource(content=content)
llm = LLM(model="gpt-4o-mini", temperature=0)
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_sources=[string_source], # Enable knowledge by adding the sources here
)
result = crew.kickoff(inputs={"question": "What city does John live in and how old is he?"})
print(result.raw)
The Output is → John lives in an unspecified city, and his age is not provided in the information available.