agentloop yield turn dict marker; agentmain intercepts and tracks per-turn outputs
This commit is contained in:
1 parent
1e9ed9bc38
commit
cebd6a37c9
4 files changed
+24
-21
No files matched your search
+4
-2
@@ -39,7 +39,8 @@ def get_pretty_json(data):
|
||||
data = data.copy(); data["script"] = data["script"].replace("; ", ";\n ")
|
||||
return json.dumps(data, indent=2, ensure_ascii=False).replace('\\n', '\n')
|
||||
|
||||
def agent_runner_loop(client, system_prompt, user_input, handler, tools_schema, max_turns=40, verbose=True, initial_user_content=None):
|
||||
def agent_runner_loop(client, system_prompt, user_input, handler, tools_schema,
|
||||
max_turns=40, verbose=True, initial_user_content=None, yield_info=False):
|
||||
messages = [
|
||||
{"role": "system", "content": system_prompt},
|
||||
{"role": "user", "content": initial_user_content if initial_user_content is not None else user_input}
|
||||
@@ -49,8 +50,9 @@ def agent_runner_loop(client, system_prompt, user_input, handler, tools_schema,
|
||||
turn += 1; turnstr = f'LLM Running (Turn {turn}) ...'
|
||||
if handler.parent.task_dir: turnstr = f'Turn {turn} ...'
|
||||
if verbose: turnstr = f'**{turnstr}**'
|
||||
if yield_info: yield {'turn': turn}
|
||||
yield f"\n\n{turnstr}\n\n"
|
||||
if turn%10 == 0: client.last_tools = '' # 每10轮重置一次工具描述,避免上下文过大导致的模型性能下降
|
||||
if turn%10 == 0: client.last_tools = '' # 每10轮重置一次工具描述
|
||||
response_gen = client.chat(messages=messages, tools=tools_schema)
|
||||
if verbose:
|
||||
response = yield from response_gen
|
||||
|
||||
Reference in new issue
Block a user