diff --git a/src/cai/parallel_worker.py b/src/cai/parallel_worker.py index d69511fbf..146c04f0b 100644 --- a/src/cai/parallel_worker.py +++ b/src/cai/parallel_worker.py @@ -132,7 +132,7 @@ def main() -> int: try: with open(args.result_file, "w", encoding="utf-8") as f: - json.dump(payload, f, ensure_ascii=False) + json.dump(payload, f, ensure_ascii=False, default=str) except Exception as write_error: # pylint: disable=broad-except print(f"[CAI worker] failed to write result file: {write_error}", file=sys.stderr) return 2 diff --git a/src/cai/tools/streaming.py b/src/cai/tools/streaming.py index f2e7554fd..b5f55a218 100644 --- a/src/cai/tools/streaming.py +++ b/src/cai/tools/streaming.py @@ -125,10 +125,13 @@ def _get_agent_token_info(): from cai.sdk.agents.models.openai_chatcompletions import ACTIVE_MODEL_INSTANCES if ACTIVE_MODEL_INSTANCES: - # Get the most recent instance (highest instance ID) - latest_key = max(ACTIVE_MODEL_INSTANCES.keys(), key=lambda x: x[1]) - model_ref = ACTIVE_MODEL_INSTANCES[latest_key] - model = model_ref() if model_ref else None + try: + # Get the most recent instance (highest instance ID) + latest_key = max(ACTIVE_MODEL_INSTANCES.keys(), key=lambda x: x[1]) + model_ref = ACTIVE_MODEL_INSTANCES.get(latest_key) + model = model_ref() if model_ref else None + except Exception: + model = None if model: # Get display name with ID