ToolManager instances are retained after they are no longer referenced

Open Beginner friendly
#336 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
tooling

Research direction

Start with mesa_llm/tools/tool_manager.py and inspect how ToolManager.instances retains created managers. Reproduce the provided weakref and garbage-collection example, then run the regression test mentioned in the issue. Done means an otherwise unreferenced ToolManager is collected while the existing instance tracking behavior remains covered.

Written by the indexing model from the issue text.

Description

Describe the bug

ToolManager keeps every created instance in the class-level instances collection using a strong reference. As a result, a ToolManager remains alive even after the application drops all other references to it.

Expected behavior

A ToolManager that is no longer referenced by the application should be eligible for garbage collection.

To Reproduce

Run the following minimal example:

import gc
import weakref

from mesa_llm.tools.tool_manager import ToolManager

ToolManager.instances.clear()

manager = ToolManager()
manager_ref = weakref.ref(manager)

del manager
gc.collect()

print(manager_ref() is None)

With the current implementation, this prints:

False

The ToolManager is still alive because it remains referenced by ToolManager.instances.

Additional context

The issue was reproduced on Python 3.13.2 on Windows.

A regression test was added to verify that a ToolManager can be garbage-collected once no strong references remain.

Dominant language
Python
Stars
73
Forks
90
Avg merge
15h 45m
Merged PRs (30d)
1

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.

More from mesa/mesa-llm

All issues in mesa/mesa-llm

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.