ui: keep the text the model streams before a tool call; test: gateway turn waits for the model switch
The final answer replaced the whole streamed entry, so 'I will read the file' vanished. The fake Telegram sent the follow-up turn together with the model button, so the turn could be read first (flaky test). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ba5b76f945
commit
fac5cffc6f
2 files changed
+22
-4
No files matched your search
@@ -222,6 +222,9 @@ tool_begin_cb(void *ctx, const char *name, const char *args)
|
||||
snprintf(t->tools_done[t->ntools_done++],
|
||||
sizeof(t->tools_done[0]), "%s %s", name, a);
|
||||
/* Flow inline in the thinking stream instead of a separate zone below. */
|
||||
/* the text before a tool call and the text after it are two paragraphs */
|
||||
if (t->live.len > 0 && t->live.p[t->live.len - 1] != '\n')
|
||||
(void)sp_buf_puts(&t->live, "\n\n");
|
||||
if (t->flow.len > 0 && t->flow.p[t->flow.len - 1] != '\n')
|
||||
(void)sp_buf_puts(&t->flow, "\n");
|
||||
snprintf(mark, sizeof(mark), "\n› %s %.480s\n\n", name, a);
|
||||
@@ -2612,9 +2615,22 @@ ui_turn(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
|
||||
if (rc == 0) {
|
||||
const char *ap = answer.p != NULL ? answer.p : "";
|
||||
|
||||
if (v.ans_id != 0)
|
||||
entry_set_text(s, v.ans_id, ap);
|
||||
else
|
||||
/*
|
||||
* The answer the agent returns is the last step's text. What the
|
||||
* model said before its tool calls ("I'll read the file") streamed
|
||||
* into the entry too; replacing the entry with the final text
|
||||
* would take it away. Keep the streamed text when it ends in the
|
||||
* final answer.
|
||||
*/
|
||||
if (v.ans_id != 0) {
|
||||
size_t lv = tu.live.len, la = strlen(ap);
|
||||
|
||||
if (la > 0 && lv >= la && tu.live.p != NULL &&
|
||||
memcmp(tu.live.p + lv - la, ap, la) == 0)
|
||||
entry_set_text(s, v.ans_id, tu.live.p);
|
||||
else
|
||||
entry_set_text(s, v.ans_id, ap);
|
||||
} else
|
||||
add_entry(s, "agent", ap);
|
||||
s->total_out_chars += strlen(ap);
|
||||
s->out_chars = strlen(ap);
|
||||
|
||||
@@ -112,7 +112,9 @@ class H(http.server.BaseHTTPRequestHandler):
|
||||
# run with SPLINTER_LOCALE=de)
|
||||
if "Waehle ein Modell" in text:
|
||||
add_callback("model:far")
|
||||
# and a turn afterwards: it has to go to the new endpoint
|
||||
if text.startswith("Modell: other (Provider far"):
|
||||
# only once the switch is confirmed: sent together with the
|
||||
# button, the turn could be read before the button was
|
||||
add_update("hallo")
|
||||
# /connect: one answer per question
|
||||
if "Neuer Provider" in text:
|
||||
|
||||
Reference in new issue
Block a user