MCPcopy Create free account
hub / github.com/modelscope/ms-agent / run_loop

Method run_loop

projects/deep_research/v2/researcher.py:28–61  ·  view source on GitHub ↗
(self, messages: Union[List[Message], str],
                       **kwargs)

Source from the content-addressed store, hash-verified

26 super().__init__(config, tag, trust_remote_code, **kwargs)
27
28 async def run_loop(self, messages: Union[List[Message], str],
29 **kwargs) -> AsyncGenerator[Any, Any]:
30 start_ts = now_iso()
31 start_time = monotonic()
32 last_messages: List[Message] = []
33 status = 'completed'
34 try:
35 async for chunk in super().run_loop(messages=messages, **kwargs):
36 last_messages = chunk
37 yield chunk
38 except Exception:
39 status = 'error'
40 raise
41 finally:
42 end_ts = now_iso()
43 duration_s = monotonic() - start_time
44 usage = summarize_usage(last_messages)
45 record = build_timing_record(
46 event='workflow',
47 agent_tag=self.tag,
48 agent_type=self.AGENT_NAME,
49 started_at=start_ts,
50 ended_at=end_ts,
51 duration_s=duration_s,
52 status=status,
53 usage=usage,
54 extra={
55 'rounds': getattr(self.runtime, 'round', None),
56 },
57 )
58 try:
59 await append_stats(get_stats_path(self.config), record)
60 except Exception as exc:
61 logger.warning(f'Failed to write workflow stats: {exc}')
62
63 async def on_task_end(self, messages: List[Message]):
64 # Keep default behavior (callbacks + agent finished log), then dump

Callers

nothing calls this directly

Calls 6

now_isoFunction · 0.90
monotonicFunction · 0.90
summarize_usageFunction · 0.90
build_timing_recordFunction · 0.90
append_statsFunction · 0.90
get_stats_pathFunction · 0.90

Tested by

no test coverage detected