Skip to content

Commit 988a58c

Browse files
fix: harden legacy agent.json loading error handling
1 parent cbc7ec3 commit 988a58c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

core/framework/runner/runner.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,11 +956,19 @@ def load(
956956

957957
# Fallback: load from agent.json (legacy JSON-based agents)
958958
agent_json_path = agent_path / "agent.json"
959-
if not agent_json_path.exists():
959+
if not agent_json_path.is_file():
960960
raise FileNotFoundError(f"No agent.py or agent.json found in {agent_path}")
961961

962962
with open(agent_json_path, encoding="utf-8") as f:
963-
graph, goal = load_agent_export(f.read())
963+
export_data = f.read()
964+
965+
if not export_data.strip():
966+
raise ValueError(f"Empty agent export file: {agent_json_path}")
967+
968+
try:
969+
graph, goal = load_agent_export(export_data)
970+
except json.JSONDecodeError as exc:
971+
raise ValueError(f"Invalid JSON in agent export file: {agent_json_path}") from exc
964972

965973
return cls(
966974
agent_path=agent_path,

0 commit comments

Comments
 (0)