Skip to content

Commit d33f186

Browse files
committed
Add a default agent
Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent 2aa503b commit d33f186

43 files changed

Lines changed: 957 additions & 908 deletions

Some content is hidden

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

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
!./**/*.template
55
!./**/*.go
66
!./**/*.txt
7+
!./**/*.txt
8+
!/cmd/root/default-agent.yaml

cmd/root/a2a.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ import (
1414
)
1515

1616
type a2aFlags struct {
17-
agentName string
18-
workingDir string
19-
port int
20-
runConfig config.RuntimeConfig
17+
agentName string
18+
port int
19+
runConfig config.RuntimeConfig
2120
}
2221

2322
func newA2ACmd() *cobra.Command {
@@ -36,7 +35,6 @@ func newA2ACmd() *cobra.Command {
3635
}
3736

3837
cmd.PersistentFlags().StringVarP(&flags.agentName, "agent", "a", "root", "Name of the agent to run")
39-
cmd.PersistentFlags().StringVar(&flags.workingDir, "working-dir", "", "Set the working directory for the session (applies to tools and relative paths)")
4038
cmd.PersistentFlags().IntVar(&flags.port, "port", 0, "Port to listen on (default: random available port)")
4139
addRuntimeConfigFlags(cmd, &flags.runConfig)
4240

@@ -59,14 +57,10 @@ func (f *a2aFlags) runA2ACommand(cmd *cobra.Command, args []string) error {
5957
_ = ln.Close()
6058
}()
6159

62-
if err := setupWorkingDirectory(f.workingDir); err != nil {
63-
return err
64-
}
65-
6660
agentFilename, err := agentfile.Resolve(ctx, out, args[0])
6761
if err != nil {
6862
return err
6963
}
7064

71-
return a2a.Start(ctx, out, agentFilename, f.agentName, f.runConfig, ln)
65+
return a2a.Start(ctx, out, agentFilename, f.agentName, &f.runConfig, ln)
7266
}

cmd/root/acp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (f *acpFlags) runACPCommand(cmd *cobra.Command, args []string) error {
5151

5252
slog.Debug("Starting ACP server", "agent_file", agentFilename)
5353

54-
acpAgent := acp.NewAgent(agentFilename, f.runConfig)
54+
acpAgent := acp.NewAgent(agentFilename, &f.runConfig)
5555
conn := acpsdk.NewAgentSideConnection(acpAgent, cmd.OutOrStdout(), cmd.InOrStdin())
5656
conn.SetLogger(slog.Default())
5757
acpAgent.SetAgentConnection(conn)

cmd/root/alias.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ func runAliasAddCommand(cmd *cobra.Command, args []string) error {
9999
out.Printf("Alias '%s' created successfully\n", name)
100100
out.Printf(" Alias: %s\n", name)
101101
out.Printf(" Agent: %s\n", absAgentPath)
102-
out.Printf("\nYou can now run: cagent run %s\n", name)
102+
103+
if name == "default" {
104+
out.Printf("\nYou can now run: cagent run %s (or even cagent run)\n", name)
105+
} else {
106+
out.Printf("\nYou can now run: cagent run %s\n", name)
107+
}
103108

104109
return nil
105110
}

cmd/root/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (f *apiFlags) runAPICommand(cmd *cobra.Command, args []string) error {
9595
opts = append(opts, server.WithAgentsDir(filepath.Dir(resolvedPath)))
9696
}
9797

98-
teams, err := teamloader.LoadTeams(ctx, resolvedPath, f.runConfig)
98+
teams, err := teamloader.LoadTeams(ctx, resolvedPath, &f.runConfig)
9999
if err != nil {
100100
return fmt.Errorf("failed to load teams: %w", err)
101101
}
@@ -107,7 +107,7 @@ func (f *apiFlags) runAPICommand(cmd *cobra.Command, args []string) error {
107107
}
108108
}()
109109

110-
s, err := server.New(sessionStore, f.runConfig, teams, opts...)
110+
s, err := server.New(sessionStore, &f.runConfig, teams, opts...)
111111
if err != nil {
112112
return fmt.Errorf("failed to create server: %w", err)
113113
}

cmd/root/debug.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (f *debugFlags) runDebugConfigCommand(cmd *cobra.Command, args []string) er
5656
return err
5757
}
5858

