Skip to content

Commit 233f403

Browse files
authored
Merge pull request #1382 from dgageot/agent-info
Add CurrentAgentInfo() to make it easier to not rely on the local runtime
2 parents 84e43b9 + c185e28 commit 233f403

6 files changed

Lines changed: 41 additions & 24 deletions

File tree

pkg/app/app.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (a *App) Runtime() runtime.Runtime {
101101

102102
// CurrentAgentCommands returns the commands for the active agent
103103
func (a *App) CurrentAgentCommands(ctx context.Context) types.Commands {
104-
return a.runtime.CurrentAgentCommands(ctx)
104+
return a.runtime.CurrentAgentInfo(ctx).Commands
105105
}
106106

107107
// CurrentMCPPrompts returns the available MCP prompts for the active agent
@@ -654,13 +654,7 @@ func (a *App) mergeEvents(events []tea.Msg) []tea.Msg {
654654

655655
// ExportHTML exports the current session as a standalone HTML file.
656656
// If filename is empty, a default name based on the session title and timestamp is used.
657-
func (a *App) ExportHTML(filename string) (string, error) {
658-
// Get agent description from the runtime if available
659-
var agentDescription string
660-
if localRuntime, ok := a.runtime.(*runtime.LocalRuntime); ok {
661-
if agent := localRuntime.CurrentAgent(); agent != nil {
662-
agentDescription = agent.Description()
663-
}
664-
}
665-
return export.SessionToFile(a.session, agentDescription, filename)
657+
func (a *App) ExportHTML(ctx context.Context, filename string) (string, error) {
658+
agentInfo := a.runtime.CurrentAgentInfo(ctx)
659+
return export.SessionToFile(a.session, agentInfo.Description, filename)
666660
}

pkg/runtime/commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func ResolveCommand(ctx context.Context, rt Runtime, userInput string) string {
3333
cmd, rest, _ := strings.Cut(userInput, " ")
3434
commandName := cmd[1:] // Remove leading "/"
3535

36-
command, found := rt.CurrentAgentCommands(ctx)[commandName]
36+
command, found := rt.CurrentAgentInfo(ctx).Commands[commandName]
3737
if !found {
3838
return userInput
3939
}

pkg/runtime/commands_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ type mockRuntime struct {
1717
tools []tools.Tool
1818
}
1919

20-
func (m *mockRuntime) CurrentAgentCommands(context.Context) types.Commands {
21-
return m.commands
22-
}
23-
2420
func (m *mockRuntime) CurrentAgentTools(context.Context) ([]tools.Tool, error) {
2521
return m.tools, nil
2622
}
2723
func (m *mockRuntime) CurrentAgentName() string { return "test" }
24+
func (m *mockRuntime) CurrentAgentInfo(context.Context) CurrentAgentInfo {
25+
return CurrentAgentInfo{
26+
Name: "test",
27+
Description: "test description",
28+
Commands: m.commands,
29+
}
30+
}
31+
2832
func (m *mockRuntime) SetCurrentAgent(string) error {
2933
return nil
3034
}

pkg/runtime/remote_runtime.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/docker/cagent/pkg/api"
1414
"github.com/docker/cagent/pkg/chat"
1515
"github.com/docker/cagent/pkg/config/latest"
16-
"github.com/docker/cagent/pkg/config/types"
1716
"github.com/docker/cagent/pkg/session"
1817
"github.com/docker/cagent/pkg/team"
1918
"github.com/docker/cagent/pkg/tools"
@@ -75,18 +74,22 @@ func (r *RemoteRuntime) CurrentAgentName() string {
7574
return r.currentAgent
7675
}
7776

77+
func (r *RemoteRuntime) CurrentAgentInfo(ctx context.Context) CurrentAgentInfo {
78+
cfg := r.readCurrentAgentConfig(ctx)
79+
return CurrentAgentInfo{
80+
Name: r.currentAgent,
81+
Description: cfg.Description,
82+
Commands: cfg.Commands,
83+
}
84+
}
85+
7886
// SetCurrentAgent sets the currently active agent for subsequent user messages
7987
func (r *RemoteRuntime) SetCurrentAgent(agentName string) error {
8088
r.currentAgent = agentName
8189
slog.Debug("Switched current agent (remote)", "agent", agentName)
8290
return nil
8391
}
8492

85-
// CurrentAgentCommands returns the commands for the current agent
86-
func (r *RemoteRuntime) CurrentAgentCommands(ctx context.Context) types.Commands {
87-
return r.readCurrentAgentConfig(ctx).Commands
88-
}
89-
9093
// CurrentAgentTools returns the tools for the current agent.
9194
// For remote runtime, this returns nil as tools are managed server-side.
9295
func (r *RemoteRuntime) CurrentAgentTools(_ context.Context) ([]tools.Tool, error) {

pkg/runtime/runtime.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ type ElicitationRequestHandler func(ctx context.Context, message string, schema
9090

9191
// Runtime defines the contract for runtime execution
9292
type Runtime interface {
93+
// CurrentAgentInfo returns information about the currently active agent
94+
CurrentAgentInfo(ctx context.Context) CurrentAgentInfo
9395
// CurrentAgentName returns the name of the currently active agent
9496
CurrentAgentName() string
9597
// SetCurrentAgent sets the currently active agent for subsequent user messages
9698
SetCurrentAgent(agentName string) error
97-
// CurrentAgentCommands returns the commands for the active agent
98-
CurrentAgentCommands(ctx context.Context) types.Commands
9999
// CurrentAgentTools returns the tools for the active agent
100100
CurrentAgentTools(ctx context.Context) ([]tools.Tool, error)
101101
// EmitStartupInfo emits initial agent, team, and toolset information for immediate display
@@ -118,6 +118,12 @@ type Runtime interface {
118118
Summarize(ctx context.Context, sess *session.Session, additionalPrompt string, events chan Event)
119119
}
120120

121+
type CurrentAgentInfo struct {
122+
Name string
123+
Description string
124+
Commands types.Commands
125+
}
126+
121127
type ModelStore interface {
122128
GetModel(ctx context.Context, modelID string) (*modelsdev.Model, error)
123129
}
@@ -372,6 +378,16 @@ func (r *LocalRuntime) CurrentAgentName() string {
372378
return r.currentAgent
373379
}
374380

381+
func (r *LocalRuntime) CurrentAgentInfo(context.Context) CurrentAgentInfo {
382+
currentAgent := r.CurrentAgent()
383+
384+
return CurrentAgentInfo{
385+
Name: currentAgent.Name(),
386+
Description: currentAgent.Description(),
387+
Commands: currentAgent.Commands(),
388+
}
389+
}
390+
375391
func (r *LocalRuntime) SetCurrentAgent(agentName string) error {
376392
// Validate that the agent exists in the team
377393
if _, err := r.team.Agent(agentName); err != nil {

pkg/tui/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (a *appModel) handleEvalSession(filename string) (tea.Model, tea.Cmd) {
123123
}
124124

125125
func (a *appModel) handleExportSession(filename string) (tea.Model, tea.Cmd) {
126-
exportFile, err := a.application.ExportHTML(filename)
126+
exportFile, err := a.application.ExportHTML(context.Background(), filename)
127127
if err != nil {
128128
return a, notification.ErrorCmd(fmt.Sprintf("Failed to export session: %v", err))
129129
}

0 commit comments

Comments
 (0)