ToolManager instances are retained after they are no longer referenced
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mesa/mesa-llm
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
-
depedency mesa-4
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100