Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions concordia/environment/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,23 @@ def action_spec_parser(next_action_spec_string: str) -> entity_lib.ActionSpec:

Supports both JSON format (preferred) and legacy string format (for backward
compatibility).

Args:
next_action_spec_string: The string representation of the next action spec.

Returns:
The parsed action spec.
"""
raw = next_action_spec_string.strip()

# Accept common LLM formatting: fenced JSON blocks.
if raw.startswith("```"):
lines = raw.splitlines()
if lines:
# Drop opening fence line (``` or ```json)
if lines[0].strip().startswith("```"):
lines = lines[1:]
# Drop closing fence line if present
if lines and lines[-1].strip() == "```":
lines = lines[:-1]
raw = "\n".join(lines).strip()

try:
spec_dict = json.loads(next_action_spec_string)
spec_dict = json.loads(raw)
return entity_lib.action_spec_from_dict(spec_dict)
except json.JSONDecodeError:
logging.warning(
Expand All @@ -174,7 +182,6 @@ def action_spec_parser(next_action_spec_string: str) -> entity_lib.ActionSpec:
)
return _legacy_action_spec_parser(next_action_spec_string)


def action_spec_to_string(action_spec: entity_lib.ActionSpec) -> str:
"""Convert an action spec to a JSON string."""
return json.dumps(action_spec.to_dict())
Loading