agent: python tool: return errors
This commit is contained in:
parent
f9afb041e2
commit
a98f48315c
1 changed files with 19 additions and 14 deletions
|
@ -22,6 +22,7 @@ def execute_python(source: str) -> Union[Dict, str]:
|
||||||
Returns:
|
Returns:
|
||||||
dict | str: A dictionary containing variables declared, or an error message if an exception occurred.
|
dict | str: A dictionary containing variables declared, or an error message if an exception occurred.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
namespace = {}
|
namespace = {}
|
||||||
sys.stderr.write(f"Executing Python program:\n{source}\n")
|
sys.stderr.write(f"Executing Python program:\n{source}\n")
|
||||||
exec(source, namespace)
|
exec(source, namespace)
|
||||||
|
@ -35,5 +36,9 @@ def execute_python(source: str) -> Union[Dict, str]:
|
||||||
and _is_serializable(v)
|
and _is_serializable(v)
|
||||||
}
|
}
|
||||||
sys.stderr.write(f"Results: {json.dumps(results, indent=2)}\n")
|
sys.stderr.write(f"Results: {json.dumps(results, indent=2)}\n")
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
except Exception as e:
|
||||||
|
msg = f"Error: {sys.exc_info()[1]}"
|
||||||
|
sys.stderr.write(f"{msg}\n")
|
||||||
|
return msg
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue