MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / parse

Method parse

src/harness/execution/response_parser.py:95–137  ·  view source on GitHub ↗

Parse an LLM message and extract all tool calls. Args: message: The message object from LLM response. Expected to have .content (str) and .tool_calls (list) attributes. Returns: ParsedResponse containing all extracted tool calls and any

(self, message: Any)

Source from the content-addressed store, hash-verified

93 self.submodule_names: Set[str] = submodule_names or set()
94
95 def parse(self, message: Any) -> ParsedResponse:
96 """Parse an LLM message and extract all tool calls.
97
98 Args:
99 message: The message object from LLM response.
100 Expected to have .content (str) and .tool_calls (list) attributes.
101
102 Returns:
103 ParsedResponse containing all extracted tool calls and any parse errors.
104 """
105 content = message.content or ""
106 tool_calls = list(message.tool_calls or [])
107
108 # Truncate to first code block if multiple are present
109 if self.enable_inline:
110 content = truncate_to_first_code_block(content)
111
112 # Check for malformed inline tools when inline parsing is enabled
113 if self.enable_inline:
114 error = detect_malformed_code_blocks(content)
115 if error:
116 return ParsedResponse(
117 content=content,
118 tool_calls=tool_calls,
119 inline_calls=[],
120 raw_bash_block=None,
121 parse_error=error,
122 )
123
124 # Extract inline calls and raw bash blocks
125 inline_calls: List[Any] = []
126 raw_bash: Optional[str] = None
127
128 if self.enable_inline:
129 raw_bash, inline_calls = self._extract_inline_calls(content)
130
131 return ParsedResponse(
132 content=content,
133 tool_calls=tool_calls,
134 inline_calls=inline_calls,
135 raw_bash_block=raw_bash,
136 parse_error=None,
137 )
138
139 def _extract_inline_calls(self, content: str) -> Tuple[Optional[str], List[Any]]:
140 """Extract inline tool calls and raw bash from content.

Calls 4

_extract_inline_callsMethod · 0.95
ParsedResponseClass · 0.85