Skip to content

Commit 8f9285d

Browse files
refactor(tui): merge subagent and A2A listings into one Agents view
SubagentsView was the fourth line-identical copy of the filterable-list scaffold and mirrored the A2A wiring 1:1. One AgentsView now renders typed rows with local/a2a chips, composing the AgentReadiness and SubagentCatalog read ports at the presentation boundary, with /a2a kept as a pre-filtered alias and AgentStatusUpdateEvent still refreshing the a2a rows.
1 parent 80da0f5 commit 8f9285d

20 files changed

Lines changed: 558 additions & 887 deletions

‎internal/agent/llm_tool_service.go‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"maps"
87
"os"
9-
"slices"
108
"strings"
119

1210
sdk "github.com/inference-gateway/sdk"
@@ -154,16 +152,6 @@ func (s *LLMToolService) isA2ATool(toolName string) bool {
154152
return strings.HasPrefix(toolName, "A2A_")
155153
}
156154

157-
// allowlistRejection returns the error for a tool blocked by the subagent
158-
// allowlist, or nil when the allowlist does not block it.
159-
func (s *LLMToolService) allowlistRejection(toolName string) error {
160-
if s.allowlist == nil || s.allowlist[toolName] {
161-
return nil
162-
}
163-
allowed := strings.Join(slices.Sorted(maps.Keys(s.allowlist)), ", ")
164-
return fmt.Errorf("tool not allowed: %s is not in this subagent's allowlist (allowed: %s); do not retry this tool", toolName, allowed)
165-
}
166-
167155
// ExecuteTool executes a tool with the given arguments
168156
func (s *LLMToolService) ExecuteTool(ctx context.Context, toolCall sdk.ChatCompletionMessageToolCallFunction) (*agentdomain.ToolExecutionResult, error) {
169157
if mode, ok := agentdomain.AgentModeFromContext(ctx); ok {
@@ -175,10 +163,6 @@ func (s *LLMToolService) ExecuteTool(ctx context.Context, toolCall sdk.ChatCompl
175163
}
176164
}
177165

178-
if err := s.allowlistRejection(toolCall.Name); err != nil {
179-
return nil, err
180-
}
181-
182166
if !s.isToolEnabled(toolCall.Name) {
183167
if s.isA2ATool(toolCall.Name) {
184168
return nil, fmt.Errorf("A2A tools are not enabled")
@@ -238,10 +222,6 @@ func (s *LLMToolService) IsToolEnabled(name string) bool {
238222

239223
// ValidateTool validates tool arguments
240224
func (s *LLMToolService) ValidateTool(name string, args map[string]any) error {
241-
if err := s.allowlistRejection(name); err != nil {
242-
return err
243-
}
244-
245225
if !s.isToolEnabled(name) {
246226
if s.isA2ATool(name) {
247227
return fmt.Errorf("A2A tools are not enabled")

‎internal/agent/llm_tool_service_allowlist_test.go‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package agent
22

33
import (
4-
"context"
54
"slices"
6-
"strings"
75
"testing"
86

9-
sdk "github.com/inference-gateway/sdk"
10-
117
config "github.com/inference-gateway/cli/config"
128
agentdomain "github.com/inference-gateway/cli/internal/agent/domain"
139
tools "github.com/inference-gateway/cli/internal/agent/tools"
@@ -63,19 +59,3 @@ func TestSubagentToolAllowlistIgnoresWhitespaceAndEmptyEntries(t *testing.T) {
6359
t.Fatalf("entries must be trimmed: Read=%v Grep=%v", svc.IsToolEnabled("Read"), svc.IsToolEnabled("Grep"))
6460
}
6561
}
66-
67-
// A blocked tool must return the allowlist message instead of the generic
68-
// "local tools are not enabled" so the model stops retrying the call.
69-
func TestSubagentToolAllowlistBlockedToolMessage(t *testing.T) {
70-
t.Setenv(tools.SubagentToolsEnv, "Read,Grep")
71-
svc := newAllowlistTestService(t)
72-
73-
_, err := svc.ExecuteTool(context.Background(), sdk.ChatCompletionMessageToolCallFunction{Name: "Bash", Arguments: "{}"})
74-
if err == nil || !strings.Contains(err.Error(), "not in this subagent's allowlist (allowed: Grep, Read)") {
75-
t.Fatalf("blocked tool must name the allowlist, got %v", err)
76-
}
77-
78-
if err := svc.ValidateTool("Bash", nil); err == nil || !strings.Contains(err.Error(), "not in this subagent's allowlist") {
79-
t.Fatalf("ValidateTool must use the same message, got %v", err)
80-
}
81-
}

‎internal/agent/tools/agent.go‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"os"
99
"os/exec"
1010
"path/filepath"
11-
"slices"
11+
"sort"
1212
"strconv"
1313
"strings"
1414
"sync"
@@ -683,24 +683,23 @@ func (t *AgentTool) lookupMarkdownAgent(name string) (markdownAgent, bool) {
683683
return markdownAgent{}, false
684684
}
685685

686-
// sortedMarkdownAgents returns the loaded agents in name order without
687-
// mutating the tool's slice.
688-
func (t *AgentTool) sortedMarkdownAgents() []markdownAgent {
689-
sorted := slices.Clone(t.mdAgents)
690-
slices.SortFunc(sorted, func(a, b markdownAgent) int { return strings.Compare(a.name, b.name) })
691-
return sorted
692-
}
693-
694686
// markdownAgentCatalog renders the Available agents list appended to the tool
695687
// description, or "" when no agents are loaded (description stays unchanged).
696688
func (t *AgentTool) markdownAgentCatalog() string {
697689
if len(t.mdAgents) == 0 {
698690
return ""
699691
}
692+
names := make([]string, 0, len(t.mdAgents))
693+
for _, agent := range t.mdAgents {
694+
names = append(names, agent.name)
695+
}
696+
sort.Strings(names)
697+
700698
var out strings.Builder
701699
out.WriteString("Available agents:")
702-
for _, agent := range t.sortedMarkdownAgents() {
703-
fmt.Fprintf(&out, "\n- %s: %s", agent.name, agent.description)
700+
for _, name := range names {
701+
agent, _ := t.lookupMarkdownAgent(name)
702+
fmt.Fprintf(&out, "\n- %s: %s", name, agent.description)
704703
}
705704
return out.String()
706705
}
@@ -709,9 +708,10 @@ func (t *AgentTool) markdownAgentCatalog() string {
709708
// unknown-agent error message.
710709
func (t *AgentTool) markdownAgentNames() []string {
711710
names := make([]string, 0, len(t.mdAgents))
712-
for _, agent := range t.sortedMarkdownAgents() {
711+
for _, agent := range t.mdAgents {
713712
names = append(names, agent.name)
714713
}
714+
sort.Strings(names)
715715
return names
716716
}
717717

‎internal/agent/tools/mdagent.go‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,13 @@ func resolveMarkdownAgentModel(model, path string) string {
170170

171171
// resolveMarkdownAgentTools computes the tool allowlist: an explicit `tools`
172172
// list (or the full known set when only `disallowedTools` is given) minus
173-
// unknown names and the disallowed set. A key that is set but parses to no
174-
// usable entries, or a restriction that resolves to no known tool, skips the
175-
// file; with neither key set the agent inherits the parent's tools (nil).
173+
// unknown names and the disallowed set. A restriction that resolves to no
174+
// tool is a broken definition and skips the file; with neither key set the
175+
// agent inherits the parent's tools (nil allowlist).
176176
func resolveMarkdownAgentTools(fm markdownAgentFrontmatter, path string, knownTools map[string]bool) ([]string, string) {
177177
requested := flexStringList(fm.Tools)
178-
disallowedNames := flexStringList(fm.DisallowedTools)
179-
if fm.Tools != nil && len(requested) == 0 {
180-
return nil, "`tools` was set but is not a non-empty list or comma-separated string"
181-
}
182-
if fm.DisallowedTools != nil && len(disallowedNames) == 0 {
183-
return nil, "`disallowedTools` was set but is not a non-empty list or comma-separated string"
184-
}
185178
disallowed := make(map[string]bool)
186-
for _, name := range disallowedNames {
179+
for _, name := range flexStringList(fm.DisallowedTools) {
187180
disallowed[name] = true
188181
}
189182
if requested == nil && len(disallowed) == 0 {
@@ -219,8 +212,7 @@ func resolveMarkdownAgentTools(fm markdownAgentFrontmatter, path string, knownTo
219212
}
220213

221214
// flexStringList accepts a YAML list (Gemini CLI) or a comma-separated string
222-
// (Claude Code) and returns the trimmed entries; any other shape yields nil,
223-
// which callers must reject when the key was set.
215+
// (Claude Code) and returns the trimmed entries.
224216
func flexStringList(v any) []string {
225217
switch t := v.(type) {
226218
case nil:

‎internal/agent/tools/mdagent_test.go‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,6 @@ func TestLoadMarkdownAgents_SkipsInvalidFiles(t *testing.T) {
177177
writeAgentFile(t, dir, "no-description.md", "---\nname: no-description\n---\nbody")
178178
writeAgentFile(t, dir, "all-unknown-tools.md", "---\nname: all-unknown-tools\ndescription: d\ntools: Glob, WebGrep\n---\nbody")
179179
writeAgentFile(t, dir, "empty-list.md", "---\nname: empty-list\ndescription: d\ntools: []\n---\nbody")
180-
writeAgentFile(t, dir, "empty-string-tools.md", "---\nname: empty-string-tools\ndescription: d\ntools: \"\"\n---\nbody")
181-
writeAgentFile(t, dir, "tools-map.md", "---\nname: tools-map\ndescription: d\ntools: {Read: true}\n---\nbody")
182-
writeAgentFile(t, dir, "disallowed-map.md", "---\nname: disallowed-map\ndescription: d\ndisallowedTools: {Read: true}\n---\nbody")
183180
writeAgentFile(t, dir, "disallow-all.md", "---\nname: disallow-all\ndescription: d\ntools: Read, Grep\ndisallowedTools: [Read, Grep]\n---\nbody")
184181
writeAgentFile(t, dir, "ignored.txt", "---\nname: ignored\ndescription: not markdown\n---\nbody")
185182

‎internal/container/container.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ func (c *ServiceContainer) registerDefaultCommands() {
708708
}
709709

710710
if c.config.IsAgentToolEnabled() {
711-
c.shortcutRegistry.Register(shortcuts.NewSubagentsShortcut())
711+
c.shortcutRegistry.Register(shortcuts.NewAgentsShortcut())
712712
}
713713

714714
if c.config.IsSpeechToTextEnabled() {

‎internal/presentation/shortcuts/core.go‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -561,26 +561,26 @@ func (c *A2AAgentsShortcut) Execute(ctx context.Context, args []string) (Shortcu
561561
}, nil
562562
}
563563

564-
// SubagentsShortcut shows the Markdown-defined subagent presets
565-
// (.infer/agents/*.md) and their capabilities.
566-
type SubagentsShortcut struct{}
564+
// AgentsShortcut shows every agent the chat can use: local Markdown subagent
565+
// presets (.infer/agents/*.md) and remote A2A agents.
566+
type AgentsShortcut struct{}
567567

568-
func NewSubagentsShortcut() *SubagentsShortcut {
569-
return &SubagentsShortcut{}
568+
func NewAgentsShortcut() *AgentsShortcut {
569+
return &AgentsShortcut{}
570570
}
571571

572-
func (c *SubagentsShortcut) GetName() string { return "agents" }
573-
func (c *SubagentsShortcut) GetDescription() string {
574-
return "Show configured Markdown subagents and their capabilities"
572+
func (c *AgentsShortcut) GetName() string { return "agents" }
573+
func (c *AgentsShortcut) GetDescription() string {
574+
return "Show configured agents (local presets and remote A2A)"
575575
}
576-
func (c *SubagentsShortcut) GetUsage() string { return "/agents" }
577-
func (c *SubagentsShortcut) CanExecute(args []string) bool { return len(args) == 0 }
576+
func (c *AgentsShortcut) GetUsage() string { return "/agents" }
577+
func (c *AgentsShortcut) CanExecute(args []string) bool { return len(args) == 0 }
578578

579-
func (c *SubagentsShortcut) Execute(ctx context.Context, args []string) (ShortcutResult, error) {
579+
func (c *AgentsShortcut) Execute(ctx context.Context, args []string) (ShortcutResult, error) {
580580
return ShortcutResult{
581581
Output: "",
582582
Success: true,
583-
SideEffect: SideEffectShowSubagents,
583+
SideEffect: SideEffectShowAgents,
584584
}, nil
585585
}
586586

‎internal/presentation/shortcuts/core_test.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,29 +229,29 @@ func TestA2AAgentsShortcut_Execute_OpensAgentsView(t *testing.T) {
229229
}
230230
}
231231

232-
func TestSubagentsShortcut_Execute_OpensSubagentsView(t *testing.T) {
233-
subagents := NewSubagentsShortcut()
232+
func TestAgentsShortcut_Execute_OpensAgentsView(t *testing.T) {
233+
agents := NewAgentsShortcut()
234234

235-
if subagents.GetName() != "agents" {
236-
t.Errorf("expected the /agents name, got: %q", subagents.GetName())
235+
if agents.GetName() != "agents" {
236+
t.Errorf("expected the /agents name, got: %q", agents.GetName())
237237
}
238-
if !subagents.CanExecute(nil) {
238+
if !agents.CanExecute(nil) {
239239
t.Error("expected /agents to accept no arguments")
240240
}
241-
if subagents.CanExecute([]string{"extra"}) {
241+
if agents.CanExecute([]string{"extra"}) {
242242
t.Error("expected /agents to reject arguments")
243243
}
244244

245-
res, err := subagents.Execute(context.Background(), nil)
245+
res, err := agents.Execute(context.Background(), nil)
246246
if err != nil {
247247
t.Fatalf("Execute returned error: %v", err)
248248
}
249249

250250
if res.Output != "" {
251251
t.Errorf("expected empty output so nothing is appended to the conversation, got: %q", res.Output)
252252
}
253-
if res.SideEffect != SideEffectShowSubagents {
254-
t.Errorf("expected SideEffectShowSubagents to drive the view, got: %v", res.SideEffect)
253+
if res.SideEffect != SideEffectShowAgents {
254+
t.Errorf("expected SideEffectShowAgents to drive the view, got: %v", res.SideEffect)
255255
}
256256
if !res.Success {
257257
t.Error("expected Success to be true")

‎internal/presentation/shortcuts/interfaces.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ const (
4848
SideEffectShowExplorer
4949
SideEffectShowToolsList
5050
SideEffectShowA2AAgents
51-
SideEffectShowSubagents
51+
SideEffectShowAgents
5252
)

‎internal/presentation/shortcuts/metadata.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewMetadataRegistry(cfg *config.Config) *Registry {
3232
reg.Register(NewInstallOpentaskShortcut())
3333
reg.Register(NewInitShortcut(cfg))
3434
if cfg.IsAgentToolEnabled() {
35-
reg.Register(NewSubagentsShortcut())
35+
reg.Register(NewAgentsShortcut())
3636
}
3737
if cfg.IsA2AToolsEnabled() {
3838
reg.Register(NewA2ATaskManagementShortcut(cfg))

0 commit comments

Comments
 (0)