Skip to content

Build and run agents you can see, understand and trust.

fix(session): allow the saving state contains illegal Unicode characters (#1123)

DavdGaof902c77a7ca4
diff --git a/src/agentscope/session/_json_session.py b/src/agentscope/session/_json_session.py
index c37b3527e..6d7f4e191 100644
--- a/src/agentscope/session/_json_session.py
+++ b/src/agentscope/session/_json_session.py
@@ -71,6 +71,7 @@ class JSONSession(SessionBase):
self._get_save_path(session_id),
"w",
encoding="utf-8",
+ errors="surrogatepass",
) as file:
json.dump(state_dicts, file, ensure_ascii=False)
@@ -93,7 +94,12 @@ class JSONSession(SessionBase):
"""
session_save_path = self._get_save_path(session_id)
if os.path.exists(session_save_path):
- with open(session_save_path, "r", encoding="utf-8") as file:
+ with open(
+ session_save_path,
+ "r",
+ encoding="utf-8",
+ errors="surrogatepass",
+ ) as file:
states = json.load(file)
for name, state_module in state_modules_mapping.items():