MCPcopy
hub / github.com/zai-org/Open-AutoGLM / _parse_response

Method _parse_response

phone_agent/model/client.py:176–216  ·  view source on GitHub ↗

Parse the model response into thinking and action parts. Parsing rules: 1. If content contains 'finish(message=', everything before is thinking, everything from 'finish(message=' onwards is action. 2. If rule 1 doesn't apply but content contains 'do(actio

(self, content: str)

Source from the content-addressed store, hash-verified

174 )
175
176 def _parse_response(self, content: str) -> tuple[str, str]:
177 """
178 Parse the model response into thinking and action parts.
179
180 Parsing rules:
181 1. If content contains 'finish(message=', everything before is thinking,
182 everything from 'finish(message=' onwards is action.
183 2. If rule 1 doesn't apply but content contains 'do(action=',
184 everything before is thinking, everything from 'do(action=' onwards is action.
185 3. Fallback: If content contains '<answer>', use legacy parsing with XML tags.
186 4. Otherwise, return empty thinking and full content as action.
187
188 Args:
189 content: Raw response content.
190
191 Returns:
192 Tuple of (thinking, action).
193 """
194 # Rule 1: Check for finish(message=
195 if "finish(message=" in content:
196 parts = content.split("finish(message=", 1)
197 thinking = parts[0].strip()
198 action = "finish(message=" + parts[1]
199 return thinking, action
200
201 # Rule 2: Check for do(action=
202 if "do(action=" in content:
203 parts = content.split("do(action=", 1)
204 thinking = parts[0].strip()
205 action = "do(action=" + parts[1]
206 return thinking, action
207
208 # Rule 3: Fallback to legacy XML tag parsing
209 if "<answer>" in content:
210 parts = content.split("<answer>", 1)
211 thinking = parts[0].replace("<think>", "").replace("</think>", "").strip()
212 action = parts[1].replace("</answer>", "").strip()
213 return thinking, action
214
215 # Rule 4: No markers found, return content as action
216 return "", content
217
218
219class MessageBuilder:

Callers 1

requestMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected