MCPcopy Create free account
hub / github.com/SkyworkAI/DeepResearchAgent / parse_agent_result

Function parse_agent_result

examples/analysis.py:189–214  ·  view source on GitHub ↗

Parse agent_result that could be: 1. Direct string: "Final answer" → (reasoning="", result="Final answer") 2. JSON string: '{"reasoning": "...", "result": "..."}' → (reasoning="...", result="...")

(agent_result: Any)

Source from the content-addressed store, hash-verified

187 return score
188
189def parse_agent_result(agent_result: Any) -> Tuple[str, Any]:
190 """
191 Parse agent_result that could be:
192 1. Direct string: "Final answer" → (reasoning="", result="Final answer")
193 2. JSON string: '{"reasoning": "...", "result": "..."}' → (reasoning="...", result="...")
194 """
195 import json
196
197 # Case 1: Direct string result
198 if isinstance(agent_result, str) and not agent_result.strip().startswith('{'):
199 return "", agent_result.strip()
200
201 # Case 2: JSON string with reasoning and result
202 if isinstance(agent_result, str):
203 try:
204 parsed = json.loads(agent_result.strip())
205 if isinstance(parsed, dict):
206 reasoning = parsed.get("reasoning", "")
207 result = parsed.get("result", "")
208 return reasoning, str(result)
209 except json.JSONDecodeError:
210 # If JSON parsing fails, treat as direct string
211 return "", agent_result.strip()
212
213 # Fallback for other types
214 return "", str(agent_result) if agent_result else ""
215
216def create_optimizer(optimizer_type: str, reward_fn: Optional[Callable[[str, str, str], Any]] = None):
217 """Create optimizer instance based on type."""

Callers 3

add_task_resultMethod · 0.70
reward_fnFunction · 0.70
process_single_taskFunction · 0.70

Calls 1

getMethod · 0.45

Tested by

no test coverage detected