Repository navigation
Conversation
f22156c to
8bb9b1a
Compare
8bb9b1a to
3f4288d
Compare
aheritier
left a comment
There was a problem hiding this comment.
8 blocking issues before merging: frontend calls can diverge from what hooks approved, and some handoff, history, and retry paths leave the client and server out of sync.
Open questions: #5119 asks for replay through the TypeScript reference client. The PR reports a manual check, but the script isn’t included; can you add a reproducible replay through the actual SDK alongside the Go interop tests?
|
Please mark this PR ready for review once you’ve addressed the requested changes. Thanks! |
8ca9c6c to
a956eff
Compare
Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
…ing targets Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
…ords Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comments docker#5122 (comment) and docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
3ffe274 to
483a3ea
Compare
|
Thanks @aheritier 🙏 Addressed in fcb2fb3..ba82849, details in the threads. |
aheritier
left a comment
There was a problem hiding this comment.
Three blocking issues remain: a frontend call can still expose arguments before redaction, upgraded threads can reuse a wire ID the client already knows, and an answer-only run can route away from the agent it should resume.
…ing targets Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
…ords Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
ba82849 to
bfc89d1
Compare
Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comments docker#5122 (comment) and docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
A malformed name the runtime repairs before dispatch is now repaired before its partial call is emitted, so a frontend call's raw arguments wait for the hooks and the client sees only the canonical name. Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
A thread stored before call records gets its calls' possible wire IDs (X, X-2, ...) reserved, so a new call reusing a runtime ID never takes an ID the client already holds. Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
|
Thanks @aheritier 🙏 Addressed in 88267fa..7a0867d, details in the threads. |
A client offers tools in RunAgentInput.tools; the model calls them like any other tool and the application runs them. Step 4 of AG-UI support (docker#5119). - The tools of a run are offered to the thread's agent (entry agent and its handoff targets), not to sub-agents. A name that is already a tool of those agents is rejected with 400. - A frontend call streams START, ARGS and END without a result; the run ends with RUN_FINISHED, outcome success and pendingToolCallIds. - The next run sends tool messages, stored as tool results (error set maps to an error result); it needs no new user message. A result may sit after its call's message rather than at the end, as @ag-ui/client places it. A pending call a run leaves unanswered gets an error result, streamed and logged. - A turn mixing a frontend call and an approval pauses on the interrupt; the resume carries the tool messages. Cancelling an expired interrupt leaves the frontend call pending unless it is answered. - The thread stores the wire IDs of its calls, so a pending call can be answered after a restart. Wire IDs are unique on the thread: a call ID the model reuses in a later run (call_0) gets a suffix, since @ag-ui/client merges calls that share an ID. Records name the agent of each call, as every agent numbers its own, and a failed run stores its calls too. - The server runs no frontend call: the safety mode neither asks, denies nor skips hooks for it. Permission deny rules and pre_tool_use hooks apply. - The dispatcher decides client calls before the other calls of a batch: a refused frontend call streams its error before an approval pauses the run, and the client gets its calls whichever call asks first. Closes docker#5119 Signed-off-by: deka <dimitri.rayer@gmail.com>
- Store frontend tool results first on resume, so a failed store leaves no grant persisted and no elicitation answer delivered, and the same resume replayed goes through. - Reject frontend tool names that collide with the agent's catalog tools or with the reserved structured output tool. - Compile tool parameter schemas at the boundary (invalid schemas and remote $refs get a 400) and accept an empty schema as no parameters, as AG-UI specifies. - Document that ask rules don't prompt for client-executed calls and that allow/ask rules skip pre_tool_use hooks for them. Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
…ing targets Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
…ords Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comments docker#5122 (comment) and docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
A manual check in examples/ag-ui/replay, pinned to @ag-ui/client 1.0.5 and run with AGUI_TS_REPLAY=1; it is skipped otherwise. The examples walk skips node_modules. Signed-off-by: deka <dimitri.rayer@gmail.com>
Signed-off-by: deka <dimitri.rayer@gmail.com>
A malformed name the runtime repairs before dispatch is now repaired before its partial call is emitted, so a frontend call's raw arguments wait for the hooks and the client sees only the canonical name. Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
A thread stored before call records gets its calls' possible wire IDs (X, X-2, ...) reserved, so a new call reusing a runtime ID never takes an ID the client already holds. Addresses review comment docker#5122 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
…calls A run that only answers client-executed calls takes up the saved routing invocation instead of starting a new one, so the calling agent's before_agent_run hook does not fire again. New user input still starts a new invocation. Addresses review comment 4801467222. Signed-off-by: deka <dimitri.rayer@gmail.com>
7a0867d to
5490758
Compare
|
@deka Sorry I'd need a bit of time for this PR |
trungutt
left a comment
There was a problem hiding this comment.
Two bugs need fixing before this can merge. Both leave a conversation permanently stuck: every request after the first failure is rejected with 400, so the user can't continue it.
1. A tool call that gets cut off breaks the conversation permanently
What happens
The app offers a tool such as pick_date, and the model starts calling it. Then the model gets cut off before it finishes. The runtime correctly throws the half-written call away, but the AG-UI server still treats it as a call the app has to answer. One of two things follows:
- The server sends
TOOL_CALL_RESULT "(retracted: the call was not executed)"for it. The client stores that as a tool message and sends it back with the next request. The server then rejects its own result with400 tool call "c1" is not pending. - Or the server lists the call in
pendingToolCallIds. The client answers it, as the spec requires, and the server rejects that answer with the same400.
The client resends its full history on every request, so every later request fails the same way, even ones that only add a new user message.
When it happens
Any of these, while the model is in the middle of a frontend tool call:
- it hits its output-token limit (
finish_reason: length); - it refuses (
finish_reason: refusal); - the provider hands the turn to another model mid-stream;
- the stream fails with a temporary error (503, overloaded, connection reset) and the runtime retries the same model;
- the primary model fails and a fallback model answers.
The first and fourth are ordinary events. The same cases with a normal server-side tool work fine, so this is new in this PR.
Reproduce
Use @ag-ui/client 1.0.5 (HttpAgent) with a scripted model. In the first run, the model streams a pick_date call, then the stream ends with finish_reason: length. Then send one more user message. It gets a 400, and so does every request after it.
Cause
The translator marks a call as a frontend call as soon as its first fragment streams (pkg/agui/translator.go:359, call.frontend = true on PartialToolCallEvent), before the runtime decides whether to dispatch it. That flag drives pendingToolCallIds in finish() and the Frontend: true record saved in ag-ui.tool-calls. matchToolResults (pkg/agui/frontend_tools.go:146-151) then rejects any result for a frontend record that has no stored result.
2. Upgrading breaks conversations started on v1.168.0–v1.170.1, even without frontend tools
What happens
serve ag-ui shipped in v1.168.0, and those versions saved no call records. Take a conversation started on one of those versions whose last turn used a sub-agent (transfer_task) that called a tool. The old server streamed the sub-agent's call and result, so the client keeps a tool message for it. After upgrading, the client's next request includes that tool message, and the server answers 400 tool call "<id>" is unknown on this thread. It does the same on every request after that.
The client doesn't need to offer any frontend tools for this to happen.
Reproduce
- Run a turn where the root agent calls
transfer_taskand the sub-agent calls a tool. - Delete the session's
ag-ui.tool-callsattribute. That leaves the session as an older version stored it. - Send the history the client holds, plus a new user message. It gets a 400.
The same thing happens when an older conversation's last turn holds a (retracted…) or (no result) result the old server streamed.
Cause
For a thread with no call records, matchToolResults falls back to checking stored (pkg/agui/frontend_tools.go:146). But stored is built from sess.OwnMessages() (:214), which leaves out sub-session results. Results that were only ever streamed and never stored are missing too.
Closes #5119: frontend tools for
serve ag-ui, step 4 of #5066 (step 1: #5067, step 2: #5087 / #5091, step 3: #5103).What changes
RunAgentInput.toolsare offered to the thread's agent (entry agent and its handoff targets), not to sub-agents or background agents. A name that is already a tool of those agents, or an invalid definition, is rejected with 400.TOOL_CALL_START,TOOL_CALL_ARGSandTOOL_CALL_ENDwith noTOOL_CALL_RESULT. Server calls in the same batch run as usual. The run then ends withRUN_FINISHED,outcome: {type: "success", pendingToolCallIds: [...]}, and the model is not called again.toolmessages with the call'stoolCallId. They are stored as tool results (errormaps to an error result), the run needs no new user message, and the model continues the turn.@ag-ui/clientputs it.call_0) gets a suffix (call_0-2).@ag-ui/clientmerges calls that share an ID, and it would otherwise leave the thread stuck on a duplicate result. Records name the agent of each call, since every agent numbers its own calls (a sub-agent'scall_0doesn't hide the root's pendingcall_0). A failed or canceled run stores its calls too, because the client keeps the results it got.pkg/runtime/toolexec):approval_source: client_executed).pre_tool_usehooks still apply, under every policy.docs/features/ag-ui/index.md: new "Frontend tools" section, plus updates to tool safety, input validation and limitations.docs/configuration/permissions/index.mdanddocs/configuration/hooks/index.md: client-executed calls.Tests
Event sequences: exact sequence for one call, two calls, an error result, and a frontend call next to a server call.
Answer placement: an answer placed before a later call's message (the reference client's order), then a new user turn after it.
Reused call IDs: three rounds through the Go reference client, in the same turn and across turns, get
c1,c1-2andc1-3, and the model gets every answer.With an interrupt: a tool approval in the same turn (answered and unanswered), a call refused before an approval, an elicitation in the same turn, and cancelling an expired interrupt.
Invalid answers: each one gets a 400, the state is unchanged and a valid retry works. A run that fails after storing results can be retried, and so can a write of the results that fails part way.
Persistence and scope: answer after a restart (SQLite store), with the call ID reused after the restart (
c1-2); a failed run whose suffixed call the client resends; a sub-agent reusing the root's call ID; reusedcall_0, policy coverage (every mode leaves the call to the client), and no frontend tools for sub-agents.Interop: the Go reference client (
ag-ui/sdks/community/go) replays the stream and its pending calls. It places results after their call's message, as@ag-ui/clientdoes.Runtime and dispatcher: unit tests for client-executed calls (
pkg/runtime/client_tools_test.go,pkg/runtime/toolexec/client_executed_test.go).Manual check against the JS reference client,
@ag-ui/client1.0.5 (HttpAgent):["c1"], the answered run finishes with "Booked", and a resend of the whole history gets a 400;The second case is committed as
examples/ag-ui/replay(pinned with a lockfile, scripted model, run by hand withAGUI_TS_REPLAY=1 go test -run TestTSReplay ./pkg/agui/, not in CI); with the wire ID suffix disabled it fails. The demo pageexamples/ag-ui/index.htmlnow offers frontend tools (pick_date,confirm,get_browser_context) and answers pending calls; checked in a browser against a scripted model, including a call left unanswered.It found two bugs, both fixed here and covered by the tests above. The client inserts a result after its call's message rather than at the end. It also merges calls that share an ID, so a per-run wire ID stuck the thread.
Mutations checked (fix disabled, test fails):
unansweredCallscounting frontend calls: the elicitation test;Checks
taskisn't installed here, so I ran the equivalent commands by hand.go build ./...passes, on the final commit like the checks below.go test ./...fails only incmd/root(TestResume*,TestOpenStore*) andpkg/programresume, with "unsafe instance path ownership or permissions" from the dev environment. The PR touches neither area.go test -racepasses onpkg/agui,pkg/runtime,pkg/sessionandpkg/runtime/toolexec.golangci-lintv2.14.0: 0 issues;go run ./lint .: no offenses;go mod tidy --diffclean;GOOS=windows go vetOK.task check-tsequivalent: no diff insdk/typescript(run before the last fixups, which change no API type).Out of scope
RUN_FINISHED. They remain follow-ups under feat: AG-UI protocol support, step 1 (serve ag-uistreaming chat) #5066.