refactor: update agent loop and tool extraction
This commit is contained in:
13
agentmain.py
13
agentmain.py
@@ -77,13 +77,15 @@ class GeneraticAgent:
|
||||
self.llmclient = self.llmclients[self.llm_no]
|
||||
self.llmclient.backend.history = lastc.backend.history
|
||||
self.llmclient.last_tools = ''
|
||||
name = self.get_llm_name().lower()
|
||||
name = self.get_llm_name(model=True)
|
||||
if 'glm' in name or 'minimax' in name or 'kimi' in name: load_tool_schema('_cn')
|
||||
else: load_tool_schema()
|
||||
def list_llms(self): return [(i, self.get_llm_name(b), i == self.llm_no) for i, b in enumerate(self.llmclients)]
|
||||
def get_llm_name(self, b=None):
|
||||
def get_llm_name(self, b=None, model=False):
|
||||
b = self.llmclient if b is None else b
|
||||
return f"{type(b.backend).__name__}/{b.backend.name}" if not isinstance(b, dict) else "BADCONFIG_MIXIN"
|
||||
if isinstance(b, dict): return 'BADCONFIG_MIXIN'
|
||||
if model: return b.backend.model.lower()
|
||||
return f"{type(b.backend).__name__}/{b.backend.name}"
|
||||
|
||||
def abort(self):
|
||||
if not self.is_running: return
|
||||
@@ -135,11 +137,10 @@ class GeneraticAgent:
|
||||
user_input = raw_query
|
||||
if source == 'feishu' and len(self.history) > 1: # 如果有历史记录且来自飞书,注入到首轮 user_input 中(支持/restore恢复上下文)
|
||||
user_input = handler._get_anchor_prompt() + f"\n\n### 用户当前消息\n{raw_query}"
|
||||
initial_user_content = None
|
||||
if 'gpt' in self.get_llm_name(model=True): handler._done_hooks.append('请确定用户任务是否完成,如未完成需要继续工具调用直到完成任务,确实需要问用户应使用ask_user工具')
|
||||
# although new handler, the **full** history is in llmclient, so it is full history!
|
||||
gen = agent_runner_loop(self.llmclient, sys_prompt, user_input,
|
||||
handler, TOOLS_SCHEMA, max_turns=40, verbose=self.verbose,
|
||||
initial_user_content=initial_user_content)
|
||||
handler, TOOLS_SCHEMA, max_turns=40, verbose=self.verbose)
|
||||
try:
|
||||
full_resp = ""; last_pos = 0
|
||||
for chunk in gen:
|
||||
|
||||
Reference in New Issue
Block a user