crewai - ✅(Solved) Fix [BUG]Telemetry Fails When Using Custom Memory Storage Backends [4 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
crewAIInc/crewAI#4703Fetched 2026-04-08 00:40:32
View on GitHub
Comments
1
Participants
2
Timeline
19
Reactions
0
Timeline (top)
referenced ×9cross-referenced ×7labeled ×2commented ×1

When using a custom Memory instance with an explicitly configured storage backend (including LanceDB), the crew fails to initialize with an OpenTelemetry error:

Invalid type Memory for attribute 'crew_memory' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

Error Message

from crewai import Agent, Crew, Task, LLM from crewai.memory import Memory from crewai.memory.storage.lancedb_storage import LanceDBStorage

Explicitly configure storage (instead of using memory=True)

storage = LanceDBStorage(path="./custom_memory", vector_dim=1536)

memory = Memory( storage=storage, llm=LLM(model="gpt-4o-mini") )

agent = Agent( role="Researcher", goal="Research topics", backstory="Expert researcher", llm=LLM(model="gpt-4o-mini") )

task = Task( description="Research AI trends", expected_output="A summary", agent=agent )

This will fail with telemetry error

crew = Crew( agents=[agent], tasks=[task], memory=memory, # Error: OpenTelemetry can't serialize Memory object )

crew.kickoff()

Root Cause

Root cause: In crewai/telemetry/telemetry.py at line 276, the code attempts to serialize the crew.memory field directly without checking its type:

Fix Action

Fixed

PR fix notes

PR #4704: fix: serialize Memory objects for telemetry span attributes (#4703)

Description (problem / solution / changelog)

fix: serialize Memory objects for telemetry span attributes (#4703)

Summary

When crew.memory is a custom Memory instance (rather than a bool), OpenTelemetry rejects it as a span attribute value since it only accepts primitives (bool, str, bytes, int, float). This caused a runtime error during crew initialization:

Invalid type Memory for attribute 'crew_memory' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

Fix: In crew_creation() in telemetry.py, the crew.memory value is now converted before being set as a span attribute — booleans pass through unchanged, while any other type (e.g. a Memory instance) is converted to its class name string.

Fixes https://github.com/crewAIInc/crewAI/issues/4703

Review & Testing Checklist for Human

  • Verify the isinstance(crew.memory, bool) guard is correct — note that bool is a subclass of int in Python, so this must check bool specifically (not a broader primitive check) to avoid True/False being converted to "bool" string
  • Confirm there are no other places in telemetry.py that pass crew.memory directly to _add_attribute (I found only the one at the former line 282)
  • Run the 4 new tests locally: pytest lib/crewai/tests/telemetry/test_telemetry.py -k TestCrewCreationTelemetryMemorySerialization -vv

Notes

<!-- CURSOR_SUMMARY -->

[!NOTE] Low Risk Low risk: small telemetry-only change that converts a single span attribute to an OTEL-serializable value, covered by new regression tests.

Overview Fixes Telemetry.crew_creation() to ensure the crew_memory span attribute is always OpenTelemetry-serializable: boolean values are preserved, and non-bool memory objects are recorded as their class name string.

Adds a focused regression test suite covering memory=True, memory=False, and custom memory instances, including an assertion that the captured crew_memory value is always a primitive OTEL accepts.

<sup>Written by Cursor Bugbot for commit b66a768ad6e142370555dca0c4f855d943ca23d0. This will update automatically on new commits. Configure here.</sup>

<!-- /CURSOR_SUMMARY -->

Changed files

  • lib/crewai/src/crewai/telemetry/telemetry.py (modified, +5/-1)
  • lib/crewai/tests/telemetry/test_telemetry.py (modified, +193/-1)

PR #4718: fix: serialize Memory objects for telemetry span attributes

Description (problem / solution / changelog)

Summary

Fixes #4703

When crew.memory is a custom Memory instance (rather than a bool), OpenTelemetry rejects it as a span attribute value since it only accepts primitives (bool, str, bytes, int, float). This causes a runtime error during crew initialization:

Invalid type Memory for attribute 'crew_memory' value.
Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

Fix: In crew_creation() in telemetry.py, convert the crew.memory value before setting it as a span attribute -- booleans pass through unchanged, while any other type (e.g. a Memory instance) is converted to its class name string.

The isinstance(crew.memory, bool) check is intentional: since bool is a subclass of int in Python, checking bool first ensures True/False are preserved as booleans rather than being converted to "bool" string.

Test Plan

  • Added parametrized test covering memory=True, memory=False, and a custom memory instance
  • Each case asserts the captured crew_memory attribute matches the expected value
  • Each case verifies the value is an OTel-serializable type
<!-- CURSOR_SUMMARY -->

[!NOTE] Low Risk Low risk change limited to telemetry span attribute formatting; primary risk is minor downstream impact on analytics expecting the previous crew_memory value shape.

Overview Prevents OpenTelemetry span creation from failing when crew.memory is a custom object by serializing the crew_memory attribute to an OTel-accepted primitive (booleans preserved; other types recorded as their class name).

Adds a regression test to ensure Telemetry.crew_creation() always emits an OTel-serializable crew_memory value for both boolean and custom memory instances.

<sup>Written by Cursor Bugbot for commit 894f5e75e66ef9bc55d579b198b59811ec2c7ad3. This will update automatically on new commits. Configure here.</sup>

<!-- /CURSOR_SUMMARY -->

Changed files

  • lib/crewai/src/crewai/telemetry/telemetry.py (modified, +5/-1)
  • lib/crewai/tests/telemetry/test_telemetry.py (modified, +44/-1)

PR #4771: fix: convert Memory object to string for OpenTelemetry attribute

Description (problem / solution / changelog)

Summary

Fixes #4703.

When crew.memory is a custom Memory instance (instead of True), passing it directly to self._add_attribute() crashes with:

Invalid type Memory for attribute 'crew_memory' value.
Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

Fix

Convert non-primitive crew.memory values to the class name string before setting the telemetry attribute:

# Before:
self._add_attribute(span, "crew_memory", crew.memory)

# After:
crew_memory = crew.memory if isinstance(crew.memory, (bool, str, int, float)) else type(crew.memory).__name__
self._add_attribute(span, "crew_memory", crew_memory)

This preserves backward compatibility with memory=True while allowing custom Memory instances to be tracked as "Memory" in telemetry.

lib/crewai/src/crewai/telemetry/telemetry.py — one-line fix at line 282.

<!-- CURSOR_SUMMARY -->

[!NOTE] Low Risk Low risk change limited to telemetry metadata: it only alters how crew_memory is recorded to avoid invalid OpenTelemetry attribute types.

Overview Fixes a telemetry crash during Telemetry.crew_creation when crew.memory is a custom object by coercing non-primitive values to the class name string before setting the crew_memory span attribute.

<sup>Written by Cursor Bugbot for commit 6f58a788741d690ade9e47c318d1cee38fe515dd. This will update automatically on new commits. Configure here.</sup>

<!-- /CURSOR_SUMMARY -->

Changed files

  • lib/crewai/src/crewai/telemetry/telemetry.py (modified, +2/-1)

PR #4778: fix(telemetry): coerce crew.memory to bool before passing to OpenTelemetry span

Description (problem / solution / changelog)

Summary

When crew.memory is a custom Memory instance (rather than a plain bool), the telemetry code passed it directly to span.set_attribute(), which raised:

Invalid type Memory for attribute 'crew_memory' value.
Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

This prevented the entire crew from initialising whenever a custom memory backend (e.g. LanceDB) was used.

Root Cause

Line 282 of telemetry.py:

self._add_attribute(span, "crew_memory", crew.memory)

crew.memory is typed as Union[bool, Memory], but OpenTelemetry's set_attribute only accepts primitive types.

Fix

Normalise the value before the attribute call:

self._add_attribute(
    span,
    "crew_memory",
    crew.memory if isinstance(crew.memory, bool) else bool(crew.memory),
)
  • If crew.memory is already a bool → pass unchanged.
  • Otherwise → coerce with bool(), preserving the semantic "was memory enabled?".

Tests

Added test_crew_created_span_with_memory_object_does_not_raise to tests/telemetry/test_telemetry.py. It passes a mock Memory object as crew.memory and asserts that span.set_attribute is called with a bool value for the crew_memory key.

Fixes #4703

<!-- CURSOR_SUMMARY -->

[!NOTE] Low Risk Low risk: a small telemetry-only change that coerces crew.memory to a primitive type to avoid OpenTelemetry attribute type errors, backed by a focused regression test.

Overview Fixes a telemetry crash during crew_creation() when crew.memory is a non-bool Memory instance by coercing the crew_memory span attribute to a bool.

Adds a regression test ensuring span.set_attribute('crew_memory', ...) is called with a boolean value, preventing crew initialization failures when custom memory backends are used.

<sup>Written by Cursor Bugbot for commit e180714c5db667837da433afbf822a7ad9f6f7fb. This will update automatically on new commits. Configure here.</sup>

<!-- /CURSOR_SUMMARY -->

Changed files

  • lib/crewai/src/crewai/telemetry/telemetry.py (modified, +5/-1)
  • lib/crewai/tests/telemetry/test_telemetry.py (modified, +54/-0)

Code Example

Invalid type Memory for attribute 'crew_memory' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

---

from crewai import Agent, Crew, Task, LLM
from crewai.memory import Memory
from crewai.memory.storage.lancedb_storage import LanceDBStorage

# Explicitly configure LanceDB storage instead of using memory=True
storage = LanceDBStorage(path="./my_memory_db", vector_dim=1536)
memory = Memory(
    storage=storage,
    llm=LLM(model="gpt-4o-mini")
)

---

agent = Agent(
    role="Researcher",
    goal="Research topics",
    backstory="Expert researcher",
    llm=LLM(model="gpt-4o-mini")
)

task = Task(
    description="Research AI trends",
    expected_output="A summary of AI trends",
    agent=agent
)

crew = Crew(
    agents=[agent],
    tasks=[task],
    memory=memory,  # Passing Memory instance instead of True
)

---

crew.kickoff()

---

from crewai import Agent, Crew, Task, LLM
from crewai.memory import Memory
from crewai.memory.storage.lancedb_storage import LanceDBStorage

# Explicitly configure storage (instead of using memory=True)
storage = LanceDBStorage(path="./custom_memory", vector_dim=1536)

memory = Memory(
    storage=storage,
    llm=LLM(model="gpt-4o-mini")
)

agent = Agent(
    role="Researcher",
    goal="Research topics",
    backstory="Expert researcher",
    llm=LLM(model="gpt-4o-mini")
)

task = Task(
    description="Research AI trends",
    expected_output="A summary",
    agent=agent
)

# This will fail with telemetry error
crew = Crew(
    agents=[agent],
    tasks=[task],
    memory=memory,  # Error: OpenTelemetry can't serialize Memory object
)

crew.kickoff()

---

Invalid type Memory for attribute 'crew_memory' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

---

self._add_attribute(span, "crew_memory", crew.memory)

---

# Line 273-276 in crewai/telemetry/telemetry.py
self._add_attribute(span, "python_version", platform.python_version())
add_crew_attributes(span, crew, self._add_attribute)
self._add_attribute(span, "crew_process", crew.process)

# Convert memory to serializable type for telemetry
memory_value = crew.memory if isinstance(crew.memory, (bool, str, int, float)) else str(type(crew.memory).__name__)
self._add_attribute(span, "crew_memory", memory_value)

self._add_attribute(span, "crew_number_of_tasks", len(crew.tasks))
RAW_BUFFERClick to expand / collapse

Description

When using a custom Memory instance with an explicitly configured storage backend (including LanceDB), the crew fails to initialize with an OpenTelemetry error:

Invalid type Memory for attribute 'crew_memory' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

Steps to Reproduce

  1. Create a custom Memory instance with LanceDBStorage explicitly configured:
from crewai import Agent, Crew, Task, LLM
from crewai.memory import Memory
from crewai.memory.storage.lancedb_storage import LanceDBStorage

# Explicitly configure LanceDB storage instead of using memory=True
storage = LanceDBStorage(path="./my_memory_db", vector_dim=1536)
memory = Memory(
    storage=storage,
    llm=LLM(model="gpt-4o-mini")
)
  1. Create a simple crew with the custom memory instance:
agent = Agent(
    role="Researcher",
    goal="Research topics",
    backstory="Expert researcher",
    llm=LLM(model="gpt-4o-mini")
)

task = Task(
    description="Research AI trends",
    expected_output="A summary of AI trends",
    agent=agent
)

crew = Crew(
    agents=[agent],
    tasks=[task],
    memory=memory,  # Passing Memory instance instead of True
)
  1. Attempt to run the crew:
crew.kickoff()
  1. Observe the telemetry error during crew initialization

Expected behavior

Custom Memory instances with explicitly configured storage backends should work without telemetry errors. The crew should initialize and run successfully, just as it does with memory=True.

Screenshots/Code snippets

Complete minimal reproduction:

from crewai import Agent, Crew, Task, LLM
from crewai.memory import Memory
from crewai.memory.storage.lancedb_storage import LanceDBStorage

# Explicitly configure storage (instead of using memory=True)
storage = LanceDBStorage(path="./custom_memory", vector_dim=1536)

memory = Memory(
    storage=storage,
    llm=LLM(model="gpt-4o-mini")
)

agent = Agent(
    role="Researcher",
    goal="Research topics",
    backstory="Expert researcher",
    llm=LLM(model="gpt-4o-mini")
)

task = Task(
    description="Research AI trends",
    expected_output="A summary",
    agent=agent
)

# This will fail with telemetry error
crew = Crew(
    agents=[agent],
    tasks=[task],
    memory=memory,  # Error: OpenTelemetry can't serialize Memory object
)

crew.kickoff()

Error message:

Invalid type Memory for attribute 'crew_memory' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

Operating System

Other (specify in additional context)

Python Version

3.11

crewAI Version

1.10.1a1 (main branch)

crewAI Tools Version

N/A

Virtual Environment

Venv

Evidence

Root cause: In crewai/telemetry/telemetry.py at line 276, the code attempts to serialize the crew.memory field directly without checking its type:

self._add_attribute(span, "crew_memory", crew.memory)

When memory=True, this works because crew.memory is a boolean. However, when passing a custom Memory instance, crew.memory contains the Memory object itself, which OpenTelemetry cannot serialize.

Possible Solution

Convert non-primitive memory values to a serializable representation in telemetry.py:

# Line 273-276 in crewai/telemetry/telemetry.py
self._add_attribute(span, "python_version", platform.python_version())
add_crew_attributes(span, crew, self._add_attribute)
self._add_attribute(span, "crew_process", crew.process)

# Convert memory to serializable type for telemetry
memory_value = crew.memory if isinstance(crew.memory, (bool, str, int, float)) else str(type(crew.memory).__name__)
self._add_attribute(span, "crew_memory", memory_value)

self._add_attribute(span, "crew_number_of_tasks", len(crew.tasks))

This change:

  1. Checks if crew.memory is a primitive type that OpenTelemetry can handle
  2. If not, converts it to the class name string (e.g., "Memory")
  3. Maintains backward compatibility with memory=True usage
  4. Allows telemetry to track that custom memory is being used without failing

Additional context

Os is MacOS Tahoe 26.3

extent analysis

Fix Plan

To resolve the OpenTelemetry error when using a custom Memory instance, you need to modify the telemetry.py file to handle non-primitive memory values. Here are the steps:

  • Open the telemetry.py file located in crewai/telemetry/.
  • Locate the lines where the crew.memory attribute is being serialized (around line 276).
  • Replace the existing code with the following snippet:
# Convert memory to serializable type for telemetry
memory_value = crew.memory if isinstance(crew.memory, (bool, str, int, float)) else str(type(crew.memory).__name__)
self._add_attribute(span, "crew_memory", memory_value)

This code checks if crew.memory is a primitive type and converts it to a string representation of the class name if it's not.

Verification

After applying the fix, you can verify that the issue is resolved by running your crew instance again:

crew.kickoff()

The crew should now initialize and run without any telemetry errors.

Extra Tips

  • Make sure to update your crewai version to the latest available to ensure you have the latest fixes and features.
  • If you're using a virtual environment, ensure that the crewai package is installed and up-to-date within that environment.
  • Consider submitting a pull request to the crewai repository with your fix to help others who may encounter the same issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Custom Memory instances with explicitly configured storage backends should work without telemetry errors. The crew should initialize and run successfully, just as it does with memory=True.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

crewai - ✅(Solved) Fix [BUG]Telemetry Fails When Using Custom Memory Storage Backends [4 pull requests, 1 comments, 2 participants]