MCPcopy Create free account
hub / github.com/HKUDS/AutoAgent / user_mode

Function user_mode

autoagent/cli.py:238–315  ·  view source on GitHub ↗
(model: str, context_variables: dict, debug: bool = True)

Source from the content-addressed store, hash-verified

236
237
238def user_mode(model: str, context_variables: dict, debug: bool = True):
239 logger = LoggerManager.get_logger()
240 console = Console()
241 system_triage_agent = get_system_triage_agent(model)
242 assert system_triage_agent.agent_teams != {}, "System Triage Agent must have agent teams"
243 messages = []
244 agent = system_triage_agent
245 agents = {system_triage_agent.name.replace(' ', '_'): system_triage_agent}
246 for agent_name in system_triage_agent.agent_teams.keys():
247 agents[agent_name.replace(' ', '_')] = system_triage_agent.agent_teams[agent_name]("placeholder").agent
248 agents["Upload_files"] = "select"
249 style = Style.from_dict({
250 'bottom-toolbar': 'bg:#333333 #ffffff',
251 })
252
253 # 创建会话
254 session = PromptSession(
255 completer=UserCompleter(agents.keys()),
256 complete_while_typing=True,
257 style=style
258 )
259 client = MetaChain(log_path=logger)
260 upload_infos = []
261 while True:
262 # query = ask_text("Tell me what you want to do:")
263 query = session.prompt(
264 'Tell me what you want to do (type "exit" to quit): ',
265 bottom_toolbar=HTML('<b>Prompt:</b> Enter <b>@</b> to mention Agents')
266 )
267 if query.strip().lower() == 'exit':
268 # logger.info('User mode completed. See you next time! :waving_hand:', color='green', title='EXIT')
269
270 logo_text = "User mode completed. See you next time! :waving_hand:"
271 console.print(Panel(logo_text, style="bold salmon1", expand=True))
272 break
273 words = query.split()
274 console.print(f"[bold green]Your request: {query}[/bold green]", end=" ")
275 for word in words:
276 if word.startswith('@') and word[1:] in agents.keys():
277 # print(f"[bold magenta]{word}[bold magenta]", end=' ')
278 agent = agents[word.replace('@', '')]
279 else:
280 # print(word, end=' ')
281 pass
282 print()
283
284 if hasattr(agent, "name"):
285 agent_name = agent.name
286 console.print(f"[bold green][bold magenta]@{agent_name}[/bold magenta] will help you, be patient...[/bold green]")
287 if len(upload_infos) > 0:
288 query = "{}\n\nUser uploaded files:\n{}".format(query, "\n".join(upload_infos))
289 messages.append({"role": "user", "content": query})
290 response = client.run(agent, messages, context_variables, debug=debug)
291 messages.extend(response.messages)
292 model_answer_raw = response.messages[-1]['content']
293
294 # attempt to parse model_answer
295 if model_answer_raw.startswith('Case resolved'):

Callers 1

mainFunction · 0.85

Calls 8

runMethod · 0.95
get_system_triage_agentFunction · 0.90
UserCompleterClass · 0.90
MetaChainClass · 0.90
select_and_copy_filesFunction · 0.90
get_loggerMethod · 0.80
from_dictMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected