agentregistry
AGENTS.md503 starsChanged 3 months agoApache-2.0View on GitHub
This document provides guidelines for both AI coding assistants (Claude, Copilot, Cursor, etc.) and human developers working on the AgentRegistry codebase. AgentRegistry is a centralized registry for securely curating, discovering, deploying, and managing agentic infrastructure including MCP (Model Context Protocol) servers, agents, and skills. Tech Stack: - Backend/CLI: Go 1.26+ - Database: PostgreSQL (accessed via pgx) - Frontend: Next.js 14 (App Router) with Tailwind CSS - CLI Framework: Cobra - API Framework: Huma (OpenAPI) Deployment/runtime code should be organized by…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
36 rules. About 0 are common, 28 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈28
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 58
Avoid introducing broad "translator" layers or catch-all shared packages when the code really belongs to one concrete runtime.
- Distinctive: line 70
No other component should have direct database access: All data operations must go through the appropriate interfaces.
- Distinctive: line 92
When to gate at the API or service layer instead: only when the operation doesn't reach the DB with a check.
- Distinctive: line 99
Prefer DB-layer gates. If you add an API-layer gate, document the reason in the handler or service comment.
- Distinctive: line 105
Every significant component must define an interface for its dependencies.
- Distinctive: line 137
Use standard Go error patterns with wrapping:
- Very specific: line 167
Always wrap errors with fmt.Errorf("context: %w", err)
- Distinctive: line 168
Use lowercase error messages (they may be wrapped)
- Distinctive: line 289
Use manual constructor injection.
- Very specific: line 322
Use Cobra for CLI commands.
- Very specific: line 346
Use the printer package (pkg/printer) for user-facing output instead of raw fmt.Printf:
- Distinctive: line 358
Use Huma for REST APIs. Huma generates OpenAPI documentation automatically.
- Very specific: line 384
Use Next.js App Router patterns with React Server Components where appropriate.
- Very specific: line 400
Use shadcn/ui components. Check ui/components/ui/ for available components.
- Distinctive: line 406
When working with this codebase, AI assistants should:
- Distinctive: line 410
Read before writing: - Always read existing code before suggesting modifications
- Distinctive: line 414
Keep changes minimal: - Only modify what's necessary for the task
- Distinctive: line 415
Check database access: - Ensure database operations go through proper layers
- Distinctive: line 419
Access database directly: - Never add direct database access outside the database layer
- Distinctive: line 420
Create god objects: - Keep components focused and small
- Distinctive: line 421
Skip error handling: - Always handle and wrap errors appropriately
- Distinctive: line 422
Add unnecessary abstractions: - Don't over-engineer solutions
- Distinctive: line 423
Ignore existing interfaces: - Use defined interfaces, don't bypass them
- Distinctive: line 424
Create new files unnecessarily: - Prefer editing existing files
- Distinctive: line 428
Check if similar functionality exists
- Distinctive: line 432
Add unit tests with mocks
- Distinctive: line 433
Add integration tests if touching database/API
- Distinctive: line 434
Update any affected documentation
- Distinctive: line 438
Write a failing test that reproduces the bug
- Distinctive: line 440
Verify the test passes
- Distinctive: line 441
Check for similar issues elsewhere
- Distinctive: line 442
Don't refactor unrelated code
- Very specific: line 448
When creating or updating a pull request in this repo, use .github/PULL_REQUEST_TEMPLATE.md as the source of truth for the PR body.
- Very specific: line 450
Use the exact top-level headings from the template (# Description, # Change Type, # Changelog).
- Very specific: line 453
When the PR is intended to close an issue, include Fixes #<issue> in the description so GitHub links the issue correctly.
- Distinctive: line 455
If an agent opens a PR without following the template, it should update the PR body before considering the task complete.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md - Development Guidelines
This document provides guidelines for both AI coding assistants (Claude, Copilot, Cursor, etc.) and human developers working on the AgentRegistry codebase.
Project Overview
AgentRegistry is a centralized registry for securely curating, discovering, deploying, and managing agentic infrastructure including MCP (Model Context Protocol) servers, agents, and skills.
Tech Stack:
- Backend/CLI: Go 1.26+
- Database: PostgreSQL (accessed via pgx)
- Frontend: Next.js 14 (App Router) with Tailwind CSS
- CLI Framework: Cobra
- API Framework: Huma (OpenAPI)
Architecture
Directory Structure
agentregistry/
├── cmd/ # Entry points only - minimal code
│ ├── cli/ # CLI entry point
│ └── server/ # Server entry point
├── pkg/ # Public, reusable packages
├── internal/ # Private implementation
│ ├── registry/ # Core registry implementation
│ │ ├── api/ # HTTP handlers
│ │ ├── database/ # Database layer (pgx)
│ │ ├── service/ # Business logic
│ │ └── ...
│ ├── cli/ # CLI command implementations
│ └── mcp/ # MCP protocol handling
├── ui/ # Next.js frontend
└── docker/ # Container images and local Compose configurationLayer Responsibilities
- cmd/ - Entry points only. Delegate immediately to pkg/ or internal/
- pkg/ - Public APIs for external consumption and reusability
- internal/ - Implementation details, not importable by external packages
- internal/registry/database/ - ONLY place that accesses the database directly
- internal/registry/service/ - Business logic, receives database interface via constructor
Runtime Ownership
Deployment/runtime code should be organized by clear ownership, not by vague helper layers:
internal/registry/runtimes/<runtime>/owns runtime behavior - concrete packages such as kubernetes should contain their adapter plus the runtime-specific materialization/apply/discovery logic they needinternal/registry/runtimes/utils/is for narrowly shared deployment utilities only - use it for adapter-shared materialization helpers, validation, name generation, and request parsing that are truly cross-runtimeinternal/registry/runtimes/types/is for shared contracts only - keep shared schemas and DTO-style runtime types here, not behavior-heavy logicinternal/registry/api/handlers/is transport only - HTTP handlers should parse requests, call services/adapters, and map errors; they should not own deployment/runtime behaviorinternal/registry/registry_app.gois the composition root - wire concrete runtime adapters here explicitly instead of hiding registration/factory behavior in handler packages
Avoid introducing broad "translator" layers or catch-all shared packages when the code really belongs to one concrete runtime. Prefer concentrated runtime packages with small, explicit shared utilities.
Critical Rules
Database Access
The database MUST only be accessed by:
- The database layer (
internal/registry/database/) - The authorizer component
No other component should have direct database access. All data operations must go through the appropriate interfaces.
// CORRECT: Service receives database interface
type RegistryService struct {
db DatabaseInterface
}
func NewRegistryService(db DatabaseInterface) *RegistryService {
return &RegistryService{db: db}
}
// INCORRECT: Service creates its own database connection
type RegistryService struct {
db *pgxpool.Pool // Direct database access - DO NOT DO THIS
}Authorization
Authz is enforced at the database layer by default — every store method calls s.authz.Check(...) before the query. Services don't normally need to invoke authz themselves; the DB call fails with auth.ErrForbidden when a caller lacks permission.
When to gate at the API or service layer instead: only when the operation doesn't reach the DB with a check. Current cases:
- External runtime calls with no downstream DB write — e.g.
UndeployDeploymentandCancelDeploymenthit adapters before any DB update, so the gate has to fire in the service before the adapter call. - Admin-scope handlers with no per-resource authz — call
authz.IsRegistryAdmindirectly in the handler.
List operations intentionally skip per-row authz checks. The DB's List* methods return what matches the SQL filter; they do not invoke authz.Check per row. The AuthzProvider interface only gates single-resource operations (Check, IsRegistryAdmin) — it has no row-filter hook. Per-row visibility filtering for Lists would require a custom database.Store implementation wired in at the composition root (registry_app.go), either joining against a permissions table in SQL or calling authz.Check per row.
Prefer DB-layer gates. If you add an API-layer gate, document the reason in the handler or service comment.
See docs/auth/authz-matrix.md for the per-endpoint permission table.
Interface Design
Every significant component must define an interface for its dependencies. This enables:
- Unit testing with mocks
- Loose coupling between packages
- Clear contract definitions
// Define interfaces for dependencies
type AgentRepository interface {
GetAgent(ctx context.Context, id string) (*Agent, error)
ListAgents(ctx context.Context, opts ListOptions) ([]Agent, error)
CreateAgent(ctx context.Context, agent *Agent) error
}
// Implementation receives interface, not concrete type
type AgentService struct {
repo AgentRepository
}Single Responsibility
Each package and file should have one clear purpose. Signs of mixed responsibilities:
- Files over 500 lines
- Packages importing many unrelated dependencies
- Functions doing multiple unrelated things
Split large components into focused units.
Error Handling
Use standard Go error patterns with wrapping:
import (
"errors"
"fmt"
)
// Wrap errors with context
func (s *Service) GetAgent(ctx context.Context, id string) (*Agent, error) {
agent, err := s.repo.GetAgent(ctx, id)
if err != nil {
return nil, fmt.Errorf("getting agent %s: %w", id, err)
}
return agent, nil
}
// Check error types
if errors.Is(err, ErrNotFound) {
// handle not found
}
// Define sentinel errors for domain-specific cases
var (
ErrNotFound = errors.New("not found")
ErrUnauthorized = errors.New("unauthorized")
)Consistency requirements:
- Always wrap errors with
fmt.Errorf("context: %w", err) - Use lowercase error messages (they may be wrapped)
- Define sentinel errors for cases that callers need to check
Logging
Use the github.com/agentregistry-dev/agentregistry/pkg/logging package for structured logging. Loggers should be package scoped in most cases, but the global logger can be directly used via the slog package if necessary. logging.New keeps track of slog.LevelVar to allow log levels to be changed at runtime via the /logging HTTP endpoint, so calling logging.New* within a re-entrant function will leak memory and should be avoided. If logging.New* is invoked within a re-entrant function, the tracked leveler should be explicitly deleted by a call to logging.DeleteLeveler("component-name") before the function returns.
import (
"log/slog"
"github.com/agentregistry-dev/agentregistry/pkg/logging"
)
var logger = logging.New("my-component")
// package scoped logger
logger.Info("agent created",
"agent_id", agent.ID,
"name", agent.Name,
)
// global logger
slog.Error("failed to create agent",
"error", err,
"agent_name", name,
)Testing
Requirements
The codebase needs significantly more test coverage. When adding or modifying code:
- Write unit tests with mocks for business logic
- Write table-driven tests for functions with multiple cases
- Write integration tests for database and API operations
Table-Driven Tests
func TestValidateAgentName(t *testing.T) {
tests := []struct {
name string
input string
wantErr bool
}{
{"valid name", "my-agent", false},
{"empty name", "", true},
{"too long", strings.Repeat("a", 256), true},
{"special chars", "my@agent", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := ValidateAgentName(tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("ValidateAgentName(%q) error = %v, wantErr %v",
tt.input, err, tt.wantErr)
}
})
}
}Mock-Based Unit Tests
type mockAgentRepo struct {
agents map[string]*Agent
}
func (m *mockAgentRepo) GetAgent(ctx context.Context, id string) (*Agent, error) {
if agent, ok := m.agents[id]; ok {
return agent, nil
}
return nil, ErrNotFound
}
func TestAgentService_GetAgent(t *testing.T) {
repo := &mockAgentRepo{
agents: map[string]*Agent{
"agent-1": {ID: "agent-1", Name: "Test Agent"},
},
}
svc := NewAgentService(repo)
agent, err := svc.GetAgent(context.Background(), "agent-1")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if agent.Name != "Test Agent" {
t.Errorf("got name %q, want %q", agent.Name, "Test Agent")
}
}Running Tests
# Run unit tests (no database needed)
make test-unit
# Run tests, including Postgres-backed integration tests (requires Postgres: make run-docker)
make test
# Run with coverage
make test-coverage
# Run with HTML coverage report
make test-coverage-reportDependency Injection
Use manual constructor injection. No DI frameworks.
// Define what you need
type AgentService struct {
repo AgentRepository
logger *slog.Logger
}
// Accept dependencies via constructor
func NewAgentService(repo AgentRepository, logger *slog.Logger) *AgentService {
return &AgentService{
repo: repo,
logger: logger,
}
}
// Wire up in main or initialization code
func main() {
db := database.NewPostgresDB(connString)
logger := slog.Default()
agentRepo := database.NewAgentRepository(db)
agentSvc := service.NewAgentService(agentRepo, logger)
// ...
}CLI Development
Use Cobra for CLI commands. Follow existing patterns in internal/cli/.
var agentCmd = &cobra.Command{
Use: "agent",
Short: "Manage agents",
}
var agentListCmd = &cobra.Command{
Use: "list",
Short: "List all agents",
RunE: func(cmd *cobra.Command, args []string) error {
// Implementation
return nil
},
}
func init() {
agentCmd.AddCommand(agentListCmd)
}CLI Output
Use the printer package (pkg/printer) for user-facing output instead of raw fmt.Printf:
printer.PrintSuccess("Added skill 'my-skill' to agent.yaml")
printer.PrintInfo("Processing...")
printer.PrintError("something went wrong")API Development
Use Huma for REST APIs. Huma generates OpenAPI documentation automatically.
// Define input/output types
type GetAgentInput struct {
ID string `path:"id"`
}
type AgentOutput struct {
Body Agent
}
// Register routes
huma.Get(api, "/agents/{id}", func(ctx context.Context, input *GetAgentInput) (*AgentOutput, error) {
agent, err := svc.GetAgent(ctx, input.ID)
if err != nil {
return nil, err
}
return &AgentOutput{Body: *agent}, nil
})Frontend Development
Use Next.js App Router patterns with React Server Components where appropriate.
// app/agents/page.tsx
export default async function AgentsPage() {
const agents = await fetchAgents();
return (
<div>
{agents.map(agent => (
<AgentCard key={agent.id} agent={agent} />
))}
</div>
);
}Use shadcn/ui components. Check ui/components/ui/ for available components.
AI Assistant Guidelines
When working with this codebase, AI assistants should:
Do
- Read before writing - Always read existing code before suggesting modifications
- Follow existing patterns - Match the style of surrounding code
- Add tests - Include tests for any new functionality
- Use interfaces - Define interfaces for new dependencies
- Keep changes minimal - Only modify what's necessary for the task
- Check database access - Ensure database operations go through proper layers
Don't
- Access database directly - Never add direct database access outside the database layer
- Create god objects - Keep components focused and small
- Skip error handling - Always handle and wrap errors appropriately
- Add unnecessary abstractions - Don't over-engineer solutions
- Ignore existing interfaces - Use defined interfaces, don't bypass them
- Create new files unnecessarily - Prefer editing existing files
When Adding New Features
- Check if similar functionality exists
- Identify the appropriate layer (api/service/database)
- Define interfaces for new dependencies
- Implement with proper error handling
- Add unit tests with mocks
- Add integration tests if touching database/API
- Update any affected documentation
When Fixing Bugs
- Write a failing test that reproduces the bug
- Fix the bug with minimal changes
- Verify the test passes
- Check for similar issues elsewhere
- Don't refactor unrelated code
Pull Requests
When creating or updating a pull request in this repo, use .github/PULL_REQUEST_TEMPLATE.md as the source of truth for the PR body.
- Use the exact top-level headings from the template (
# Description,# Change Type,# Changelog). The CI labeler (kgateway-dev/pr-kind-labeler) enforces the presence of a# Descriptionsection and will fail if headings use##or are missing. - Include at least one
/kind ...entry in the Change Type section. - Fill the
release-noteblock exactly as required by the template. If no release note applies, writeNONE. - When the PR is intended to close an issue, include
Fixes #<issue>in the description so GitHub links the issue correctly.
If an agent opens a PR without following the template, it should update the PR body before considering the task complete.
Code Review Checklist
- Database access only through database layer or authorizer
- New dependencies injected via constructor
- Interfaces defined for mockability
- Errors wrapped with context
- Unit tests with mocks included
- Table-driven tests for multiple cases
- No mixed responsibilities in components
- No hardcoded values that should be configurable
Quick Reference
| Task | Command |
| Build CLI | make build-cli |
| Build Server | make build-server |
| Run Unit Tests | make test-unit |
| Run all Tests | make test |
| Run Tests w/ Coverage | make test-coverage |
| Coverage HTML Report | make test-coverage-report |
| Run Linter | make lint |
| Format Code | make fmt |
| Build UI | make build-ui |
| Dev UI | make dev-ui |
| Run Docker Environment | make run-docker |
| Stop Local Environment | make down |
Related Documentation
- README.md - Project overview and quick start
- DEVELOPMENT.md - Architecture details
- CONTRIBUTING.md - Contribution guidelines
- docs/auth/authz-matrix.md - AuthZ matrix for HTTP endpoints
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

