Update app.py
Browse files
app.py
CHANGED
|
@@ -959,29 +959,7 @@ def execute_approved_proposals(selected_ids: list, pending_proposals: list,
|
|
| 959 |
|
| 960 |
|
| 961 |
def auto_continue_after_approval(history: list, pending_proposals: list) -> tuple:
|
| 962 |
-
"""Automatically re-enter the agent loop after approval
|
| 963 |
-
|
| 964 |
-
CHANGELOG [2026-02-01 - Claude/Opus]
|
| 965 |
-
PROBLEM: After Josh approved staged operations, results were injected into
|
| 966 |
-
chat history but Kimi never got another turn. Josh had to type something
|
| 967 |
-
like "continue" to trigger Kimi to process the tool results.
|
| 968 |
-
|
| 969 |
-
FIX: This function is chained via .then() after execute_approved_proposals.
|
| 970 |
-
It sends a synthetic continuation prompt through the agent loop so Kimi
|
| 971 |
-
automatically processes the approved tool results and continues working.
|
| 972 |
-
|
| 973 |
-
We only continue if the last message in history is our injected results
|
| 974 |
-
(starts with '✅ **Approved'). This prevents infinite loops if called
|
| 975 |
-
when there's nothing to continue from.
|
| 976 |
-
|
| 977 |
-
Args:
|
| 978 |
-
history: Chat history (should contain injected results from approval)
|
| 979 |
-
pending_proposals: Current pending proposals (passed through)
|
| 980 |
-
|
| 981 |
-
Returns:
|
| 982 |
-
Same tuple shape as agent_loop so it can update the same outputs
|
| 983 |
-
"""
|
| 984 |
-
# Safety check: only continue if last message is our injected results
|
| 985 |
if not history or history[-1].get("role") != "assistant":
|
| 986 |
return (
|
| 987 |
history, "", pending_proposals,
|
|
@@ -989,17 +967,17 @@ def auto_continue_after_approval(history: list, pending_proposals: list) -> tupl
|
|
| 989 |
_stats_label_files(), _stats_label_convos()
|
| 990 |
)
|
| 991 |
|
|
|
|
| 992 |
last_msg_content = history[-1].get("content", "")
|
| 993 |
|
| 994 |
-
# Handle Gradio 6 list-of-dicts format
|
| 995 |
if isinstance(last_msg_content, list):
|
| 996 |
# Extract text from the first content block
|
| 997 |
last_msg_text = last_msg_content[0].get("text", "") if last_msg_content else ""
|
| 998 |
else:
|
| 999 |
-
last_msg_text = last_msg_content
|
| 1000 |
|
|
|
|
| 1001 |
if not last_msg_text.startswith("✅ **Approved"):
|
| 1002 |
-
|
| 1003 |
return (
|
| 1004 |
history, "", pending_proposals,
|
| 1005 |
_format_gate_choices(pending_proposals),
|
|
@@ -1007,8 +985,6 @@ def auto_continue_after_approval(history: list, pending_proposals: list) -> tupl
|
|
| 1007 |
)
|
| 1008 |
|
| 1009 |
# Re-enter the agent loop with a synthetic continuation prompt
|
| 1010 |
-
# This tells Kimi "I approved your operations, here are the results,
|
| 1011 |
-
# now keep going with whatever you were doing."
|
| 1012 |
return agent_loop(
|
| 1013 |
message="[The operations above were approved and executed. Continue with your task using these results.]",
|
| 1014 |
history=history,
|
|
|
|
| 959 |
|
| 960 |
|
| 961 |
def auto_continue_after_approval(history: list, pending_proposals: list) -> tuple:
|
| 962 |
+
"""Automatically re-enter the agent loop after approval."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 963 |
if not history or history[-1].get("role") != "assistant":
|
| 964 |
return (
|
| 965 |
history, "", pending_proposals,
|
|
|
|
| 967 |
_stats_label_files(), _stats_label_convos()
|
| 968 |
)
|
| 969 |
|
| 970 |
+
# Gradio 6 sends content as a list of blocks. We must safely extract the text string.
|
| 971 |
last_msg_content = history[-1].get("content", "")
|
| 972 |
|
|
|
|
| 973 |
if isinstance(last_msg_content, list):
|
| 974 |
# Extract text from the first content block
|
| 975 |
last_msg_text = last_msg_content[0].get("text", "") if last_msg_content else ""
|
| 976 |
else:
|
| 977 |
+
last_msg_text = str(last_msg_content)
|
| 978 |
|
| 979 |
+
# Now .startswith() will work because last_msg_text is guaranteed to be a string
|
| 980 |
if not last_msg_text.startswith("✅ **Approved"):
|
|
|
|
| 981 |
return (
|
| 982 |
history, "", pending_proposals,
|
| 983 |
_format_gate_choices(pending_proposals),
|
|
|
|
| 985 |
)
|
| 986 |
|
| 987 |
# Re-enter the agent loop with a synthetic continuation prompt
|
|
|
|
|
|
|
| 988 |
return agent_loop(
|
| 989 |
message="[The operations above were approved and executed. Continue with your task using these results.]",
|
| 990 |
history=history,
|