Skip to content

Enhance the agents API#3761

Merged
Sayt-0 merged 1 commit into
docker:mainfrom
trungutt:api-agents-expose-commands
Jul 20, 2026
Merged

Enhance the agents API#3761
Sayt-0 merged 1 commit into
docker:mainfrom
trungutt:api-agents-expose-commands

Conversation

@trungutt

@trungutt trungutt commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Enhance the agents API.

Add a Commands []string field to api.Agent so clients can enumerate
the slash commands defined on the root of each loaded config.

Populated from cfg.Agents.First().Commands (already merged with any
UseCommands references by config.Load), sorted alphabetically, and
omitted from the JSON when empty for backward compatibility.

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

The changes are correct and well-implemented:

  • Commands []string with omitempty — older clients silently ignore the new field; newer clients pointing at an older server see an absent list. Backward-compatible by design, no coordinated release required.
  • Map iteration + slices.Sort — Go map iteration is non-deterministic; collecting keys then sorting produces a deterministic, stable API response. Correct approach.
  • Nil-vs-empty handling — when the root agent has no commands the commands variable stays nil, which omitempty omits from JSON output. No spurious empty arrays emitted to clients.
  • cfg.Agents.First() as root — correct choice for the root agent whose slash commands are the ones clients enumerate.
  • Test coverageTestServer_ListAgents exercises both the empty-commands (single-agent) and populated-commands (multi-agent) cases with a sorted assertion matching the sorted output.

@trungutt trungutt changed the title pkg/api: expose root-agent command names in /api/agents Enhance the agents API Jul 20, 2026
@trungutt
trungutt marked this pull request as ready for review July 20, 2026 15:26
@trungutt
trungutt requested a review from a team as a code owner July 20, 2026 15:26

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

The PR cleanly exposes root-agent command names in /api/agents. The implementation correctly:

  • Extracts map keys from root.Commands and sorts them deterministically with slices.Sort
  • Guards against the empty-commands case with if len(root.Commands) > 0, leaving commands as nil so the omitempty tag suppresses the field when there are no commands
  • Avoids a double call to cfg.Agents.First() by caching the result in root
  • Adds test coverage for the happy path (multi-agent config with commands, single-agent configs without)

No confirmed or likely bugs found.

@aheritier aheritier added area/api For features/issues/fixes related to the usage of the cagent API kind/feat PR adds a new feature (maps to feat:). Use on PRs only. labels Jul 20, 2026
@Sayt-0
Sayt-0 merged commit 185d64f into docker:main Jul 20, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api For features/issues/fixes related to the usage of the cagent API kind/feat PR adds a new feature (maps to feat:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants