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

Method step

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

Args: tasks: stringfied list of tasks active_task_ids: list of active task ids active_agent_ids: list of active agent ids

(self, tasks: List[Task], team: List[str],**kwargs)

Source from the content-addressed store, hash-verified

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>."})
76
77 printf('TASK> Using random selection')
78 return Response(end=False,
79 raw="Error in parsing, using default random selection",
80 content=random.choice(team),
81 role='ordinator',
82 usage=outputs['usage'],
83 cost=outputs['cost']*3)

Callers 1

_task_assignMethod · 0.45

Calls 9

generateMethod · 0.95
load_leaderboardFunction · 0.90
_parseFunction · 0.90
ResponseClass · 0.90
printfFunction · 0.90
printFunction · 0.85
appendMethod · 0.80
formatMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected