Skip to content

Commit 57ad5c4

Browse files
placerdaCopilot
andcommitted
fix(agent): use ruamel.yaml instead of pyyaml in agent modules
Four agent modules imported PyYAML (`import yaml`) but `pyproject.toml` only declares `ruamel.yaml`. On clean CI runners (no PyYAML in the venv) this raised `ModuleNotFoundError: yaml` at `agentops doctor` time, breaking the doctor step of the generated deploy workflow. Refactored to the existing `ruamel.yaml` dependency (same pattern as `src/agentops/utils/yaml.py`): - `agent/checks/opex_workspace.py` - `agent/checks/spec_conformance.py` - `agent/llm_assist/_bundle_rule.py` - `agent/cockpit.py` (preserved the lazy-import semantics inside `_resolve_agent_identity`) Behaviour preserved: `YAML(typ='safe').load(...)` returns plain dicts/lists just like `yaml.safe_load(...)`. No new runtime dependency. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent fc204e3 commit 57ad5c4

4 files changed

Lines changed: 16 additions & 13 deletions

File tree

src/agentops/agent/checks/opex_workspace.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
from pathlib import Path
2525
from typing import Any, Dict, List, Optional
2626

27-
import yaml
27+
from ruamel.yaml import YAML
28+
from ruamel.yaml.error import YAMLError
2829

2930
from agentops.agent.findings import Category, Finding, Severity
3031

@@ -552,8 +553,8 @@ def _safe_load_yaml(path: Path) -> Optional[dict]:
552553
return None
553554
try:
554555
with path.open("r", encoding="utf-8") as handle:
555-
data = yaml.safe_load(handle)
556-
except (OSError, yaml.YAMLError):
556+
data = YAML(typ="safe").load(handle)
557+
except (OSError, YAMLError):
557558
return None
558559
return data if isinstance(data, dict) else None
559560

src/agentops/agent/checks/spec_conformance.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
from pathlib import Path
2323
from typing import Iterable, List, Optional
2424

25-
import yaml
25+
from ruamel.yaml import YAML
26+
from ruamel.yaml.error import YAMLError
2627

2728
from agentops.agent.config import SpecConformanceCheckConfig
2829
from agentops.agent.findings import Category, Finding, Severity
@@ -297,8 +298,8 @@ def _check_agent_drift(workspace: Path, doc: SpecDocument) -> List[Finding]:
297298
if not run_yaml.exists():
298299
return []
299300
try:
300-
raw = yaml.safe_load(run_yaml.read_text(encoding="utf-8"))
301-
except (OSError, yaml.YAMLError):
301+
raw = YAML(typ="safe").load(run_yaml.read_text(encoding="utf-8"))
302+
except (OSError, YAMLError):
302303
return []
303304
if not isinstance(raw, dict):
304305
return []
@@ -342,8 +343,8 @@ def _collect_evaluator_names(workspace: Path) -> set[str]:
342343
return out
343344
for p in bundles_dir.glob("*.y*ml"):
344345
try:
345-
raw = yaml.safe_load(p.read_text(encoding="utf-8"))
346-
except (OSError, yaml.YAMLError):
346+
raw = YAML(typ="safe").load(p.read_text(encoding="utf-8"))
347+
except (OSError, YAMLError):
347348
continue
348349
if not isinstance(raw, dict):
349350
continue

src/agentops/agent/cockpit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,11 +2286,11 @@ def _resolve_agent_identity(workspace: Path) -> Tuple[Optional[str], str]:
22862286
``agentops.yaml``) takes precedence over the legacy layered schema
22872287
(``target.endpoint.agent_id`` in ``run.yaml``).
22882288
"""
2289-
import yaml # noqa: PLC0415
2289+
from ruamel.yaml import YAML # noqa: PLC0415
22902290

22912291
def _read_yaml(path: Path) -> Optional[dict]:
22922292
try:
2293-
data = yaml.safe_load(path.read_text(encoding="utf-8"))
2293+
data = YAML(typ="safe").load(path.read_text(encoding="utf-8"))
22942294
except Exception: # noqa: BLE001
22952295
return None
22962296
return data if isinstance(data, dict) else None

src/agentops/agent/llm_assist/_bundle_rule.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from pathlib import Path
1212
from typing import List, Optional
1313

14-
import yaml
14+
from ruamel.yaml import YAML
15+
from ruamel.yaml.error import YAMLError
1516

1617
from agentops.agent.findings import Category, Finding
1718
from agentops.agent.llm_assist._base import (
@@ -106,8 +107,8 @@ def check_bundle_coverage(
106107

107108
# Sanity check: skip when the YAML is unparseable.
108109
try:
109-
yaml.safe_load(bundle_text)
110-
except yaml.YAMLError:
110+
YAML(typ="safe").load(bundle_text)
111+
except YAMLError:
111112
return []
112113

113114
ih = hash_text("bundle_coverage", bundle_text, agent_excerpt)

0 commit comments

Comments
 (0)