fix: ask_user_choice Short-Poll, Freitext-Option, Stop-Kontext-Fix
- Long-Poll durch Short-Poll ersetzt (MCP-Server pollt jede Sekunde statt einer blockierenden HTTP-Anfrage)
- Expliziter Lambda-Rückgabetyp Task<IResult> für ASP.NET Minimal API Endpoints (behebt 200 empty body Bug)
- Freitext-Option bei Choice-Buttons ("Eigene Antwort…") für freie User-Eingabe
- Stop während ask_user_choice markiert Chain als awaiting_user_choice statt stopped (Kontext bleibt erhalten)
- ask_user_choice System-Prompt-Instruktion breiter formuliert (Quiz, Multiple-Choice etc.)
- Text wird jetzt immer in DB gespeichert, auch bei ask_user_choice
- Key-Check Model auf claude-haiku-4-5 geändert
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
3e0a69e7a4
commit
92ecaf9dac
8 files changed
+184
-66
No files matched your search
@@ -217,7 +217,8 @@ def handle_memory_list(req_id, arguments):
|
||||
|
||||
|
||||
def handle_ask_user_choice(req_id, arguments):
|
||||
"""Stellt dem User eine Frage und wartet auf Antwort (long-poll)."""
|
||||
"""Stellt dem User eine Frage und wartet auf Antwort (short-poll)."""
|
||||
import time
|
||||
question = arguments.get("question", "")
|
||||
choices = arguments.get("choices", [])
|
||||
if not question:
|
||||
@@ -225,23 +226,29 @@ def handle_ask_user_choice(req_id, arguments):
|
||||
if not choices or len(choices) < 2:
|
||||
return make_result(req_id, "Fehler: Mindestens 2 choices erforderlich", True)
|
||||
|
||||
# Long-Poll: Blockiert bis der User antwortet (max 5 Min)
|
||||
# Der Backend-Endpoint /api/internal/ask-user-choice blockiert selbst
|
||||
result = api_call_long("ask-user-choice", {"sessionId": SESSION_ID})
|
||||
choice = result.get("choice", "")
|
||||
return make_result(req_id, f"User hat gewählt: {choice}")
|
||||
# Short-Poll: Jede Sekunde beim Backend nachfragen ob der User geantwortet hat
|
||||
for i in range(300): # max 5 Minuten
|
||||
try:
|
||||
result = api_call("ask-user-choice", {"sessionId": SESSION_ID})
|
||||
# 200 = Antwort vorhanden
|
||||
if "choice" in result:
|
||||
return make_result(req_id, f"User hat gewählt: {result['choice']}")
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code == 202:
|
||||
# 202 = noch ausstehend, weiter pollen
|
||||
pass
|
||||
else:
|
||||
body = ""
|
||||
try:
|
||||
body = e.read().decode("utf-8")
|
||||
except Exception:
|
||||
pass
|
||||
return make_result(req_id, f"API-Fehler {e.code}: {body}", True)
|
||||
except Exception as e:
|
||||
return make_result(req_id, f"Fehler: {str(e)}", True)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
def api_call_long(endpoint, payload):
|
||||
"""API-Call mit langem Timeout (für Long-Poll Endpoints)."""
|
||||
url = f"{API_URL}/api/internal/{endpoint}"
|
||||
data = json.dumps(payload).encode("utf-8")
|
||||
req = urllib.request.Request(url, data=data, method="POST")
|
||||
req.add_header("Content-Type", "application/json")
|
||||
if AUTH_TOKEN:
|
||||
req.add_header("X-Internal-Token", AUTH_TOKEN)
|
||||
with urllib.request.urlopen(req, timeout=330) as resp:
|
||||
return json.loads(resp.read().decode("utf-8"))
|
||||
return make_result(req_id, "Timeout – keine Auswahl getroffen (5 Minuten)", True)
|
||||
|
||||
|
||||
TOOL_HANDLERS = {
|
||||
|
||||
Reference in new issue
Block a user