MCPcopy Create free account
hub / github.com/Tencent/digitalhuman / StreamOrdinator

Class StreamOrdinator

SWF/src/run.py:18–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16
17@dataclass
18class StreamOrdinator(Agent):
19 leaderboards: List[str] = field(default_factory=lambda: ["IFEval", "MATH", "GPQA", "MuSR", "MMLU", "Average"])
20
21 def generate(self, messages, **kwargs):
22 if self.model_name == 'DeepSeek-R1':
23 kwargs['temperature'] = 0.5
24 return super().generate(messages, **kwargs)
25
26 def step(self, tasks: List[Task], team: List[str],**kwargs):
27 """
28 Args:
29 tasks: stringfied list of tasks
30 active_task_ids: list of active task ids
31 active_agent_ids: list of active agent ids
32 """
33 leaderboard_str = load_leaderboard(names=team, leaderboards=self.leaderboards)
34 # _extra = ['Country'] if self.culture else []
35 # if self.culture:
36 # leaderboard_str += "\nPlease note that some team member from the same country with you while some are not."
37 system_prompt = self.system.format(team=leaderboard_str, num=len(team))
38 # if self.culture:
39 # system_prompt = f"You are {self.name} from {self.origin}, {self.country}." + system_prompt
40
41 messages = [
42 {"role": "system", "content": system_prompt},
43 ]
44 if len(self.history) == 0:
45 self.history.append({"role": "user", "content": self.inputs.format(task=tasks[0].content)})
46 else:
47 assert self.history[-1]['role'] == 'user' and len(messages) % 2 == 1
48 self.history[-1]['content'] += '\n\n' + self.inputs.format(task=tasks[0].content)
49
50 messages += self.history[-7:]
51 if 'gpt-5' in self.model_name and 'chat' not in self.model_name or os.environ.get('SHORT', 'False') == 'True':
52 messages[-1]['content'] += '\n Based on the above requirement, please select one member and enclose the corresponding name in <agent> </agent>. Please **very briely** explain your reasoning (less than 500-600 words).**'
53 elif os.environ.get('SHORT','False') == 'Extreme':
54 print('=' * 100)
55 messages[-1]['content'] += '\n Based on the above requirement, please select one member and enclose the corresponding name in <agent> </agent>. You can only summarize your reasoning in **only one concise sentence**.'
56
57 print(messages[0]['content'])
58 print(messages[-1]['content'])
59 cnt = 0
60 while cnt < self.max_retry:
61 outputs: Dict = self.generate(messages)
62 try:
63 names = _parse(outputs['content'], tag='agent')
64 names = [name for name in names if name in team]
65 self.usage.append(outputs['usage'])
66 return Response(end=True,
67 raw=outputs['content'],
68 content=names[-1],
69 role='ordinator',
70 usage=outputs['usage'],
71 cost=outputs['cost'])
72 except:
73 cnt += 1
74 messages.append({"role": "assistant", "content": outputs['content']})
75 messages.append({"role": "user", "content": f"You select no valid member. Please reading the context carefully and select one from '{team}' enclosed in <agent> </agent>."})

Callers 1

_runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected