Merge pull request #330 from Leiber-CivilComEngineer/fix-400-error-in-s13-background-tasks

fix 400 error in s13_background_tasks
This commit is contained in:
gui-yue
2026-05-31 15:57:15 +08:00
committed by GitHub
5 changed files with 9 additions and 14 deletions

View File

@@ -444,15 +444,14 @@ def agent_loop(messages: list, context: dict):
"tool_use_id": block.id, "tool_use_id": block.id,
"content": output}) "content": output})
# Inject background notifications + tool results in one user message # Inject tool results + background notifications in one user message
user_content = [] user_content = list(results)
bg_notifications = collect_background_results() bg_notifications = collect_background_results()
if bg_notifications: if bg_notifications:
for notif in bg_notifications: for notif in bg_notifications:
user_content.append({"type": "text", "text": notif}) user_content.append({"type": "text", "text": notif})
print(f" \033[32m[inject] {len(bg_notifications)} background " print(f" \033[32m[inject] {len(bg_notifications)} background "
f"notification(s)\033[0m") f"notification(s)\033[0m")
user_content.extend(results)
messages.append({"role": "user", "content": user_content}) messages.append({"role": "user", "content": user_content})
context = update_context(context, messages) context = update_context(context, messages)
system = get_system_prompt(context) system = get_system_prompt(context)

View File

@@ -726,13 +726,12 @@ def agent_loop(messages: list, context: dict) -> dict:
"tool_use_id": block.id, "tool_use_id": block.id,
"content": output}) "content": output})
# Merge background notifications + tool results into one user message # Merge background tool results + notifications into one user message
user_content = [] user_content = list(results)
bg_notifications = collect_background_results() bg_notifications = collect_background_results()
if bg_notifications: if bg_notifications:
for notif in bg_notifications: for notif in bg_notifications:
user_content.append({"type": "text", "text": notif}) user_content.append({"type": "text", "text": notif})
user_content.extend(results)
messages.append({"role": "user", "content": user_content}) messages.append({"role": "user", "content": user_content})
context = update_context(context, messages) context = update_context(context, messages)
system = get_system_prompt(context) system = get_system_prompt(context)

View File

@@ -887,13 +887,12 @@ def agent_loop(messages: list, context: dict):
"tool_use_id": block.id, "tool_use_id": block.id,
"content": output}) "content": output})
# Merge background notifications + tool results into one user message # Merge background tool results + notifications into one user message
user_content = [] user_content = list(results)
bg_notifications = collect_background_results() bg_notifications = collect_background_results()
if bg_notifications: if bg_notifications:
for notif in bg_notifications: for notif in bg_notifications:
user_content.append({"type": "text", "text": notif}) user_content.append({"type": "text", "text": notif})
user_content.extend(results)
messages.append({"role": "user", "content": user_content}) messages.append({"role": "user", "content": user_content})
context = update_context(context, messages) context = update_context(context, messages)
system = get_system_prompt(context) system = get_system_prompt(context)

View File

@@ -839,13 +839,12 @@ def agent_loop(messages: list, context: dict):
"tool_use_id": block.id, "tool_use_id": block.id,
"content": output}) "content": output})
# Merge background notifications + tool results into one user message # Merge background tool results + notifications into one user message
user_content = [] user_content = list(results)
bg_notifications = collect_background_results() bg_notifications = collect_background_results()
if bg_notifications: if bg_notifications:
for notif in bg_notifications: for notif in bg_notifications:
user_content.append({"type": "text", "text": notif}) user_content.append({"type": "text", "text": notif})
user_content.extend(results)
messages.append({"role": "user", "content": user_content}) messages.append({"role": "user", "content": user_content})
context = update_context(context, messages) context = update_context(context, messages)
system = get_system_prompt(context) system = get_system_prompt(context)

View File

@@ -1872,10 +1872,9 @@ def prepare_context(messages: list) -> list:
def build_user_content(results: list[dict]) -> list[dict]: def build_user_content(results: list[dict]) -> list[dict]:
# Tool results and completed background notifications are both returned to # Tool results and completed background notifications are both returned to
# the model as user-side content, matching the tool_result feedback loop. # the model as user-side content, matching the tool_result feedback loop.
content = [] content = list(results)
for note in collect_background_results(): for note in collect_background_results():
content.append({"type": "text", "text": note}) content.append({"type": "text", "text": note})
content.extend(results)
return content return content