Files
docker-agent/cmd/root
David Gageot 4f7d8f8d68 feat: add docker agent serve chat command (OpenAI-compatible API)
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
2026-04-27 15:46:10 +02:00
..
2026-04-17 23:28:27 +02:00
2026-03-23 10:04:02 +01:00