docs: add AGENTS.md files with AI assistant guidelines#4507
docs: add AGENTS.md files with AI assistant guidelines#4507
Conversation
Adds CLAUDE.md capturing instrumentation library design principles surfaced during PR review (#4470): - Never block in New*/Wrap*/Setup* — fetch external data asynchronously - WithX options are user-facing API only; use unexported setters for internal state - Order public function params from broadest to narrowest scope - Keep implementation details out of public function signatures - Avoid repeated type assertions; assign to a local variable - Extract helpers for near-identical code blocks - Note input-scale assumptions in normalization algorithms - Always run make format before committing Also adds a brief "Instrumentation library design principles" section to CONTRIBUTING.md with a pointer to CLAUDE.md for human contributors. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 8cc6580 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files🚀 New features to boost your workflow:
|
Remove rules that are too weak to prevent recurrence at generation time: - Remove "run make format" (AI can't run tools; already in CONTRIBUTING.md) - Remove "avoid repeated type assertions" (too subtle; caught at review not generation) - Remove "input-scale assumptions" (was a reviewer question, not a design rule) Strengthen remaining rules: - Reframe parameter naming rule as "public functions must encapsulate their preconditions" — addresses the design cause, not just the naming symptom - Reframe helper extraction as "inject dependencies instead of duplicating bodies" — more actionable: accept the constructed dependency, don't duplicate the body Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
CONTRIBUTING.md is the canonical source for all contributor guidance. Move the full rules (with code examples) there so they apply to human contributors and AI assistants alike. CLAUDE.md is reduced to an operational pointer: repo layout, a summary link to the CONTRIBUTING.md Code quality section, and a pre-push reminder. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
BenchmarksBenchmark execution time: 2026-03-09 16:18:46 Comparing candidate commit 8cc6580 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 156 metrics, 8 unstable metrics.
|
- Fix Close() guideline: async work should be canceled on Close(), not awaited — users should not be blocked by background enrichment - Fix unexported setter example: SetClusterID → setClusterID Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Could we name it as Also, we might consider learning more about using Claude rules for specific knowledge: https://code.claude.com/docs/en/memory#organize-rules-with-claude%2Frules%2F |
Per reviewer suggestion, use AGENTS.md as the canonical filename (aligns with the APM DCS AI Guild initiative to standardize on AGENTS.md). CLAUDE.md is kept as a symlink for backward compatibility with Claude Code. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
I would hope we can craft this ourselves instead of having an agent do it. This is good start but it is missing a lot of things IMO |
|
Done — renamed to |
Hand-crafting is certainly an option, but best practices are evolving so quickly that having the agent generate its own instructions (and humans can confirm) is often a solid workflow. This is especially true if you're using Claude and notice it goes off the rails - you can prompt it with |
kakkoyun
left a comment
There was a problem hiding this comment.
Thanks for initializing this. DCS AI guild was planning to start this initiative.
I believe we should take a layered approach here. We should have dedicated agents files for contrib, tracer, profiler and instrumentation. They might have different concerns.
This would also solves the ownership problem of these files.
What do you think?
|
@kakkoyun I agree. The content here came from feedback I previously gave on a PR for contrib files, so we can start the “layered” approach by having this PR introduce the contrib section. The one thing I wasn’t sure about is whether this guidance should apply to both @eliottness I also agree there are other ways we could get to a more ideal state, but I still think this is a very good starting point and sets us up well for future iterations and additions. |
Replaces the minimal stub with a full AGENTS.md grounded in three research inputs: - Analysis of 383 merged PRs and ~580 review comments (past 6 months), surfacing the top recurring reviewer requests - Deep inspection of existing codebase patterns (option pattern, env var routing, contrib structure, testing conventions) - AGENTS.md best-practice research from Anthropic, OpenAI, and community sources (commands-first, under 200 lines, no duplication) Key additions: - Full commands block (make test/unit vs make test, per-package go test, go.work update step, configinverter workflow) - Lock discipline (Locked suffix, +checklocks annotations, no closures in locked regions) - Naming rules (noop vs nop, fake vs mock, reflect.Pointer) - Compile-time interface assertion requirement - Constants rule (no magic numbers) - Contrib package checklist (module path /v2 in declaration, not directory; orchestrion.yml; example_test.go; copyright headers) - Testing conventions (_test.go suffix on helpers, no bogus tests, no test-only fields on prod structs) - PR template instructions (follow .github/pull_request_template.md, ask user if context is missing) - Definition of done checklist Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
… files Move contrib- and ddtrace-specific conventions out of the root AGENTS.md into dedicated files agents can load when working in those areas: - contrib/AGENTS.md: new package checklist, library init (New*/Wrap* must not block), WithX option pattern, API parameter ordering, per-package test commands, instrumentation/env usage - ddtrace/AGENTS.md: lock discipline (checklocks, Locked suffix, no closures in locked regions), api.txt public surface tracking, checklocks.sh invocation Root AGENTS.md retains repo-wide rules: naming, constants, env var routing, performance, compile-time assertions, generated files, imports, testing conventions, PR template, definition of done. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@kakkoyun just split out the AGENTS.md files and generalized it a bit more using context from our repo docs, code conventions, recent PRs/comments, and current research from Anthropic/OpenAI It is worth mentioning that current research does not show material improvements from separate AGENTS.md when the code, instructions, and conventions are similar between packages, but it definitely shouldn't hurt |
|
/rerun |
Co-authored-by: Mikayla Toffler <[email protected]>
Co-authored-by: Mikayla Toffler <[email protected]>
There was a problem hiding this comment.
AGENTS.md best-practice research — guidance from Anthropic, OpenAI, and
community sources on what makes an effective agents file: commands first, under 200
lines per file, no content inferable from reading the code, progressive disclosure
via subdirectory files. Leans on findings in Evaluating AGENTS.md.
The study linked concluded that LLM-generated context files typically have a negative impact. So I'd argue that we should only consider human-written context files for now, which is not what is being proposed here, right?
I'm also worried that introducing AGENTS.md files into our repos will end up being append-only dumps for every issue people encounter, causing agent performance to significantly degrade over time. Who gets to decide what should be added? And more importantly, what gets removed? How do we evaluate these files?
I'd prefer to not introduce these files or to keep them minimal and human-written.
People who want more elaborate default instructions for their agents are free to maintain their own local context files.
|
Following up on what @felixge suggests, could a AGENTS.md that points to human-written docs around different matters be a compromise? I imagine some more detailed files like |
|
Skimming the paper linked in this PR (https://arxiv.org/pdf/2602.11988): the headline is basically “LLM-generated AGENTS.md tends to make agents slightly worse ( +1 to the compromise idea of “AGENTS.md points to human docs.” Given the paper’s conclusion that extra requirements can make tasks harder (and increase cost), let's keep AGENTS.md as (as suggested already):
On top of that we could rather add |
|
Seems like this is very hotly contested, so I'll close it for now |
What does this PR do?
Adds AI assistant context files at three levels of the repository, with a
CLAUDE.mdsymlink at the root for Claude Code compatibility. Also adds a Code quality section
to
CONTRIBUTING.mdwith the same rules for human contributors.AGENTS.mdcontrib/AGENTS.mdWithXoptions, API design, new package checklist, per-package testingddtrace/AGENTS.mdchecklocks),api.txtpublic surface,checklocks.shusagePackage-specific conventions live in the subdirectory closest to where they apply.
Agents load the root file always, then the nearest subdirectory file when working in
that area — so only relevant rules are in context for each task.
Motivation
AI coding assistants (Claude Code, GitHub Copilot, Codex, etc.) read
AGENTS.mdat thestart of every session. Without it, agents repeatedly make the same mistakes that show
up in PR review. Surfacing these rules upfront reduces reviewer burden.
The rules were derived from three sources:
6 months of PR review history — 383 merged PRs and ~580 review comments were
analyzed to identify the most common reviewer requests. Top themes: lock discipline,
naming consistency (
noopnotnop,fakevsmock), magic number extraction,test helper file suffixes, compile-time interface assertions, import grouping.
Codebase inspection — deep read of existing patterns across
contrib/,ddtrace/, andinternal/to ensure every rule reflects what the code actually does(option pattern, env var routing, contrib module structure, copyright headers).
AGENTS.md best-practice research — guidance from Anthropic, OpenAI, and
community sources on what makes an effective agents file: commands first, under 200
lines per file, no content inferable from reading the code, progressive disclosure
via subdirectory files. Leans on findings in Evaluating AGENTS.md.
AGENTS.mdis the cross-tool open standard (Linux Foundation).CLAUDE.mdis kept asa symlink for backward compatibility with Claude Code.
Reviewer's Checklist
make lintlocally. — N/A (documentation only)make testlocally. — N/A (documentation only)make generatelocally. — N/A (documentation only)make fix-moduleslocally. — N/A (no go.mod changes)Unsure? Have a question? Request a review!