59-
cfg, err := config.LoadConfig(agentFilename, filesystem.AllowAll)
59+
cfg, err := config.LoadConfig(ctx, agentFilename, filesystem.AllowAll)
6060
if err != nil {
6161
return err
6262
}
@@ -75,7 +75,7 @@ func (f *debugFlags) runDebugToolsetsCommand(cmd *cobra.Command, args []string)
7575
return err
7676
}
7777

78-
team, err := teamloader.Load(ctx, agentFilename, f.runConfig)
78+
team, err := teamloader.Load(ctx, agentFilename, &f.runConfig)
7979
if err != nil {
8080
return err
8181
}

cmd/root/default-agent.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
agents:
2+
root:
3+
model: auto
4+
description: A helpful AI assistant
5+
welcome_message: |
6+
Hello! I'm your AI assistant. How can I help you today?
7+
instruction: |
8+
You are a knowledgeable assistant that helps users with various tasks.
9+
Be helpful, accurate, and concise in your responses.
10+
toolsets:
11+
- type: filesystem
12+
- type: shell
13+
- type: fetch

cmd/root/eval.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (f *evalFlags) runEvalCommand(cmd *cobra.Command, args []string) error {
4242
return err
4343
}
4444

45-
agents, err := teamloader.Load(cmd.Context(), agentFilename, f.runConfig)
45+
agents, err := teamloader.Load(cmd.Context(), agentFilename, &f.runConfig)
4646
if err != nil {
4747
return err
4848
}

cmd/root/flags.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func addRuntimeConfigFlags(cmd *cobra.Command, runConfig *config.RuntimeConfig)
2121
addGatewayFlags(cmd, runConfig)
2222
cmd.PersistentFlags().StringSliceVar(&runConfig.EnvFiles, "env-from-file", nil, "Set environment variables from file")
2323
cmd.PersistentFlags().BoolVar(&runConfig.GlobalCodeMode, "code-mode-tools", false, "Provide a single tool to call other tools via Javascript")
24+
cmd.PersistentFlags().StringVar(&runConfig.WorkingDir, "working-dir", "", "Set the working directory for the session (applies to tools and relative paths)")
2425
}
2526

2627
func setupWorkingDirectory(workingDir string) error {
@@ -71,6 +72,11 @@ func addGatewayFlags(cmd *cobra.Command, runConfig *config.RuntimeConfig) {
7172
// Ensure the gateway url is canonical.
7273
runConfig.ModelsGateway = canonize(runConfig.ModelsGateway)
7374

75+
// Setup working directory
76+
if err := setupWorkingDirectory(runConfig.WorkingDir); err != nil {
77+
return err
78+
}
79+
7480
// First call the original persistentPreRunE if it exists (from this command)
7581
if persistentPreRunE != nil {
7682
return persistentPreRunE(cmd, args)

cmd/root/mcp.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import (
1313
)
1414

1515
type mcpFlags struct {
16-
workingDir string
17-
runConfig config.RuntimeConfig
16+
runConfig config.RuntimeConfig
1817
}
1918

2019
func newMCPCmd() *cobra.Command {
@@ -32,7 +31,6 @@ func newMCPCmd() *cobra.Command {
3231
RunE: flags.runMCPCommand,
3332
}
3433

35-
cmd.PersistentFlags().StringVar(&flags.workingDir, "working-dir", "", "Set the working directory for the session (applies to tools and relative paths)")
3634
addRuntimeConfigFlags(cmd, &flags.runConfig)
3735

3836
return cmd
@@ -44,14 +42,10 @@ func (f *mcpFlags) runMCPCommand(cmd *cobra.Command, args []string) error {
4442
ctx := cmd.Context()
4543
out := cli.NewPrinter(io.Discard)
4644

47-
if err := setupWorkingDirectory(f.workingDir); err != nil {
48-
return err
49-
}
50-
5145
agentFilename, err := agentfile.Resolve(ctx, out, args[0])
5246
if err != nil {
5347
return err
5448
}
5549

56-
return mcp.StartMCPServer(ctx, out, agentFilename, f.runConfig)
50+
return mcp.StartMCPServer(ctx, out, agentFilename, &f.runConfig)
5751
}

0 commit comments

Comments
 (0)