Skip to content

Commit d7a1cd4

Browse files
authored
Merge branch 'docker:main' into nebius-provider
2 parents 52569ed + 639741a commit d7a1cd4

70 files changed

Lines changed: 2003 additions & 1277 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/root/exec.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
package root
22

3-
import "github.com/spf13/cobra"
3+
import (
4+
"context"
5+
6+
"github.com/spf13/cobra"
7+
8+
"github.com/docker/cagent/pkg/telemetry"
9+
)
410

511
func NewExecCmd() *cobra.Command {
612
cmd := &cobra.Command{
713
Use: "exec <agent-name>",
814
Short: "Execute an agent",
915
Args: cobra.RangeArgs(1, 2),
10-
RunE: execCommand,
16+
RunE: func(cmd *cobra.Command, args []string) error {
17+
return execCommand(cmd.Context(), args)
18+
},
1119
}
1220

1321
cmd.PersistentFlags().StringVarP(&agentName, "agent", "a", "root", "Name of the agent to run")
@@ -23,3 +31,9 @@ func NewExecCmd() *cobra.Command {
2331

2432
return cmd
2533
}
34+
35+
func execCommand(ctx context.Context, args []string) error {
36+
telemetry.TrackCommand("exec", args)
37+
setupOtel(ctx)
38+
return doRunCommand(ctx, args, true)
39+
}

cmd/root/feedback.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import (
55

66
"github.com/spf13/cobra"
77

8+
"github.com/docker/cagent/pkg/feedback"
89
"github.com/docker/cagent/pkg/telemetry"
910
)
1011

11-
var FeedbackLink = "https://docker.qualtrics.com/jfe/form/SV_cNsCIg92nQemlfw"
12-
1312
// NewFeedbackCmd creates a new feedback command
1413
func NewFeedbackCmd() *cobra.Command {
1514
return &cobra.Command{
@@ -19,7 +18,7 @@ func NewFeedbackCmd() *cobra.Command {
1918
Args: cobra.NoArgs,
2019
Run: func(cmd *cobra.Command, args []string) {
2120
telemetry.TrackCommand("feedback", args)
22-
fmt.Println("Feel free to give feedback:\n", FeedbackLink)
21+
fmt.Println("Feel free to give feedback:\n", feedback.FeedbackLink)
2322
},
2423
}
2524
}

cmd/root/new.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/spf13/cobra"
99

10+
"github.com/docker/cagent/pkg/cli"
1011
"github.com/docker/cagent/pkg/creator"
1112
"github.com/docker/cagent/pkg/input"
1213
"github.com/docker/cagent/pkg/runtime"
@@ -54,19 +55,19 @@ func NewNewCmd() *cobra.Command {
5455
switch {
5556
case os.Getenv("ANTHROPIC_API_KEY") != "":
5657
modelProvider = "anthropic"
57-
fmt.Printf("%s\n\n", white("ANTHROPIC_API_KEY found, using Anthropic"))
58+
fmt.Printf("%s\n\n", cli.White("ANTHROPIC_API_KEY found, using Anthropic"))
5859
case os.Getenv("OPENAI_API_KEY") != "":
5960
modelProvider = "openai"
60-
fmt.Printf("%s\n\n", white("OPENAI_API_KEY found, using OpenAI"))
61+
fmt.Printf("%s\n\n", cli.White("OPENAI_API_KEY found, using OpenAI"))
6162
case os.Getenv("GOOGLE_API_KEY") != "":
6263
modelProvider = "google"
63-
fmt.Printf("%s\n\n", white("GOOGLE_API_KEY found, using Google"))
64+
fmt.Printf("%s\n\n", cli.White("GOOGLE_API_KEY found, using Google"))
6465
default:
6566
modelProvider = "dmr"
66-
fmt.Printf("%s\n\n", yellow("⚠️ No provider credentials found, defaulting to Docker Model Runner (DMR)"))
67+
fmt.Printf("%s\n\n", cli.Yellow("⚠️ No provider credentials found, defaulting to Docker Model Runner (DMR)"))
6768
}
6869
if modelParam == "" {
69-
fmt.Printf("%s\n\n", white("use \"--model provider/model\" to use a different model"))
70+
fmt.Printf("%s\n\n", cli.White("use \"--model provider/model\" to use a different model"))
7071
}
7172
} else {
7273
// Using Models Gateway; default to Anthropic if not specified
@@ -78,10 +79,10 @@ func NewNewCmd() *cobra.Command {
7879
if len(args) > 0 {
7980
prompt = strings.Join(args, " ")
8081
} else {
81-
fmt.Printf("%s\n", blue("------- Welcome to %s! -------", bold(AppName)))
82-
fmt.Printf("%s\n\n", white(" (Ctrl+C to exit)"))
83-
fmt.Printf("%s\n\n", blue("What should your agent/agent team do? (describe its purpose)"))
84-
fmt.Print(blue("> "))
82+
fmt.Printf("%s\n", cli.Blue("------- Welcome to %s! -------", cli.Bold(AppName)))
83+
fmt.Printf("%s\n\n", cli.White(" (Ctrl+C to exit)"))
84+
fmt.Printf("%s\n\n", cli.Blue("What should your agent/agent team do? (describe its purpose)"))
85+
fmt.Print(cli.Blue("> "))
8586

8687
var err error
8788
prompt, err = input.ReadLine(ctx, os.Stdin)
@@ -112,34 +113,34 @@ func NewNewCmd() *cobra.Command {
112113
fmt.Println()
113114
llmIsTyping = false
114115
}
115-
printToolCall(e.ToolCall)
116+
cli.PrintToolCall(e.ToolCall)
116117
case *runtime.ToolCallResponseEvent:
117118
if llmIsTyping {
118119
fmt.Println()
119120
llmIsTyping = false
120121
}
121-
printToolCallResponse(e.ToolCall, e.Response)
122+
cli.PrintToolCallResponse(e.ToolCall, e.Response)
122123
case *runtime.ErrorEvent:
123124
if llmIsTyping {
124125
fmt.Println()
125126
llmIsTyping = false
126127
}
127-
printError(fmt.Errorf("%s", e.Error))
128+
cli.PrintError(fmt.Errorf("%s", e.Error))
128129
case *runtime.MaxIterationsReachedEvent:
129130
if llmIsTyping {
130131
fmt.Println()
131132
llmIsTyping = false
132133
}
133134

134-
result := promptMaxIterationsContinue(ctx, e.MaxIterations)
135+
result := cli.PromptMaxIterationsContinue(ctx, e.MaxIterations)
135136
switch result {
136-
case ConfirmationApprove:
137-
rt.Resume(ctx, string(runtime.ResumeTypeApprove))
138-
case ConfirmationReject:
139-
rt.Resume(ctx, string(runtime.ResumeTypeReject))
137+
case cli.ConfirmationApprove:
138+
rt.Resume(ctx, runtime.ResumeTypeApprove)
139+
case cli.ConfirmationReject:
140+
rt.Resume(ctx, runtime.ResumeTypeReject)
140141
return nil
141-
case ConfirmationAbort:
142-
rt.Resume(ctx, string(runtime.ResumeTypeReject))
142+
case cli.ConfirmationAbort:
143+
rt.Resume(ctx, runtime.ResumeTypeReject)
143144
}
144145
}
145146
}

cmd/root/otel.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
const AppName = "cagent"
1717

1818
// initOTelSDK initializes OpenTelemetry SDK with OTLP exporter
19-
func initOTelSDK(ctx context.Context) (shutdown func(context.Context) error, err error) {
19+
func initOTelSDK(ctx context.Context) (err error) {
2020
res, err := resource.Merge(
2121
resource.Default(),
2222
resource.NewWithAttributes(
@@ -26,7 +26,7 @@ func initOTelSDK(ctx context.Context) (shutdown func(context.Context) error, err
2626
),
2727
)
2828
if err != nil {
29-
return nil, fmt.Errorf("failed to create resource: %w", err)
29+
return fmt.Errorf("failed to create resource: %w", err)
3030
}
3131

3232
var traceExporter trace.SpanExporter
@@ -39,7 +39,7 @@ func initOTelSDK(ctx context.Context) (shutdown func(context.Context) error, err
3939
otlptracehttp.WithInsecure(), // TODO: make configurable
4040
)
4141
if err != nil {
42-
return nil, fmt.Errorf("failed to create trace exporter: %w", err)
42+
return fmt.Errorf("failed to create trace exporter: %w", err)
4343
}
4444
}
4545

@@ -59,5 +59,10 @@ func initOTelSDK(ctx context.Context) (shutdown func(context.Context) error, err
5959
tp := trace.NewTracerProvider(tracerProviderOpts...)
6060
otel.SetTracerProvider(tp)
6161

62-
return tp.Shutdown, nil
62+
go func() {
63+
<-ctx.Done()
64+
_ = tp.Shutdown(context.Background())
65+
}()
66+
67+
return nil
6368
}

cmd/root/root.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/spf13/cobra"
1616

1717
"github.com/docker/cagent/pkg/environment"
18+
"github.com/docker/cagent/pkg/feedback"
1819
"github.com/docker/cagent/pkg/paths"
1920
"github.com/docker/cagent/pkg/telemetry"
2021
"github.com/docker/cagent/pkg/version"
@@ -83,9 +84,6 @@ func NewRootCmd() *cobra.Command {
8384
}(),
8485
})))
8586
}
86-
if cmd.DisplayName() != "exec" && os.Getenv("CAGENT_HIDE_FEEDBACK_LINK") != "1" {
87-
_, _ = cmd.OutOrStdout().Write([]byte("\nFor any feedback, please visit: " + FeedbackLink + "\n\n"))
88-
}
8987

9088
telemetry.SetGlobalTelemetryDebugMode(debugMode)
9189
return nil
@@ -146,7 +144,7 @@ For any feedback, please visit: %s
146144
We collect anonymous usage data to help improve cagent. To disable:
147145
- Set environment variable: TELEMETRY_ENABLED=false
148146
149-
`, FeedbackLink)
147+
`, feedback.FeedbackLink)
150148
_, _ = os.Stderr.WriteString(startupMsg)
151149
}
152150

0 commit comments

Comments
 (0)