mirror of
https://github.com/docker/docker-agent.git
synced 2026-11-04 10:02:15 +00:00
Emit a strict Zod schema per builtin tool from the parameters each toolset actually advertises, per-toolset tool-name lists with a ToolName union, and the Toolset config as a union discriminated on type, with per-type fields derived from Toolset.validate. Generation fails on JSON Schema constructs the Zod emitter doesn't support instead of widening them, and coverage tests tie the output to the registered toolset types and ToolName constants.
7.8 KiB
7.8 KiB
Project Agent Guidelines
This document provides guidance for AI agents and contributors working on the docker-agent codebase.
Code Quality Standards
- Write clean, self-documenting code with minimal comments
- Follow existing code style and patterns in the project
- Implement proper error handling and validation
- Consider edge cases and failure scenarios
- Ensure code is maintainable and extensible
Code Comments Philosophy
Comments are only added when the code's purpose or logic is not immediately
evident. Never write comments that merely restate what the code does (e.g.
// increment counter above counter++). Comments should explain why
something is done a certain way, document non-obvious edge cases, or clarify
complex algorithms that cannot be simplified further.
Keep comments short and to the point:
- Prefer a single concise line over a multi-line block
- Cut filler words, restated context, and obvious explanations
- Write terse notes, not prose — assume an experienced reader
- If a comment needs a paragraph, the code probably needs refactoring instead
Working Approach
- Use tools to gather information rather than relying on assumptions
- Examine existing code before making changes
- Grep for existing plumbing before adding a mechanism, and before calling something unavailable
- Validate all changes before considering tasks complete
- Ask clarifying questions only when truly necessary
- When possible, call independent tools concurrently — it's faster
Model Providers
When adding or changing a model provider, follow the provider implementation checklist.
Client and Session Lifetimes
- Provider clients are built per team load: once per session in
serve api, once at startup inserve a2aandserve mcp - Anything that must vary per conversation belongs in a request middleware, not in client construction
- The session ID is on the request context via
httpclient.SessionIDFromContext;chatgptAuthMiddlewareshows the shape
Validation Requirements
Before marking work as complete:
- Code builds successfully (
task build) - All tests pass (
task test) - Linter shows no new issues (
task lint) - Changes meet acceptance criteria
- Code follows project patterns and conventions
- Proper error handling is implemented
- Edge cases are considered
Development Commands
Canonical setup, commands and style guide: the contributing guide. The list below is a quick reference.
Build and Development
task build— Build the application binary (outputs to./bin/docker-agent)task test— Run Go tests (clears API keys to ensure deterministic tests)task lint— Run golangci-lint (uses.golangci.ymlconfiguration)task format— Format code using golangci-lint fmttask dev— Run lint, test, and build in paralleltask generate-ts— Regeneratesdk/typescriptafter changing types the API serves (pkg/api, sessions, config, runtime events) or builtin tools;task check-tsis the CI check
Docker and Cross-Platform Builds
task build-local— Build binary for local platform using Docker Buildxtask cross— Build binaries for multiple platforms (linux/amd64, linux/arm64, darwin/amd64, darwin/arm64, windows/amd64, windows/arm64)task build-image— Build Docker image tagged asdocker/docker-agenttask push-image— Build and push multi-platform Docker image to registry
Running docker-agent
./bin/docker-agent run <config.yaml>— Run agent with configuration (launches TUI by default)./bin/docker-agent run <config.yaml> -a <agent_name>— Run specific agent from multi-agent config./bin/docker-agent run myorg/agent:tag— Run agent directly from OCI registry./bin/docker-agent run --exec <config.yaml>— Execute agent without TUI (non-interactive)./bin/docker-agent new— Generate new agent configuration interactively./bin/docker-agent new --model openai/gpt-5— Generate with specific model./bin/docker-agent share push ./agent.yaml namespace/repo— Push agent to OCI registry./bin/docker-agent share pull namespace/repo— Pull agent from OCI registry./bin/docker agent serve mcp ./agent.yaml— Expose agents as MCP tools./bin/docker agent serve a2a <config.yaml>— Start agent as A2A server./bin/docker agent serve api— Start docker-agent API server
Debug and Development Flags
--debugor-d— Enable debug logging (logs to~/.cagent/cagent.debug.log)--log-file <path>— Specify custom debug log location--otelor-o— Enable OpenTelemetry tracing- Example:
./bin/docker-agent run config.yaml --debug --log-file ./debug.log
Testing
- Tests are located alongside source files (
*_test.go) - Run
task testto execute the full test suite - E2E tests live in the
e2e/directory - Test fixtures and data live in
testdata/subdirectories - Use
github.com/stretchr/testify/assertandrequirefor assertions - Cover edge cases and error conditions
- Mock external dependencies for unit tests
Agent Config YAML
- Agent config files follow a strict schema:
./agent-schema.json - The schema is versioned
./pkg/config/v0,./pkg/config/v1, ... packages handle older versions of the config./pkg/config/latestpackage handles the current, work-in-progress config format- When adding new features to the config, only add them to the latest config
- Older config types are frozen — do not modify them
- When adding new features to the config:
- Update
./agent-schema.jsonaccordingly - Create an example YAML that demonstrates the new feature
- Update
Git Practices
- Write clear, descriptive commit messages
- Prefer Conventional Commits format, e.g.
feat:,fix:,docs:,chore:,refactor:,test: - Make commits logical and atomic
- Group related changes together; avoid mixing unrelated changes
- Keep branches focused on single features or fixes
- Ensure your branch is up-to-date before submitting
- Sign commits with a GPG or SSH key (
git commit -S)
GitHub Actions
ci / gateis the single required status check onmain. It needs every blocking job; to make a new job blocking, add it togate.needsin.github/workflows/ci.yml— the ruleset does not change. Docs-only PRs (onlydocs/**changed) skip the Go jobs, and so does amainpush whose SHA already passed a merge-queue run;gatetreats skipped as passedreport-main-failuresruns after the test jobs on failed pushes to the canonical repository'smainbranch. It files deduplicated Bug issues using the requiredflaky-testlabel, assigns them todgageot, and throttles repeat run-link comments to once per 24 hours. The job is diagnostic and intentionally excluded fromgate.needs- Every job sets
timeout-minutes; every checkout setspersist-credentials: false. zizmor (.github/zizmor.yml) and Dependabot (.github/dependabot.yml, GitHub Actions only) keep both honest - Pin every third-party action by 40-character SHA with a
# vX.Y.Zcomment, and only to versions listed in the org allow list (docker/infra-github-allow-list,terraform/docker/main.tf);actions/*,github/*anddocker/*are allowed at any version - Every PR-triggered workflow declares a
concurrencygroup. Runs onmainand on tags are never queued or cancelled: their group includesgithub.run_id - Shared setup lives in
.github/actions/, referenced as$/.github/actions/<name>(no checkout needed):setup-go(Go, Task, per-job cache),setup-hugo,setup-buildx(Hub OIDC login and builder). Pin tool versions there, not in workflows scripts/workflow-lint.shenforces the above and runs in thelintjob