Description:
⚡ The Problem
Currently, the OM1 runtime relies on LLM providers returning strictly formatted JSON. However, modern VLMs and LLMs (especially via providers like OpenAI or Anthropic) occasionally wrap their responses in Markdown code blocks (e.g., json ... ) or include conversational filler.
When this happens, the current implementation of json.loads() fails, causing the agent thread to crash or enter an unrecoverable state. This is a primary cause of "silent deaths" in long-running agent sessions.
✨ The Solution
This PR introduces a Resilient Parsing Utility that:
Extracts JSON from Markdown: Uses regex to identify and isolate JSON objects within backticks.
Bracket-based Fallback: If no markdown is found, it attempts to locate the primary JSON object using bracket indexing.
Graceful Failure: Instead of raising a JSONDecodeError that kills the process, it logs the error and returns a "Safe No-Op" (a wait action), allowing the agent to remain alive and retry in the next tick.
🛠️ Changes:
Added src/utils/parsing.py with the extract_and_parse_json utility.
Updated src/connectors/base_connector.py (or relevant connector file) to utilize the safe parser.
Added a small unit test suite to verify parsing against various "dirty" LLM outputs.
🧪 Testing Conducted:
[x] Tested with raw JSON strings.
[x] Tested with Markdown-wrapped JSON ( json ... ).
[x] Verified that malformed strings no longer crash the agent runtime.
Description:
⚡ The Problem
Currently, the OM1 runtime relies on LLM providers returning strictly formatted JSON. However, modern VLMs and LLMs (especially via providers like OpenAI or Anthropic) occasionally wrap their responses in Markdown code blocks (e.g.,
json ...) or include conversational filler.When this happens, the current implementation of json.loads() fails, causing the agent thread to crash or enter an unrecoverable state. This is a primary cause of "silent deaths" in long-running agent sessions.
✨ The Solution
This PR introduces a Resilient Parsing Utility that:
Extracts JSON from Markdown: Uses regex to identify and isolate JSON objects within backticks.
Bracket-based Fallback: If no markdown is found, it attempts to locate the primary JSON object using bracket indexing.
Graceful Failure: Instead of raising a JSONDecodeError that kills the process, it logs the error and returns a "Safe No-Op" (a wait action), allowing the agent to remain alive and retry in the next tick.
🛠️ Changes:
Added src/utils/parsing.py with the extract_and_parse_json utility.
Updated src/connectors/base_connector.py (or relevant connector file) to utilize the safe parser.
Added a small unit test suite to verify parsing against various "dirty" LLM outputs.
🧪 Testing Conducted:
[x] Tested with raw JSON strings.
[x] Tested with Markdown-wrapped JSON (
json ...).[x] Verified that malformed strings no longer crash the agent runtime.