Skip to content
Changelog

PythonTools returns a variable that holds None

Contributors澍Kaustubh Shukla

October 1, 20261 min read

Agno's PythonTools.run_python_code, save_to_file_and_run and run_python_file_return_variable now check that variable_to_return exists in the namespace before they read it. They used .get() and treated a None result as a missing name, so an agent whose code assigned None, like a search that found no match, was told the variable it had just set didn't exist. A defined value still comes back as a string:

from agno.tools.python import PythonTools
 
PythonTools().run_python_code("match = None", variable_to_return="match")
# Before: 'Variable match not found'
# Now:    'None'
 
PythonTools().run_python_code("x = 1", variable_to_return="match")
# Before and now: 'Variable match not found'

See the cookbook, and learn more about PythonTools in the documentation.

Frequently asked questions

Earlier releases looked the variable up with .get(), which returns None for a missing name, and treated any None as missing. A variable assigned None got the "not found" message. PythonTools now checks whether the name exists first.

run_python_code, save_to_file_and_run and run_python_file_return_variable all take variable_to_return, and all three now tell a None value apart from a missing name.

Shipped around the same time