Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: Improve `run_code` output format (#2270)
Matthew Zhou7fdf2e27b327
diff --git a/letta/services/tool_executor/tool_executor.py b/letta/services/tool_executor/tool_executor.pyindex 92b2aab76..143696992 100644--- a/letta/services/tool_executor/tool_executor.py+++ b/letta/services/tool_executor/tool_executor.py@@ -1,3 +1,4 @@+import jsonimport mathimport tracebackfrom abc import ABC, abstractmethod@@ -723,8 +724,21 @@ class LettaBuiltinToolExecutor(ToolExecutor):# Leave empty for pythonparams["language"] = language- res = await sbx.run_code(**params)- return str(res)+ res = self._llm_friendly_result(await sbx.run_code(**params))+ return json.dumps(res, ensure_ascii=False)++ def _llm_friendly_result(self, res):+ out = {+ "results": [r.text if hasattr(r, "text") else str(r) for r in res.results],+ "logs": {+ "stdout": getattr(res.logs, "stdout", []),+ "stderr": getattr(res.logs, "stderr", []),+ },+ }+ err = getattr(res, "error", None)+ if err is not None:+ out["error"] = err+ return outasync def web_search(agent_state: "AgentState", query: str) -> str:"""