crewAIInc / crewAIInc/crewAI

[BUG] Crew silently continues when knowledge_sources fail to initialize (missing OPENAI_API_KEY)

Open
#7,415 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
58.8k
Forks
8.5k
Avg merge
1d 15h
Merged PRs (30d)
109

Description

Description

When a Crew is constructed with explicit knowledge_sources, knowledge initialization can fail (for example missing OPENAI_API_KEY for the default Chroma OpenAI embedder). The failure is logged, but create_crew_knowledge catches the exception and the crew continues as if knowledge were configured.

Result: kickoff “succeeds” with empty knowledge, and agents answer without retrieval. Easy to miss in non-verbose runs.

Also: ChromaDBConfig._default_embedding_function docstring says the default is all-MiniLM-L6-v2 via ONNX, but the implementation uses OpenAIEmbeddingFunction / text-embedding-3-small (docs elsewhere correctly say OpenAI is the default).

Steps to Reproduce
from crewai import Agent, Crew, Task, Process
from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource
from crewai.llms.base_llm import BaseLLM

class StubLLM(BaseLLM):
    def call(self, messages, tools=None, callbacks=None, available_functions=None,
             from_task=None, from_agent=None, response_model=None):
        return "Thought: ok.\nFinal Answer: invented answer without retrieval."
    def supports_function_calling(self) -> bool:
        return False

# Ensure OPENAI_API_KEY is unset
knowledge = StringKnowledgeSource(content="Secret fact: the vault code is 42.")
agent = Agent(role="r", goal="g", backstory="b", llm=StubLLM(model="stub"), verbose=False)
task = Task(description="What is the vault code?", expected_output="the code", agent=agent)
crew = Crew(
    agents=[agent],
    tasks=[task],
    knowledge_sources=[knowledge],
    process=Process.sequential,
    verbose=False,
)
result = crew.kickoff()
print(result)  # completes; knowledge never loaded
Expected behavior

If the user explicitly provided knowledge_sources and initialization/upsert fails, Crew construction or kickoff should fail loudly (raise) so the misconfiguration is obvious. Optionally fix the misleading ONNX docstring on _default_embedding_function.

Actual behavior

Errors like Failed to upsert documents: The OPENAI_API_KEY environment variable is not set. are logged, then create_crew_knowledge swallows the exception and the crew runs without knowledge.

Operating System

macOS

Python Version

3.13

crewAI Version

1.15.21 / current main

Willingness to Contribute

Yes — I can open a PR that re-raises on explicit knowledge_sources init failure + corrects the Chroma default-embedder docstring, with a regression test.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with create_crew_knowledge and trace how explicit knowledge_sources initialization and upsert exceptions are handled, then inspect ChromaDBConfig._default_embedding_function and its misleading docstring. Use the provided missing-OPENAI_API_KEY reproduction to add a regression test; done means explicit knowledge initialization failure raises instead of allowing kickoff to continue without retrieval, and the docstring matches the implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.