Skip to content

[BUG] Knowledge doesn't read from the knowledge source using StringSource #2315

Closed
@chadsly

Description

@chadsly

Description

I've attempted running the example "knowledge" code that is in the docs: https://docs.crewai.com/concepts/knowledge
The first example uses the StringSource. Maybe after I can get this one to work, I'll move on to more complicated options.
I used the code as is (except changing the llm) and run it as a simple python script. I've also rewritten it to run it as a crewai input.

Steps to Reproduce

  1. With the python code below, simply run python3 main.py

Expected behavior

  1. I expected the output of the question to give the information about the user ("John") that corresponded to the knowledge source. In this case, it should have told me that John was 30 and living in San Fransisco.

Screenshots/Code snippets

from crewai import Agent, Task, Crew, 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,
)

Create an LLM with a temperature of 0 to ensure deterministic outputs

llm = LLM(model="gpt-4o-mini", temperature=0)

llm=LLM(model="ollama/llama3.2:1b", base_url="http://localhost:11434")

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_sources=[string_source], # Enable knowledge by adding the sources here. You can also add more sources to the sources list.
)

result = crew.kickoff(inputs={"question": "What city does John Albertson live in and how old is he?"})

Operating System

Ubuntu 20.04

Python Version

3.10

crewAI Version

0.98.0

crewAI Tools Version

Virtual Environment

Venv

Evidence

The answer told me that John lived in New York City and was 38 years old. In other words, it didn't use the knowledge at all.

Possible Solution

None

Additional context

  1. I didn't include the larger crewai CLI example because it seemed to have the same incorrect information. It's just not reading the knowledge source.
  2. In case you didn't notice in the code, I'm using ollama with a local model.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions