Repository navigation
Conversation
cff17e1 to
61c4b5a
Compare
|
Just a heads up, this is a big PR, we're gonna need some time to review and grok it |
Yes, maybe after merging the new A2A features? |
|
@deka Could you please tell me how I can test this? How can I get a UI that listens to docker-agent's ag-ui stream |
aheritier
left a comment
There was a problem hiding this comment.
Six blocking issues inline: prompt policy, request validation, thread isolation, two stream outcomes, and CLI completion.
ea43569 to
4ecb1ca
Compare
Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Decoder.More returned false on a stray closing bracket and on read errors, so a malformed body started a run and a chunked body past the size limit lost its 413. Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
The runtime ends an answer truncated by the model's token limit as a normal turn, with FinishReason=length. The stream now ends with RUN_ERROR (code length) instead of RUN_FINISHED. Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
TOOL_CALL_END only closes the argument stream: clients report a started call without a TOOL_CALL_RESULT as pending when the run succeeds. A call retracted by a provider fallback now gets a result saying it was not executed, and RUN_FINISHED is never sent with an unanswered call. Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
The session ID names the directory of large tool results, which the session-end hook removes. On a case-insensitive filesystem two threads whose IDs differ only by case shared it, while the store and the run lock told them apart. The session ID is now ag-ui-<sha256(threadId)>; events keep the wire threadId. Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
A retry skipped user_prompt_submit, so a prompt a hook had blocked reached the model, and only the last of several new user messages was checked. The new user messages now make one prompt, and a retry submits the unanswered prompt again: the runtime announces, stores and checks it like any other. Deduplication only decides which messages are new. Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
|
Thanks @aheritier 🙏 Addressed in 7aba9c2..c42c866, details in the threads. |
|
Please move this PR back to ready for review once the requested changes are addressed. |
|
@rumpl I added a demo page for that in 17bf357: |
Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Decoder.More returned false on a stray closing bracket and on read errors, so a malformed body started a run and a chunked body past the size limit lost its 413. Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
The runtime ends an answer truncated by the model's token limit as a normal turn, with FinishReason=length. The stream now ends with RUN_ERROR (code length) instead of RUN_FINISHED. Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
TOOL_CALL_END only closes the argument stream: clients report a started call without a TOOL_CALL_RESULT as pending when the run succeeds. A call retracted by a provider fallback now gets a result saying it was not executed, and RUN_FINISHED is never sent with an unanswered call. Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
The session ID names the directory of large tool results, which the session-end hook removes. On a case-insensitive filesystem two threads whose IDs differ only by case shared it, while the store and the run lock told them apart. The session ID is now ag-ui-<sha256(threadId)>; events keep the wire threadId. Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
A retry skipped user_prompt_submit, so a prompt a hook had blocked reached the model, and only the last of several new user messages was checked. The new user messages now make one prompt, and a retry submits the unanswered prompt again: the runtime announces, stores and checks it like any other. Deduplication only decides which messages are new. Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
074476a to
acdde79
Compare
aheritier
left a comment
There was a problem hiding this comment.
Four blocking issues: rejected prompts can reach the model on a later turn, batched messages can be replayed, repeated tool calls lose their results, and provider refusals are reported as success.
Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
|
Thanks @aheritier 🙏 Addressed in 73581ec..869df41, details in the threads. |
|
Thanks @deka, looks great now. Two things left:
|
Add `docker agent serve ag-ui`, the server side of the AG-UI protocol: POST /ag-ui takes a RunAgentInput and streams the run back as AG-UI events over SSE, so any AG-UI client SDK can drive an agent. - pkg/agui translates runtime events to AG-UI events (run, text, reasoning, tool call, step and custom events) with the Go SDK of ag-ui-protocol/ag-ui; the runtime is unchanged - threadId maps to the session ID; the server-side session is the source of truth and only the trailing user messages are appended - one run at a time per thread; a client disconnect cancels the run - RunAgentInput is validated before any session change; non-empty tools, state or resume are rejected rather than ignored - same auth, CORS and tool safety defaults as serve a2a Human-in-the-loop, frontend tools, shared state and attachments are left to follow-up issues. Closes docker#5066 Signed-off-by: deka <dimitri.rayer@gmail.com>
Input:
- restrict threadId to letters, digits, '.', '_' and '-': it becomes the
session ID, which names the tool-result directory removed at session end
(".." resolved to the temp dir itself)
- bound message ids, reject duplicate ids among the trailing user messages,
and stop validating the history that is discarded
Cross-site requests:
- require Content-Type: application/json (415), so a browser needs a CORS
preflight
- check the Host header on a loopback listener without a token
- honour literal origins when --cors-origin mixes literals and patterns
Run outcome:
- only the stop event ends the stream: an error the run recovered from is
sent as CUSTOM docker-agent.error before RUN_FINISHED
- a run cut short (max_iterations, budget_exceeded, hook_blocked,
loop_detected) or closed without a stop event ends with RUN_ERROR
- close open messages, tool calls and steps before RUN_ERROR
- name unnamed tool calls, and log an invalid event instead of treating it
as a client disconnect
Shutdown cancels the runs even when Serve fails on its own; the drain stays
bounded and is now documented, along with the response codes.
Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Decoder.More returned false on a stray closing bracket and on read errors, so a malformed body started a run and a chunked body past the size limit lost its 413. Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
The runtime ends an answer truncated by the model's token limit as a normal turn, with FinishReason=length. The stream now ends with RUN_ERROR (code length) instead of RUN_FINISHED. Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
TOOL_CALL_END only closes the argument stream: clients report a started call without a TOOL_CALL_RESULT as pending when the run succeeds. A call retracted by a provider fallback now gets a result saying it was not executed, and RUN_FINISHED is never sent with an unanswered call. Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
The session ID names the directory of large tool results, which the session-end hook removes. On a case-insensitive filesystem two threads whose IDs differ only by case shared it, while the store and the run lock told them apart. The session ID is now ag-ui-<sha256(threadId)>; events keep the wire threadId. Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
A retry skipped user_prompt_submit, so a prompt a hook had blocked reached the model, and only the last of several new user messages was checked. The new user messages now make one prompt, and a retry submits the unanswered prompt again: the runtime announces, stores and checks it like any other. Deduplication only decides which messages are new. Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
A one-file page using the official @ag-ui/client, showing the chat and the raw AG-UI events, with a README to build, prepare the agent and run it. Signed-off-by: deka <dimitri.rayer@gmail.com>
8000 serves the demo page and 8084 the AG-UI server. requireLocalPort keeps the same ports on the host, so the page origin matches --cors-origin. Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
Addresses review comment docker#5067 (comment). Signed-off-by: deka <dimitri.rayer@gmail.com>
869df41 to
b91787b
Compare
Closes #5066
Summary
Adds a first, deliberately small level of AG-UI support:
docker agent serve ag-ui <agent-file>|<registry-ref>implements the server side of the protocol.POST /ag-uitakes aRunAgentInputand streams the run back as AG-UI events over SSE, so any AG-UI client SDK can drive a Docker Agent agent.Step 1 is a plain chat: user text in; streamed assistant text, reasoning and server-side tool activity out. Human-in-the-loop, frontend tools, shared state and attachments are left to follow-up issues, as scoped in #5066.
What changed
cmd/root/agui.go: theserve ag-uicommand, with the flag conventions ofserve a2a(--agent,--listen(default127.0.0.1:8084),--session-db,--safety,--auth-token,--cors-origin,--insecure-no-auth, runtime flags). A non-loopback listener requires--auth-tokenor--insecure-no-auth.pkg/agui(new):translator.go: a state machine that turns runtime events into AG-UI events. The runtime is unchanged.input.go:RunAgentInputdecoding and validation at the boundary.server.go: endpoint, session mapping, per-thread run lock, SSE streaming, shutdown.ag-ui-protocol/ag-ui(sdks/community/go), so the wire format follows the specification. The SDK has no tagged release yet, sogo.modpins a pseudo-version.pkg/httpsec:OriginMatcher.Match, which checks literals and patterns together.docs/features/cli/index.md(command and flags), new guidedocs/features/ag-ui/index.md, nav entry, and a note in the HTTP 413 troubleshooting section.Behaviour
Session mapping
threadIdis the session ID (originag-ui); an unknownthreadIdcreates the session. AthreadIdthat matches a session of another origin is rejected with409and that session is left untouched (same rule as A2A context IDs).messagesare appended; the rest of the client history (system, assistant, tool) is ignored.id, so a message the thread already holds is not appended twice. A request with no new user message gets400, unless the thread still ends on a user message (its last run failed before storing any output): resending the same messages then retries it.409. Closing the connection cancels the run and releases the thread.Event mapping (as specified in the issue)
StreamStarted(root session)RUN_STARTEDStreamStopped(root session), normal stopRUN_FINISHEDStreamStopped(root session), any other stopRUN_ERROR(withcode)Error(root session)RUN_ERRORif the run then stops;CUSTOMdocker-agent.errorbeforeRUN_FINISHEDif the run recoveredAgentChoiceTEXT_MESSAGE_START/CONTENT/END, boundaries from the message IDAgentChoiceReasoningREASONING_START/REASONING_MESSAGE_START/CONTENT/END/REASONING_ENDPartialToolCallTOOL_CALL_START/TOOL_CALL_ARGSToolCall/ToolCallResponseTOOL_CALL_END/TOOL_CALL_RESULTAgentSwitchingSTEP_STARTED/STEP_FINISHED(stepName= agent name)TokenUsage,Warning,SessionTitle,ModelFallbackCUSTOM(docker-agent.<type>)The translator keeps the stream well formed for strict clients:
RUN_STARTEDalways comes first, every started message, tool call and step is ended beforeRUN_FINISHEDorRUN_ERROR, and nothing follows a terminal event. It also covers providers that do not stream tool calls, retracted tool calls (ToolCallsRetracted), unnamed tool calls, and text that resumes after a tool call.Only the stop event ends the stream, because not every runtime error ends a run (a failed compaction reports one and the loop goes on).
RUN_FINISHEDis sent for a normal stop only. A run that was cut short ends withRUN_ERROR, whosecodeiscanceled, the runtime error code, the stop reason (max_iterations,budget_exceeded,hook_blocked,loop_detected) orrun_failed. A stream that closes without a stop event is reported asRUN_ERRORtoo.Input validation
RunAgentInputis validated before any session change: invalid input gets400with{"error": "..."}, creates nothing, and a valid retry on the samethreadIdstill works. A non-emptytools,stateorresumeis rejected with a clear error rather than ignored; non-text user content is rejected too. Bodies above 8 MiB get413.threadIdstarts with a letter or digit and contains only letters, digits,.,_and-. It becomes the session ID, which names the tool-result directory thelimit_large_tool_resultshook removes at session end:..resolved to the temp directory itself.ids are bounded (256 bytes) and must be distinct among the trailing user messages. The content of the history that is discarded is not validated.Security defaults
Same as
serve a2a:restrictedtool safety unless--safetysays otherwise, bearer auth throughhttpsec.BearerAuth, CORS off unless--cors-originis set (allowed headers:Authorization,Content-Type,Accept). The session is non-interactive: a tool call the policy does not allow is denied, and an elicitation is declined, because nobody can answer over AG-UI yet.Two checks protect the default unauthenticated loopback listener from web pages the user visits:
Content-Typemust beapplication/json(415otherwise), so a cross-origin browser request needs a CORS preflight.--auth-token, a loopback listener only accepts a loopbackHost(httpsec.LoopbackHost, as inserve api), which stops DNS rebinding.--cors-originnow honours literal origins when the value mixes literals and~patterns: echo ignoresAllowOriginsonceAllowOriginFuncis set, so the function uses the newhttpsec.OriginMatcher.Match.Shutdown
The server rejects new runs with
503, closes the connections, cancels the runs in progress (also whenServefails on its own) and waits up to 10 seconds for them. A run that ignores its cancellation is abandoned so it cannot block the shutdown. Nothing is resumed at startup: the thread keeps what was stored and accepts a new run. The guide documents this.Tests
transfer_task), an error, and a client disconnect (run canceled, thread released, next run accepted).nullmessage, mistyped fields,tools/state/resume, non-text content...), then a check that nothing was stored and a valid retry works.409), a sibling thread not blocked, oversized body, auth and CORS preflight, shutdown waiting for in-flight runs, shutdown not blocked by a run that ignores its cancellation, the production entry pointRun.threadIdsuch as..is rejected and a sentinel file in a confined temp directory survives; atext/plainor form POST gets415and a foreignHostgets403with no model call and no session; a token-protected server accepts anyHost; literal, pattern and mixed--cors-originvalues.restricted,strictandbalancedthe tool is not executed, a denial result is streamed and the run finishes; a thread created underautonomousfollows the server's policy after a restart asrestricted.CUSTOM).go test -race ./pkg/agui/ ./pkg/httpsec/passes. Key behaviours were checked by disabling them and watching the matching test fail (thread lock, request cancellation, shutdown wait, origin collision, dedup, auth, body limit, elicitation decline,threadIdpattern, content-type and Host checks, CORS matching, safety policy, resume ceiling, stop-reason mapping...).Interoperability
TestInterop_SDKClientConsumesStreamdrives the server with the AG-UI Go SDK client (pkg/client/sse), decodes every frame with the SDK decoder and runsevents.ValidateSequenceon the result.@ag-ui/client1.0.5 (HttpAgent.runAgent, which applies the protocol's own event verification) consumed a multi-agent run with reasoning and a tool call, and rebuilt the expected messages (assistant tool call, tool result, reasoning, assistant text).Validation
task build: OKtask test(go test ./...with.env.test): OKgolangci-lint run,go run ./lint .,go mod tidy --diff: no finding in the files of this PR. My local golangci-lint reportserrcheckon channel receives in files this PR does not touch (cmd/root/backend_auth_test.go,pkg/sqliteutil/sqlite_test.go,pkg/tools/lifecycle/supervisor_test.go); they are pre-existing and left alone.Known gaps, not fixed here
serve a2aandserve chatbuild their CORS configuration the same way, so they still drop literal origins when--cors-originmixes literals and patterns. The fix is to useOriginMatcher.Matchthere too. The threecorsMiddlewareConfigcopies cannot move topkg/httpsec, which must not depend on echo (TestPackageDoesNotDependOnEcho).serve a2ahas noHostcheck on an unauthenticated loopback listener.largeToolResultDirtrusts the session ID; this PR validates the ID at the AG-UI boundary and leaves the hook unchanged.Notes for reviewers
/ag-uiand the default port8084(next to8082for A2A and8083for chat). Both are easy to change if you prefer other values.id:line built from the event type and timestamp to each frame. It is valid SSE and both clients ignore it.