MCPcopy Create free account
hub / github.com/THUDM/AgentTuning / step

Method step

eval_heldout/hotpotQA/src/agent_arch.py:182–222  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

180 return action_type, argument
181
182 def step(self) -> None:
183
184 # agent forward
185 ret = self.forward()
186 if ret:
187 action_type, argument = ret[0], ret[1]
188 else:
189 action_type = ret
190
191 # Observe
192 self.scratchpad += f'\nObservation {self.step_n}: '
193
194 if action_type == 'Finish':
195 self.answer = argument
196 if self.is_correct():
197 self.scratchpad += 'Answer is CORRECT'
198 else:
199 self.scratchpad += 'Answer is INCORRECT'
200 self.finished = True
201 self.step_n += 1
202 return
203
204 if action_type == 'Search':
205 try:
206 self.scratchpad += format_step(self.docstore.search(argument))
207 except Exception as e:
208 print(e)
209 self.scratchpad += f'Could not find that page, please try again.'
210
211 elif action_type == 'Lookup':
212 try:
213 self.scratchpad += format_step(self.docstore.lookup(argument))
214 except ValueError:
215 self.scratchpad += f'The last page Searched was not found, so you cannot Lookup a keyword in it. Please try one of the similar pages given.'
216
217 else:
218 self.scratchpad += 'Invalid Action. Valid Actions are Lookup[<topic>] Search[<topic>] and Finish[<answer>].'
219
220 print(self.scratchpad.split('\n')[-1])
221
222 self.step_n += 1
223
224 def _build_agent_prompt(self) -> str:
225 raise NotImplementedError

Callers 1

runMethod · 0.95

Calls 5

forwardMethod · 0.95
is_correctMethod · 0.95
format_stepFunction · 0.85
searchMethod · 0.80
lookupMethod · 0.80

Tested by

no test coverage detected