crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] memory=True causes embedding model token limit error with large input in CrewAI

Open Kevv-J opened this issue 9 months ago โ€ข 4 comments

Description

When enabling memory (memory=True) in CrewAI and running it with a large input, the system crashes with a token limit error from the embedding model. This seems to stem from a failure to chunk or truncate large inputs before passing them to the embedding model, leading to prompt sizes far exceeding the model's context window (e.g., 30k+ tokens vs. an 8k token limit).

Steps to Reproduce

Steps to Reproduce

  1. Initialize CrewAI with memory=True
  2. Provide a large input (e.g., a long text file or extended conversation history)
  3. Run the agent/task
  4. Observe the error during memory search

Expected behavior

The input should be automatically truncated, chunked, or summarized to ensure that it fits within the modelโ€™s maximum context length (e.g., 8192 tokens). Memory operations should be handled gracefully, even for large inputs.

Screenshots/Code snippets

Image

Operating System

Ubuntu 20.04

Python Version

3.11

crewAI Version

0.118.0

crewAI Tools Version

0.43.0

Virtual Environment

Venv

Evidence

  1. Error occurs only when memory=True
  2. Error is triggered when large content (e.g., >20,000 tokens) is processed
  3. Disabling memory or reducing input size avoids the error

Possible Solution

  1. Implement automatic chunking, summarization, or truncation logic before passing content to the embedding model
  2. Add pre-checks or warnings for token length when memory is enabled
  3. Allow user configuration of max tokens to align with the model in use

Additional context

Model in use: Azure OpenAI text-embedding-3-small model with 8k token limit

Kevv-J avatar May 05 '25 08:05 Kevv-J

for context I am providing Embedder in Crew as such embedder={ "provider": "azure", "config": { "api_key": AZURE_OPENAI_EMBEDDINGS_API_KEY, "api_base": AZURE_OPENAI_EMBEDDINGS_ENDPOINT, "api_version": AZURE_OPENAI_EMBEDDINGS_API_VERSION, "model_name": AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT, "deployment_id": AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT, }, }

Kevv-J avatar May 05 '25 08:05 Kevv-J

I think this has been fixed in one of the recent PR's.

Vidit-Ostwal avatar May 05 '25 10:05 Vidit-Ostwal

Can you try to install the latest main branch pip install git+https://github.com/crewAIInc/crewAI.git@main

Vidit-Ostwal avatar May 05 '25 10:05 Vidit-Ostwal

@Kevv-J thanks for reporting! Some clarification questions:

  1. Are you using any Tool?
  2. Does the long file text is a plain/text file or some binary data?

lucasgomide avatar May 05 '25 13:05 lucasgomide

Hi @Vidit-Ostwal I'll try it out and let you know

@lucasgomide Yes I am using FileReadTool and some CustomTools I have written. The text is large plain text which equates to around 45k tokens but the text-embedding-small only supports 8k tokens

Kevv-J avatar May 09 '25 10:05 Kevv-J

Whats the embedding model that you are using ?

lorenzejay avatar May 13 '25 22:05 lorenzejay

Hi I've installed the latest version on a brand new virtual environment with Python 3.11: crewai==0.119.0 crewai-tools==0.44.0

I seem to encounter a new issue when using memory with AzureOpenAI

Image

Here is a code sample to reproduce the same issue

from crewai import Agent, Task, Crew, LLM

from pydantic import BaseModel, Field

from crewai_tools import ScrapeWebsiteTool


AZURE_OPENAI_ENDPOINT_NEW = ""  # Add your own endpoint
AZURE_OPENAI_API_VERSION_NEW = "2025-01-01-preview"
AZURE_OPENAI_DEPLOYMENT_NEW = "gpt-4.1"
AZURE_OPENAI_API_KEY_NEW = ""  # Add your own key

AZURE_OPENAI_EMBEDDINGS_ENDPOINT = ""  # Add your own endpoint
AZURE_OPENAI_EMBEDDINGS_API_VERSION = "2023-05-15"
AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT = "text-embedding-3-small"
AZURE_OPENAI_EMBEDDINGS_API_KEY = ""  # Add your own key

llm = LLM(
    model=f"azure/{AZURE_OPENAI_DEPLOYMENT_NEW}",
    api_version="2025-01-01-preview",
    api_base=AZURE_OPENAI_ENDPOINT_NEW,
    api_key=AZURE_OPENAI_API_KEY_NEW,
)

support_agent = Agent(
    role="Senior Support Representative",
    goal="Be the most friendly and helpful " "support representative in your team",
    backstory=(
        "You work at crewAI (https://crewai.com) and "
        " are now working on providing "
        "support to {customer}, a super important customer "
        " for your company."
        "You need to make sure that you provide the best support!"
        "Make sure to provide full complete answers, "
        " and make no assumptions."
    ),
    allow_delegation=False,
    verbose=True,
    llm=llm,
)

support_quality_assurance_agent = Agent(
    role="Support Quality Assurance Specialist",
    goal="Get recognition for providing the "
    "best support quality assurance in your team",
    backstory=(
        "You work at crewAI (https://crewai.com) and "
        "are now working with your team "
        "on a request from {customer} ensuring that "
        "the support representative is "
        "providing the best support possible.\n"
        "You need to make sure that the support representative "
        "is providing full"
        "complete answers, and make no assumptions."
    ),
    verbose=True,
    llm=llm,
)


docs_scrape_tool = ScrapeWebsiteTool(
    website_url="https://docs.crewai.com/how-to/Creating-a-Crew-and-kick-it-off/"
)

inquiry_resolution = Task(
    description=(
        "{customer} just reached out with a super important ask:\n"
        "{inquiry}\n\n"
        "{person} from {customer} is the one that reached out. "
        "Make sure to use everything you know "
        "to provide the best support possible."
        "You must strive to provide a complete "
        "and accurate response to the customer's inquiry."
    ),
    expected_output=(
        "A detailed, informative response to the "
        "customer's inquiry that addresses "
        "all aspects of their question.\n"
        "The response should include references "
        "to everything you used to find the answer, "
        "including external data or solutions. "
        "Ensure the answer is complete, "
        "leaving no questions unanswered, and maintain a helpful and friendly "
        "tone throughout."
    ),
    tools=[docs_scrape_tool],
    agent=support_agent,
)


class ResponseOutput(BaseModel):
    response: str = Field(..., description="Response to be sent to the user")


quality_assurance_review = Task(
    description=(
        "Review the response drafted by the Senior Support Representative for {customer}'s inquiry. "
        "Ensure that the answer is comprehensive, accurate, and adheres to the "
        "high-quality standards expected for customer support.\n"
        "Verify that all parts of the customer's inquiry "
        "have been addressed "
        "thoroughly, with a helpful and friendly tone.\n"
        "Check for references and sources used to "
        " find the information, "
        "ensuring the response is well-supported and "
        "leaves no questions unanswered."
    ),
    expected_output=(
        "A final, detailed, and informative response "
        "ready to be sent to the customer.\n"
        "This response should fully address the "
        "customer's inquiry, incorporating all "
        "relevant feedback and improvements.\n"
        "Don't be too formal, we are a chill and cool company "
        "but maintain a professional and friendly tone throughout."
    ),
    agent=support_quality_assurance_agent,
    output_pydantic=ResponseOutput,
)

crew = Crew(
    agents=[support_agent, support_quality_assurance_agent],
    tasks=[inquiry_resolution, quality_assurance_review],
    verbose=True,
    memory=True,
    llm=llm,
    embedder={
        "provider": "azure",
        "config": {
            "api_key": AZURE_OPENAI_EMBEDDINGS_API_KEY,
            "api_base": AZURE_OPENAI_EMBEDDINGS_ENDPOINT,
            "api_version": AZURE_OPENAI_EMBEDDINGS_API_VERSION,
            "model_name": AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT,
            "deployment_id": AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT,
        },
    },
)

inputs = {
    "customer": "DeepLearningAI",
    "person": "Andrew Ng",
    "inquiry": "I need help with setting up a Crew "
    "and kicking it off, specifically "
    "how can I add memory to my crew? "
    "Can you provide guidance?",
}


result = crew.kickoff(inputs=inputs)


print(result.pydantic)

This issue is causing the Crew to not retain long term memory which causes the results to be wrong or somtimes even the Crew kickoff to fail

Full Trace of error -

/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/chromadb/types.py:144: PydanticDeprecatedSince211: Accessing the 'model_fields' attribute on the instance is deprecated. Instead, you should access this attribute from the model class. Deprecated in Pydantic V2.11 to be removed in V3.0.
  return self.model_fields  # pydantic 2.x

Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.

Failed to add to long term memory: Failed to convert text into a Pydantic model due to error: litellm.APIError: AzureException APIError - argument of type 'NoneType' is not iterable
๐Ÿš€ Crew: crew
โ”œโ”€โ”€ ๐Ÿ“‹ Task: a1ead2f3-0c2a-4bc9-b60b-532ba102e9e3
โ”‚      Assigned to: Agent1
โ”‚      Status: โœ… Completed
โ”‚   โ””โ”€โ”€ ๐Ÿค– Agent: Agent1
โ”‚           Status: โœ… Completed
โ””โ”€โ”€ ๐Ÿ“‹ Task: d565a0b8-4b1c-427b-aaa9-9b49f8264f9c
       Status: Executing Task...
    โ””โ”€โ”€ ๐Ÿค– Agent: Agent2
            Status: โœ… Completed


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'.

๐Ÿš€ Crew: crew
โ”œโ”€โ”€ ๐Ÿ“‹ Task: a1ead2f3-0c2a-4bc9-b60b-532ba102e9e3
โ”‚      Assigned to: Agent1
โ”‚      Status: โœ… Completed
โ”‚   โ””โ”€โ”€ ๐Ÿค– Agent: Agent1
โ”‚           Status: โœ… Completed
โ””โ”€โ”€ ๐Ÿ“‹ Task: d565a0b8-4b1c-427b-aaa9-9b49f8264f9c
       Assigned to: Agent2
       Status: โŒ Failed
    โ””โ”€โ”€ ๐Ÿค– Agent: Agent2
            Status: โœ… Completed
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Task Failure โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚                                                                                                                                                                                                                 โ”‚
โ”‚  Task Failed                                                                                                                                                                                                    โ”‚
โ”‚  Name: d565a0b8-4b1c-427b-aaa9-9b49f8264f9c                                                                                                                                                                     โ”‚
โ”‚  Agent: Agent2                                                                                                                                                                                        โ”‚
โ”‚                                                                                                                                                                                                                 โ”‚
โ”‚                                                                                                                                                                                                                 โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Crew Failure โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚                                                                                                                                                                                                                 โ”‚
โ”‚  Crew Execution Failed                                                                                                                                                                                          โ”‚
โ”‚  Name: crew                                                                                                                                                                                                     โ”‚
โ”‚  ID: 10de0999-083e-4392-925d-e4f801e21f86                                                                                                                                                                       โ”‚
โ”‚                                                                                                                                                                                                                 โ”‚
โ”‚                                                                                                                                                                                                                 โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/utilities/converter.py", line 128, in convert_to_model
    escaped_result = json.dumps(json.loads(result, strict=False))
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/llms/azure/azure.py", line 217, in completion
    if "gateway.ai.cloudflare.com" in api_base:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/main.py", line 1343, in completion
    response = azure_chat_completions.completion(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/llms/azure/azure.py", line 358, in completion
    raise AzureOpenAIError(
litellm.llms.azure.common_utils.AzureOpenAIError: argument of type 'NoneType' is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/instructor/retry.py", line 168, in retry_sync
    response = func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/utils.py", line 1255, in wrapper
    raise e
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/utils.py", line 1133, in wrapper
    result = original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/main.py", line 3216, in completion
    raise exception_type(
          ^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2224, in exception_type
    raise e
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2062, in exception_type
    raise APIError(
litellm.exceptions.APIError: litellm.APIError: AzureException APIError - argument of type 'NoneType' is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/instructor/retry.py", line 163, in retry_sync
    for attempt in max_retries:
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/tenacity/__init__.py", line 445, in __iter__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/tenacity/__init__.py", line 378, in iter
    result = action(retry_state)
             ^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/tenacity/__init__.py", line 421, in exc_check
    raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x7f0de01dd4d0 state=finished raised APIError>]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/utilities/converter.py", line 27, in to_pydantic
    result = self._create_instructor().to_pydantic()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/utilities/internal_instructor.py", line 40, in to_pydantic
    model = self._client.chat.completions.create(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/instructor/client.py", line 178, in create
    return self.create_fn(
           ^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/instructor/patch.py", line 193, in new_create_sync
    response = retry_sync(
               ^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/instructor/retry.py", line 194, in retry_sync
    raise InstructorRetryException(
instructor.exceptions.InstructorRetryException: litellm.APIError: AzureException APIError - argument of type 'NoneType' is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/llms/azure/azure.py", line 217, in completion
    if "gateway.ai.cloudflare.com" in api_base:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/main.py", line 1343, in completion
    response = azure_chat_completions.completion(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/llms/azure/azure.py", line 358, in completion
    raise AzureOpenAIError(
litellm.llms.azure.common_utils.AzureOpenAIError: argument of type 'NoneType' is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/instructor/retry.py", line 168, in retry_sync
    response = func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/utils.py", line 1255, in wrapper
    raise e
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/utils.py", line 1133, in wrapper
    result = original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/main.py", line 3216, in completion
    raise exception_type(
          ^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2224, in exception_type
    raise e
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2062, in exception_type
    raise APIError(
litellm.exceptions.APIError: litellm.APIError: AzureException APIError - argument of type 'NoneType' is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/instructor/retry.py", line 163, in retry_sync
    for attempt in max_retries:
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/tenacity/__init__.py", line 445, in __iter__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/tenacity/__init__.py", line 378, in iter
    result = action(retry_state)
             ^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/tenacity/__init__.py", line 421, in exc_check
    raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x7f0de018ef90 state=finished raised APIError>]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/utilities/converter.py", line 27, in to_pydantic
    result = self._create_instructor().to_pydantic()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/utilities/internal_instructor.py", line 40, in to_pydantic
    model = self._client.chat.completions.create(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/instructor/client.py", line 178, in create
    return self.create_fn(
           ^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/instructor/patch.py", line 193, in new_create_sync
    response = retry_sync(
               ^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/instructor/retry.py", line 194, in retry_sync
    raise InstructorRetryException(
instructor.exceptions.InstructorRetryException: litellm.APIError: AzureException APIError - argument of type 'NoneType' is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/llms/azure/azure.py", line 217, in completion
    if "gateway.ai.cloudflare.com" in api_base:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/main.py", line 1343, in completion
    response = azure_chat_completions.completion(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/llms/azure/azure.py", line 358, in completion
    raise AzureOpenAIError(
litellm.llms.azure.common_utils.AzureOpenAIError: argument of type 'NoneType' is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/instructor/retry.py", line 168, in retry_sync
    response = func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/utils.py", line 1255, in wrapper
    raise e
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/utils.py", line 1133, in wrapper
    result = original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/main.py", line 3216, in completion
    raise exception_type(
          ^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2224, in exception_type
    raise e
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2062, in exception_type
    raise APIError(
litellm.exceptions.APIError: litellm.APIError: AzureException APIError - argument of type 'NoneType' is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/instructor/retry.py", line 163, in retry_sync
    for attempt in max_retries:
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/tenacity/__init__.py", line 445, in __iter__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/tenacity/__init__.py", line 378, in iter
    result = action(retry_state)
             ^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/tenacity/__init__.py", line 421, in exc_check
    raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x7f0de01def90 state=finished raised APIError>]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/utilities/converter.py", line 27, in to_pydantic
    result = self._create_instructor().to_pydantic()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/utilities/internal_instructor.py", line 40, in to_pydantic
    model = self._client.chat.completions.create(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/instructor/client.py", line 178, in create
    return self.create_fn(
           ^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/instructor/patch.py", line 193, in new_create_sync
    response = retry_sync(
               ^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/instructor/retry.py", line 194, in retry_sync
    raise InstructorRetryException(
instructor.exceptions.InstructorRetryException: litellm.APIError: AzureException APIError - argument of type 'NoneType' is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kevin/Documents/projects/Summarize-Text/sample_crew.py", line 368, in <module>
    result = crew.kickoff(inputs=inputs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/crew.py", line 663, in kickoff
    result = self._run_sequential_process()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/crew.py", line 775, in _run_sequential_process
    return self._execute_tasks(self.tasks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/crew.py", line 878, in _execute_tasks
    task_output = task.execute_sync(
                  ^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/task.py", line 347, in execute_sync
    return self._execute_core(agent, context, tools)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/task.py", line 491, in _execute_core
    raise e  # Re-raise the exception after emitting the event
    ^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/task.py", line 417, in _execute_core
    pydantic_output, json_output = self._export_output(result)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/task.py", line 672, in _export_output
    model_output = convert_to_model(
                   ^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/utilities/converter.py", line 131, in convert_to_model
    return handle_partial_json(
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/utilities/converter.py", line 181, in handle_partial_json
    return convert_with_instructions(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/utilities/converter.py", line 204, in convert_with_instructions
    converter.to_pydantic() if not is_json_output else converter.to_json()
    ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/utilities/converter.py", line 66, in to_pydantic
    return self.to_pydantic(current_attempt + 1)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/utilities/converter.py", line 66, in to_pydantic
    return self.to_pydantic(current_attempt + 1)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/projects/Summarize-Text/crew_venv/lib/python3.11/site-packages/crewai/utilities/converter.py", line 67, in to_pydantic
    raise ConverterError(
crewai.utilities.converter.ConverterError: Failed to convert text into a Pydantic model due to error: litellm.APIError: AzureException APIError - argument of type 'NoneType' is not iterable

Kevv-J avatar May 14 '25 06:05 Kevv-J

@lorenzejay I'm using text-embedding-3-small from Azure OpenAI. I've attached a code sample above showing how I'm using it too.

Kevv-J avatar May 14 '25 06:05 Kevv-J

@Kevv-J thanks for sharing! There is something I'd like to test, would you mind updating your crewai (from you virtual env) by adding your model to the LLM_CONTEXT_WINDOW_SIZES? It's a quick test

The final result would be something like:

{
...
"YOUR/MODEL": 8192
}

lucasgomide avatar May 14 '25 11:05 lucasgomide

Hi Lucas, I think a return statement is missing in the summarize_message

https://github.com/crewAIInc/crewAI/blob/c403497cf44b7e08712502b289be71eaf9a050b7/src/crewai/utilities/agent_utils.py#L326

I think this is the complete flow If LLMContextLengthExceededException(str(exception)) is raised,

This will automatically invoke the https://github.com/crewAIInc/crewAI/blob/c403497cf44b7e08712502b289be71eaf9a050b7/src/crewai/agents/crew_agent_executor.py#L210

which will call the above function, but there are no changes in the crew_agent_executor messages list

Vidit-Ostwal avatar May 14 '25 11:05 Vidit-Ostwal

@Vidit-Ostwal we are updating the messages using memory reference - i'm not a big fan of this approach, btw

lucasgomide avatar May 14 '25 12:05 lucasgomide

@Vidit-Ostwal we are updating the messages using memory reference - i'm not a big fan of this approach, btw

Yes, my bad. I got a little confused python passes objects by references.

Vidit-Ostwal avatar May 14 '25 12:05 Vidit-Ostwal

Hi @lucasgomide, I wasnโ€™t able to override LLM_CONTEXT_WINDOW_SIZES successfully.

That said, it looks like the context size issue might have been resolved in version 0.119.0, but Iโ€™m now running into a different problem.

I traced the error by setting breakpoints, and it seems that one of the functions is attempting to make an Azure OpenAI call via LiteLLM without the required parameters โ€” specifically, api_key and api_base are None.

This occurs during the following call stack, inside: crewai.agents.agent_builder.base_agent_executor_mixin.CrewAgentExecutorMixin._create_long_term_memory() ๐Ÿ‘‡

Image

At the point of calling litellm.main.completion(), the values for api_key and api_base are missing: ๐Ÿ‘‡

Image

Itโ€™s odd because all other LLM calls โ€” including agents and orchestration โ€” seem to work fine. I'm not sure why only this specific call fails due to missing parameters, but I hope this gives you a useful clue to track it down.

Kevv-J avatar May 14 '25 13:05 Kevv-J

Hey team, just wanted to follow up and share that my issues have now been resolved.

The original problem related to the embedding model's token limit seems to have been addressed with the latest 0.119.0 release. However, I encountered two unrelated issues afterward that I wanted to document here in case it's helpful to others.

โœ… 1. Azure LLM Configuration Error When Using CustomTool with args_schema

I was seeing this error:

crewai.utilities.converter.ConverterError: Failed to convert text into a Pydantic model due to error: litellm.APIError: AzureException APIError - argument of type 'NoneType' is not iterable

It turned out to be a configuration issue. I was passing api_key and api_base explicitly when creating the LLM object and assigning it to the Agent and Crew, but the error occurred because:

  • The method crewai.utilities.internal_instructor.InternalInstructor.to_pydantic() internally calls completions.create() without passing those values explicitly for formatting CustomTool Input Pydantic Model according to args_schema.
  • Instead, it expects AZURE_API_KEY and AZURE_API_BASE to be present in the environment variables.

This is different from regular LLM calls, which work without needing those values in the environment, so the behavior feels a bit inconsistent. That said, setting the values in the environment fixed the issue:

os.environ["AZURE_API_KEY"] = AZURE_OPENAI_API_KEY_NEW
os.environ["AZURE_API_BASE"] = AZURE_OPENAI_ENDPOINT_NEW

โœ… 2. Outdated ChromaDB Cache from Older CrewAI Versions

I encountered the following error when trying to use long-term memory:

2025-05-14 18:56:15,575 - 140457043244864 - rag_storage.py-rag_storage:138 - ERROR: Error during entities search: 'dict' object has no attribute 'dimensionality'

This was due to an outdated local ChromaDB cache from older versions of CrewAI that used a different storage format. Simply clearing the cache resolved the issue.

Hope this helps someone else in a similar situation, and thanks again for the continued improvements in CrewAI!

Kevv-J avatar May 14 '25 16:05 Kevv-J

For the

  1. I think a PR is already being raised, #2786

Vidit-Ostwal avatar May 14 '25 16:05 Vidit-Ostwal

2025-06-06 13:08:38,807 - 140588796036928 - rag_storage.py-rag_storage:138 - ERROR: Error during short_term search: APIStatusError.__init__() missing 2 required keyword-only arguments: 'response' and 'body'
2025-06-06 13:08:40,333 - 140588796036928 - rag_storage.py-rag_storage:138 - ERROR: Error during entities search: APIStatusError.__init__() missing 2 required keyword-only arguments: 'response' and 'body'

Regret to inform that I had missed this earlier, the token limit issue still exists with crewai==0.119.0 Facing this issue still and I have a feeling this is causing FileReadTool calls to fails as well where I specify line_count=None but the Agent still calls the file read tool randomly with line_count=40 or line_count=60 or start_line with null and fail completely for no reason. example

## Using tool: Read a file's content
## Tool Input: 
"{\"file_path\": \"./file.md\", \"start_line\": null, \"line_count\": null}"
## Tool Output: 
Error: Failed to read file ./file.md. unsupported operand type(s) for -: 'NoneType' and 'int'

@Vidit-Ostwal any idea why I would still be getting this error

Kevv-J avatar Jun 06 '25 07:06 Kevv-J

@Kevv-J, can you once bump the crewai version and re-try this again, just want to confirm whether this has been already fixed in the newer versions.

Vidit-Ostwal avatar Jun 10 '25 05:06 Vidit-Ostwal

Error: Failed to read file ./file.md. unsupported operand type(s) for -: 'NoneType' and 'int'

I'm on it

Agent still calls the file read tool randomly with line_count=40 or line_count=60

For some reason your Agent is thinking is something relevant in those lines. You can fix it with prompt engineer, like saying to always read the entire file.

lucasgomide avatar Jun 10 '25 18:06 lucasgomide

@Kevv-J I just fixed the 'NoneType' and 'int'. It should be available in the next cut.

I'm heading to close this issue since I believe the other issue might be resolved with prompt engineer. Feel free to reopen if you still having trouble with that

lucasgomide avatar Jun 11 '25 13:06 lucasgomide