feat: stream LLM responses and improve agent UI

This commit is contained in:
Liang Jiaqing
2026-02-04 18:56:50 +08:00
parent 541d44567d
commit a9209daaf7
6 changed files with 140 additions and 64 deletions

View File

@@ -45,14 +45,9 @@ def agent_runner_loop(client, system_prompt, user_input, handler, tools_schema,
]
for turn in range(max_turns):
yield f"**LLM Running (Turn {turn+1}) ...**\n\n"
response = client.chat(messages=messages, tools=tools_schema)
if response.thinking: yield '<thinking>' + response.thinking + '</thinking>\n\n'
showcontent = response.content
if '</summary>' in showcontent: showcontent = showcontent.replace('</summary>', '</summary>\n\n')
if '</file_content>' in showcontent:
showcontent = re.sub(r'<file_content>\s*(.*?)\s*</file_content>', r'\n````\n<file_content>\n\1\n</file_content>\n````', showcontent, flags=re.DOTALL)
yield showcontent + '\n\n'
response_gen = client.chat(messages=messages, tools=tools_schema)
response = yield from response_gen
yield '\n\n'
if not response.tool_calls:
tool_name, args = 'no_tool', {}