Skip to content

Commit 0e4c814

Browse files
committed
Implement ACP
Signed-off-by: Djordje Lukic <[email protected]>
1 parent 54cf0cf commit 0e4c814

File tree

10 files changed

+904
-126
lines changed

10 files changed

+904
-126
lines changed

cmd/root/acp.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package root
2+
3+
import (
4+
"log/slog"
5+
"os"
6+
7+
acpsdk "github.com/coder/acp-go-sdk"
8+
"github.com/spf13/cobra"
9+
10+
"github.com/docker/cagent/pkg/acp"
11+
"github.com/docker/cagent/pkg/telemetry"
12+
)
13+
14+
// NewACPCmd creates a new acp command
15+
func NewACPCmd() *cobra.Command {
16+
cmd := &cobra.Command{
17+
Use: "acp <agent-file>",
18+
Short: "Start an ACP (Agent Client Protocol) server",
19+
Long: `Start an ACP server that exposes the agent via the Agent Client Protocol`,
20+
Args: cobra.ExactArgs(1),
21+
RunE: func(cmd *cobra.Command, args []string) error {
22+
telemetry.TrackCommand("acp", args)
23+
return runACP(cmd, args)
24+
},
25+
}
26+
27+
addGatewayFlags(cmd)
28+
addRuntimeConfigFlags(cmd)
29+
30+
return cmd
31+
}
32+
33+
func runACP(cmd *cobra.Command, args []string) error {
34+
ctx := cmd.Context()
35+
agentFilename := args[0]
36+
37+
slog.Debug("Starting ACP server", "agent_file", agentFilename, "debug_mode", debugMode)
38+
39+
acpAgent := acp.NewAgent(agentFilename, runConfig)
40+
conn := acpsdk.NewAgentSideConnection(acpAgent, os.Stdout, os.Stdin)
41+
conn.SetLogger(slog.Default())
42+
acpAgent.SetAgentConnection(conn)
43+
defer acpAgent.Stop(ctx)
44+
45+
slog.Debug("acp started, waiting for conn")
46+
47+
<-conn.Done()
48+
49+
return nil
50+
}

cmd/root/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func NewRootCmd() *cobra.Command {
114114
cmd.AddCommand(NewExecCmd())
115115
cmd.AddCommand(NewNewCmd())
116116
cmd.AddCommand(NewAPICmd())
117+
cmd.AddCommand(NewACPCmd())
117118
cmd.AddCommand(NewEvalCmd())
118119
cmd.AddCommand(NewPushCmd())
119120
cmd.AddCommand(NewPullCmd())

docs/USAGE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ $ cagent exec config.yaml --yolo # Run the agent once and auto-accept a
5757
$ cagent api config.yaml
5858
$ cagent api config.yaml --listen :8080
5959

60+
# ACP Server (Agent Client Protocol via stdio)
61+
$ cagent acp config.yaml # Start ACP server on stdio
62+
6063
# Other commands
6164
$ cagent new # Initialize new project
6265
$ cagent new --model openai/gpt-5-mini --max-tokens 32000 # Override max tokens during generation

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/charmbracelet/bubbletea/v2 v2.0.0-beta.4.0.20250930175933-4cafc092c5e7
1515
github.com/charmbracelet/glamour/v2 v2.0.0-20250811143442-a27abb32f018
1616
github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.3.0.20250917201909-41ff0bf215ea
17+
github.com/coder/acp-go-sdk v0.4.9
1718
github.com/dop251/goja v0.0.0-20251008123653-cf18d89f3cf6
1819
github.com/fatih/color v1.18.0
1920
github.com/goccy/go-yaml v1.18.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2
6060
github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k=
6161
github.com/clipperhouse/uax29/v2 v2.2.0 h1:ChwIKnQN3kcZteTXMgb1wztSgaU+ZemkgWdohwgs8tY=
6262
github.com/clipperhouse/uax29/v2 v2.2.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
63+
github.com/coder/acp-go-sdk v0.4.9 h1:F4sKT2up4sMqNYt6yt2L9g4MaE09VPgt3eRqDFnoY5k=
64+
github.com/coder/acp-go-sdk v0.4.9/go.mod h1:yKzM/3R9uELp4+nBAwwtkS0aN1FOFjo11CNPy37yFko=
6365
github.com/containerd/stargz-snapshotter/estargz v0.17.0 h1:+TyQIsR/zSFI1Rm31EQBwpAA1ovYgIKHy7kctL3sLcE=
6466
github.com/containerd/stargz-snapshotter/estargz v0.17.0/go.mod h1:s06tWAiJcXQo9/8AReBCIo/QxcXFZ2n4qfsRnpl71SM=
6567
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=

0 commit comments

Comments
 (0)