MCPcopy Create free account
hub / github.com/IBM/AssetOpsBench / _parse_tool_call

Function _parse_tool_call

src/agent/plan_execute/executor.py:351–370  ·  view source on GitHub ↗

Parse LLM output into a {tool, args} dict (utility, not used in main path).

(raw: str)

Source from the content-addressed store, hash-verified

349
350
351def _parse_tool_call(raw: str) -> dict:
352 """Parse LLM output into a {tool, args} dict (utility, not used in main path)."""
353 text = raw.strip()
354 if text.startswith("```"):
355 lines = text.splitlines()
356 inner = lines[1:-1] if lines[-1].strip() == "```" else lines[1:]
357 text = "\n".join(inner)
358 if text.startswith("json"):
359 text = text[4:]
360 text = text.strip()
361 try:
362 return json.loads(text)
363 except json.JSONDecodeError:
364 start, end = text.find("{"), text.rfind("}") + 1
365 if start != -1 and end > start:
366 try:
367 return json.loads(text[start:end])
368 except json.JSONDecodeError:
369 pass
370 return {"tool": None, "answer": text}

Calls 1

findMethod · 0.45