fix: universal parsing + OpenRouter + state bug — purpose_agent/actor.py
Browse files- purpose_agent/actor.py +15 -22
purpose_agent/actor.py
CHANGED
|
@@ -218,30 +218,23 @@ class Actor:
|
|
| 218 |
)),
|
| 219 |
]
|
| 220 |
|
| 221 |
-
#
|
| 222 |
-
|
| 223 |
-
"type": "object",
|
| 224 |
-
"properties": {
|
| 225 |
-
"thought": {"type": "string"},
|
| 226 |
-
"action": {
|
| 227 |
-
"type": "object",
|
| 228 |
-
"properties": {
|
| 229 |
-
"name": {"type": "string"},
|
| 230 |
-
"params": {"type": "object"},
|
| 231 |
-
},
|
| 232 |
-
"required": ["name"],
|
| 233 |
-
},
|
| 234 |
-
"expected_delta": {"type": "string"},
|
| 235 |
-
},
|
| 236 |
-
"required": ["thought", "action", "expected_delta"],
|
| 237 |
-
}
|
| 238 |
|
| 239 |
try:
|
| 240 |
-
result = self.llm.generate_structured(messages, schema=
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
|
| 246 |
action_data = result.get("action", {})
|
| 247 |
if isinstance(action_data, str):
|
|
|
|
| 218 |
)),
|
| 219 |
]
|
| 220 |
|
| 221 |
+
# Universal parsing: try structured output, fall back to robust text parser
|
| 222 |
+
from purpose_agent.robust_parser import parse_actor_response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
try:
|
| 225 |
+
result = self.llm.generate_structured(messages, schema={
|
| 226 |
+
"type": "object",
|
| 227 |
+
"properties": {
|
| 228 |
+
"thought": {"type": "string"},
|
| 229 |
+
"action": {"type": "object", "properties": {"name": {"type": "string"}, "params": {"type": "object"}}, "required": ["name"]},
|
| 230 |
+
"expected_delta": {"type": "string"},
|
| 231 |
+
},
|
| 232 |
+
"required": ["thought", "action", "expected_delta"],
|
| 233 |
+
})
|
| 234 |
+
except Exception:
|
| 235 |
+
# Structured output not available — use universal text parser
|
| 236 |
+
raw = self.llm.generate(messages, temperature=0.7, max_tokens=2000)
|
| 237 |
+
result = parse_actor_response(raw)
|
| 238 |
|
| 239 |
action_data = result.get("action", {})
|
| 240 |
if isinstance(action_data, str):
|