Skip to content

feat(agent): cap rendered skills list and harden system prompt injection - #761

Merged
edenreich merged 1 commit into
mainfrom
feat/harden-context-injection
Jul 6, 2026
Merged

edenreich merged 1 commit into
mainfrom
feat/harden-context-injection

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Summary

Audit of the memory/skills context-injection path confirmed the design is sound (index/frontmatter-only, one ephemeral system message per request, no history accumulation). This PR closes the three small gaps it surfaced:

  • Cap the rendered skills list — new agent.skills.max_chars (default 4000, 0 disables, env INFER_AGENT_SKILLS_MAX_CHARS). Skills past the budget are listed by name only instead of growing the system prompt unbounded; whole entries only, never a truncated description, so every skill stays discoverable.
  • Truncate the memory index at a line boundary — the memory.max_chars cut previously left a broken half-entry in the prompt.
  • Date-only system-prompt timestamp — the minute-resolution Current date and time: line changed the system prompt every turn, invalidating provider-side prompt-prefix caching for the whole conversation. Now Current date: at day resolution; the model can run date when it needs the time.

Testing

  • New tests: TestBuildSkillsInfo_CapsRenderedList, TestBuildMemoryInfo_TruncatesAtLineBoundary; updated the timestamp assertions.
  • task test and task lint pass.
  • Verified with infer debug agent system_prompt: capped skills block, clean memory-index tail, date-only line.

Cross-repo impact

New user-facing config key agent.skills.max_chars → needs a [DOCS] issue for inference-gateway/docs (configuration reference).

- add agent.skills.max_chars (default 4000): skills past the budget are
  listed by name only instead of growing the system prompt unbounded
- truncate the injected memory index at a line boundary so no partial
  entry survives the max_chars cut
- use a date-only timestamp in the system prompt; minute resolution
  changed the prompt every turn and busted provider prompt-prefix caching
@edenreich

Copy link
Copy Markdown
Contributor Author

Docs follow-up filed: inference-gateway/docs#352 (on Roadmap 2026, Status: Todo).

@edenreich
edenreich merged commit cb0f36e into main Jul 6, 2026
1 check passed
@edenreich
edenreich deleted the feat/harden-context-injection branch July 6, 2026 13:07
inference-gateway-releaser Bot added a commit that referenced this pull request Jul 6, 2026
## [0.133.0](v0.132.1...v0.133.0) (2026-07-06)

### 🚀 Features

* add nvidia provider support ([#753](#753)) ([e9ea883](e9ea883)), closes [#751](#751)
* **agent:** cap rendered skills list and harden system prompt injection ([#761](#761)) ([cb0f36e](cb0f36e))
* scope memory entries by project ([#759](#759)) ([cabda08](cabda08)), references [#758](#758)
* **chat:** show session continuation instructions on exit ([#757](#757)) ([8d04a3a](8d04a3a)), closes [#756](#756)

### 🐛 Bug Fixes

* **chat:** add --session-id flag and fix exit message ([#760](#760)) ([a2202ba](a2202ba))
* **ci:** release notes are not being generated ([32b7acf](32b7acf))
* replace /compact with /new when plan is accepted ([#755](#755)) ([30304ed](30304ed)), closes [#754](#754)

### ♻️ Code Refactoring

* **agent:** remove comments about skill description capping ([e50aa30](e50aa30))

### 🧹 Maintenance

* **deps:** bump claude-code-action v1.0.161 -> v1.0.165 ([#752](#752)) ([44d1985](44d1985))
* **deps:** update flox packages ([8a35d5e](8a35d5e))
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.133.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

1 participant