Skip to content

feat(agent): point the agent at nested AGENTS.md files - #1392

Merged
edenreich merged 3 commits into
mainfrom
fix/issue-1385
Sep 28, 2026
Merged

edenreich merged 3 commits into
mainfrom
fix/issue-1385

Conversation

@inference-gateway-maintainer

@inference-gateway-maintainer inference-gateway-maintainer Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #1385

Summary

infer now tells the model about nested AGENTS.md files below the working directory, following the agents.md standard for subprojects (https://agents.md). The root AGENTS.md is still injected whole, exactly as before. Nested files are pointed at, not injected, and the model reads a brief with the Read tool when it works in that directory. This keeps package briefs such as internal/tools/AGENTS.md and internal/presentation/AGENTS.md reachable without growing every turn's system prompt.

Changes

  • buildAgentsMDInfo in internal/agent/utils.go injects the root AGENTS.md as before, then appends a one-line precedence rule when nested files exist: a nested AGENTS.md takes precedence over the root file for its directory, so read it before working there.
  • When the project tree (agent.context.tree_enabled) is in the prompt, it already shows where the nested files are, so only the rule is added. With the tree off, their paths are listed as well, capped at 20 entries.
  • Discovery walks up to 4 directory levels and skips hidden trees and node_modules/vendor. The walk runs in lexical order, so the system prompt stays byte-stable across turns for KV-cache reuse.
  • No config schema changes. agent.agents_md.enabled, max_lines and max_chars keep their meaning and defaults, and still cap only the root file.
  • Table-driven subtests in TestBuildAgentsMDInfo cover these cases:
    • Nested files are listed after the root and their content is not injected.
    • Only the rule is added when the project tree is shown.
    • The root stays whole when nested files exist.
    • Nested files are listed when there is no root file.
    • The listing stops at 20 entries.
    • The hidden, vendored and depth skip rules hold.
  • Documented the agent.agents_md section and the nested behavior in docs/configuration-reference.md, and updated the "Package AGENTS files" line in the root AGENTS.md.

Why pointers instead of injection

An earlier revision injected every nested file into a shared max_chars budget, nearest file first. In this repository the root file (7047 bytes) plus the two package briefs (1647 bytes) exceed the 8000 default, so the root lost its Security Gotchas tail and Config section. Pointing at the briefs keeps the root rules intact and costs one line.

Verification

  • task precommit:run passes (fmt, lint with 0 issues, markdownlint).
  • go test ./internal/agent/... -race passes.
  • infer debug agent system_prompt in this repository shows the whole root AGENTS.md with no truncation marker, then the rule line. internal/tools/: AGENTS.md and internal/presentation/: AGENTS.md appear once, in the project tree.

Docs follow-up: inference-gateway/docs#853

buildAgentsMDInfo now discovers AGENTS.md files below the working directory (up to 4 levels, hidden and vendored trees skipped) and injects them alongside the root file, each labeled with the directory it applies to. The combined text is budgeted nearest-file-first at agent.agents_md.max_chars so the file closest to the edited code keeps its instructions while shallower files are truncated or dropped.

Resolves #1385
… them

Injecting every nested brief spent the agent.agents_md.max_chars budget on
package files first and truncated the root AGENTS.md in this repository.
The root file is now injected whole as before. Nested files get a one-line
precedence rule, and their paths are listed only when the project tree is
off, since the tree already shows them. The model reads a brief when it
works in that directory.
@edenreich edenreich changed the title feat(agent): inject nested AGENTS.md briefs from subdirectories feat(agent): point the agent at nested AGENTS.md files Sep 28, 2026
@edenreich
edenreich merged commit 1e8e335 into main Sep 28, 2026
1 check passed
@edenreich
edenreich deleted the fix/issue-1385 branch September 28, 2026 23:00
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.218.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Load nested AGENTS.md files

1 participant