Skip to content
Changelog

Cached tools now release agent state after each run

September 8, 20261 min read

On Python 3.13, a long-running Agno process held on to Agent, session and run state for as long as it lived. The leak came from Agno's cached tool wrappers.

Pydantic's validate_call stores the caller's local variables on each wrapper it builds, and Agno caches those tool wrappers for the life of the process. On Python 3.13, every cached tool kept alive its building frame, which held the Agent, session and run state from the stack.

Agno now clears the frame reference once the validators are built.

Two reference chains compared. Before, the tool cache, which lives as long as the process, held the validate_call wrapper, which held the caller's frame, which held the Agent, session and run state, so none of it was ever freed. Now the link from the wrapper to the frame is cut, and the frame and the state are released after the run.

Learn more about Python functions as tools in the documentation.

Frequently asked questions

Each wrapper that Pydantic's validate_call builds stores the caller's local variables, and Agno keeps those tool wrappers cached for as long as the process runs. On Python 3.13, each cached tool kept its building frame alive, along with the Agent, session and run state. Agno now drops that reference after it builds the validators.

Yes. Agno cuts the link from the cached validate_call wrapper to the frame that built it, so the frame and the Agent, session and run state are released after the run.

Shipped around the same time