mirror of
https://github.com/docker/docker-agent.git
synced 2026-11-04 10:02:15 +00:00
Expose any docker-agent agent through an OpenAI-compatible HTTP
server, so tools that already speak the Chat Completions protocol
(Open WebUI, the official `openai` SDKs, ad-hoc curl scripts, etc.)
can drive an agent without any custom integration.
Endpoints:
GET /v1/models — lists exposed agents as OpenAI models
POST /v1/chat/completions — runs the agent; supports stream: true
(Server-Sent Events) and false
The team is loaded once at startup and shared across requests; each
chat completion gets a fresh session and runtime. Tool calls and
elicitation prompts are auto-handled (this is a non-interactive
endpoint). The `model` field can pin a specific agent in a multi-
agent team, or is ignored and the team's default agent runs.
Implementation notes:
- New `cmd/root/chat.go` cobra command (default 127.0.0.1:8083,
--agent / --listen flags) wired into `cmd/root/serve.go`.
- New `pkg/chatserver` package, split into:
- server.go — Run, router, HTTP handlers, sseStream, errors
- agent.go — agentPolicy, buildSession, runAgentLoop, sessionUsage
- types.go — request/response shapes
- Reuses `openai.Model` from github.com/openai/openai-go/v3 for
/v1/models. Other OpenAI SDK response types serialise too noisily
with stdlib `encoding/json` (the SDK relies on its internal
`apijson` package which we can't import), so request/response
shapes are hand-rolled for clean output.
- Defensive event handling in runAgentLoop: ToolsApproved=true and
NonInteractive=true mean the runtime never blocks for confirmation
in normal flow, but ElicitationRequestEvent must still be answered
or the runtime would hang on its dedicated channel.
Tests cover session-building, agent-policy, error-envelope shape,
and the three early-validation paths of /v1/chat/completions via
httptest. Validated with `mise lint` (0 issues), `mise test` (all
packages green), and a curl smoke test against examples/42.yaml.
Fixes docker/docker-agent#2502
Assisted-By: docker-agent