MCPcopy Create free account
hub / github.com/BUPT-GAMMA/MASFactory / parse_retrieval_xml

Function parse_retrieval_xml

applications/mapcoder/components/retrieval.py:58–83  ·  view source on GitHub ↗

Best-effort parse of the Retrieval Agent's XML output. Returns a `(exemplars, algorithm)` tuple. `exemplars` is a list of `{description, code, plan}` dicts (empty list if the LLM produced nothing parseable). `algorithm` is a string (empty if missing).

(content: str)

Source from the content-addressed store, hash-verified

56
57
58def parse_retrieval_xml(content: str) -> tuple[list[dict[str, str]], str]:
59 """Best-effort parse of the Retrieval Agent's XML output.
60
61 Returns a `(exemplars, algorithm)` tuple. `exemplars` is a list of
62 `{description, code, plan}` dicts (empty list if the LLM produced nothing
63 parseable). `algorithm` is a string (empty if missing).
64 """
65 if not isinstance(content, str) or not content.strip():
66 return [], ""
67
68 exemplars: list[dict[str, str]] = []
69 for block in _PROBLEM_BLOCK_RE.findall(content):
70 desc_match = _DESC_RE.search(block)
71 code_match = _CODE_RE.search(block)
72 plan_match = _PLAN_RE.search(block)
73 description = _clean(desc_match.group(1)) if desc_match else ""
74 code = _clean(code_match.group(1)) if code_match else ""
75 plan = _clean(plan_match.group(1)) if plan_match else ""
76 # Skip blocks that have nothing useful (defensive against LLM noise).
77 if not (description or code or plan):
78 continue
79 exemplars.append({"description": description, "code": code, "plan": plan})
80
81 algo_match = _ALGO_RE.search(content)
82 algorithm = _clean(algo_match.group(1)) if algo_match else ""
83 return exemplars, algorithm
84
85
86def retrieval_parser_forward(

Callers 1

retrieval_parser_forwardFunction · 0.85

Calls 1

_cleanFunction · 0.70

Tested by

no test coverage detected