Skip to content

Commit 56b8308

Browse files
Dave Lealclaude
andcommitted
fix: strip markdown fences in persona JSON parsing + update usage test
Personas often return JSON wrapped in ```json fences which caused json.loads to fail and fall back to {"raw": text}. Now strips fences before parsing, so persona outputs are structured dicts in TurnContext and _summarize_slot can show meaningful previews in discussion log. Update test_usage_integration: "hello" is now correctly classified as simple → haiku (agent-manager enabled by default). 715 tests passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a80f7b4 commit 56b8308

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

tests/test_usage_integration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,5 @@ def test_project_message_records_mention():
6868
event, say=MagicMock(), channel_name="alpha-dev"
6969
)
7070

71-
mock_record.assert_called_once_with("api", "claude-sonnet-4-6")
71+
# "hello" is classified as simple → haiku by agent-manager
72+
mock_record.assert_called_once_with("api", "claude-haiku-4-5-20251001")

tools/personas/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import json
1111
import logging
12+
import re
1213
from abc import abstractmethod
1314
from typing import ClassVar
1415

@@ -58,8 +59,10 @@ def run(self, inputs: dict[str, dict]) -> dict:
5859
resolved_model = MODEL_MAP.get(self.model, self.model)
5960
msg = self._call_api(system, user, resolved_model, self.max_tokens)
6061
text = msg.content[0].text.strip()
62+
# Strip markdown code fences (```json ... ```) before JSON parsing
63+
cleaned = re.sub(r"^```[a-z]*\n?", "", text).rstrip("`").strip()
6164
try:
62-
result = json.loads(text)
65+
result = json.loads(cleaned)
6366
except (json.JSONDecodeError, ValueError):
6467
result = {"raw": text}
6568
result["_usage"] = {

0 commit comments

Comments
 (0)