add-middleware
Skill238 starsChanged 2 months agoApache-2.0View on GitHub
Add a new NeMo Relay guardrail or intercept type, registration surface, or pipeline stage. Do not use for changing an existing middleware implementation without a new middleware contract.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- KhaledSaeed18/node-express-boilerplatetheir own version, first seen Jul 15, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- KhaledSaeed18/node-express-boilerplate★ 36same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository30 other files it gives its agents.
- AGENTS.mdAGENTS.md
- add-binding-featureSkill
- check-release-deploymentsSkill
- contribute-docsSkill
- contribute-integrationSkill
- create-beta-tagSkill
- create-rc-tagSkill
- create-release-tagSkill
- draft-release-notesSkill
- maintain-ciSkill
- maintain-dynamic-pluginsSkill
- maintain-observabilitySkill
- maintain-optimizerSkill
- maintain-packagingSkill
- prepare-code-freezeSkill
- prepare-prSkill
- rename-surfacesSkill
- review-doc-styleSkill
- update-project-versionSkill
- nemo-relay-debug-runtime-integrationSkill
- nemo-relay-get-startedSkill
- nemo-relay-installSkill
- nemo-relay-instrument-callsSkill
- nemo-relay-instrument-context-isolationSkill
- nemo-relay-instrument-typed-wrappersSkill
- nemo-relay-integrate-upstreamSkill
- nemo-relay-migrate-from-flowSkill
- nemo-relay-plugin-adaptive-tuningSkill
- nemo-relay-plugin-buildSkill
- nemo-relay-plugin-observabilitySkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 1 is distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
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 14
Use this skill when introducing a new middleware registration surface or adding middleware behavior to a new pipeline stage.
- Very specific: line 30
If this is an event sanitizer, which of data, category_profile, and metadata can change, and is the event used only as immutable context?
- Very specific: line 63
Add the registry field to NemoRelayContextState in crates/core/src/api/runtime/state.rs.
- Very specific: line 66
Add a SortedRegistry<GuardrailEntry<MyNewFn>> or SortedRegistry<Intercept<MyNewFn>> field to the state struct.
- Very specific: line 69
Add registration and deregistration APIs in crates/core/src/api/.
- Very specific: line 71
Use the existing global_*_registry_api!
- Very specific: line 75
Add chain execution helpers to NemoRelayContextState in crates/core/src/api/runtime/state.rs.
- Very specific: line 78
Follow the pattern of tool_sanitize_request_chain or tool_request_intercepts_chain.
- Very specific: line 82
Update the relevant lifecycle owner to call the new chain method at the appropriate pipeline stage.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill 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
Add a Middleware Type
NeMo Relay supports guardrails (validate/gate) and intercepts (transform) at various pipeline stages. Adding a new middleware type requires checking every layer that exposes the new contract.
Use this skill when introducing a new middleware registration surface or adding middleware behavior to a new pipeline stage.
Lock The Design First
Decide these before editing code:
- Is this for tools, LLMs, marks, scope events, or a combination?
- Is it a conditional guardrail, sanitize guardrail, request intercept, or execution intercept?
- Does it run on request input, inner callable execution, stream chunks, or final response output?
- Is the callback fallible, and how should callback failures propagate?
- Does it need both global and scope-local registration?
- What should subscribers and exporters observe in the event payload after this middleware runs?
- If this is an event sanitizer, which of
data,category_profile, andmetadatacan change, and is the event used only as immutable context?
Pipeline Order
Refer to docs/about-nemo-relay/concepts/middleware.mdx for the full diagrams.
- Tool execute: conditional guardrails -> request intercepts -> sanitize request (for events) | execution intercept chain(callable) -> sanitize response
- LLM execute: conditional guardrails -> request intercepts -> sanitize request (for events) | execution intercept chain(callable) -> sanitize response
- Mark and scope events: specialized tool or LLM sanitizer (when applicable) -> mark or scope event sanitizer -> subscriber and exporter dispatch
Tool execution callbacks and each execution-intercept next continuation
return the canonical ToolExecutionResult { result, annotation }. A forwarding
intercept must preserve both fields in ToolExecutionInterceptOutcome; Relay
retains pending_marks separately. Tool sanitize-response guardrails receive
only result. Scope-end event sanitizers govern the annotation after Relay
projects it to category_profile.tool_result_annotation.
Core Steps
- Define or reuse the callback type alias in
crates/core/src/api/runtime/callbacks.rs.
pub type MyNewFn = Box<dyn Fn(&str, Json) -> Json + Send + Sync>;- Add the registry field to
NemoRelayContextStateincrates/core/src/api/runtime/state.rs.
Add a SortedRegistry<GuardrailEntry<MyNewFn>> or SortedRegistry<Intercept<MyNewFn>>
field to the state struct.
- Add registration and deregistration APIs in
crates/core/src/api/.
Use the existing global_*_registry_api! and scope_*_registry_api! macro
patterns in crates/core/src/api/registry.rs. Both global and scope-local
variants are needed unless the design explicitly rules one out.
- Add chain execution helpers to
NemoRelayContextStateincrates/core/src/api/runtime/state.rs.
Follow the pattern of tool_sanitize_request_chain or tool_request_intercepts_chain.
- Wire the chain into the execute path.
Update the relevant lifecycle owner to call the new chain method at the
appropriate pipeline stage. Tool and LLM paths live in
crates/core/src/api/tool.rs and crates/core/src/api/llm.rs; shared mark and
scope event sanitization lives in crates/core/src/api/shared.rs and is called
from crates/core/src/api/scope.rs.
- Expose the new middleware surface in every affected binding.
For a public middleware contract, implement the Rust source of truth, then update only the bindings, FFI, wrappers, documentation, and tests that expose or observe the new contract.
Required Tests
- Registration and duplicate-name behavior
- Deregistration and no-op missing-name behavior
- Ordering by priority
- Callback failure policy, including fail-open behavior when required
- Scope-local registration, inheritance, and cleanup on pop
- Event payload semantics after middleware mutation
- Tool execution result and annotation preservation, replacement, and removal when the middleware touches tool execution
- Mark and scope event field semantics, including immutable identity fields
- Parity coverage in every affected binding
Key References
- Pipeline logic:
crates/core/src/api/tool.rs,crates/core/src/api/llm.rs - Type aliases:
crates/core/src/api/runtime/callbacks.rs - Runtime state and chain builders:
crates/core/src/api/runtime/state.rs - Scope-local registry merging:
crates/core/src/context/registries.rs - Registry:
crates/core/src/registry.rs - Pipeline docs:
docs/about-nemo-relay/concepts/middleware.mdx - Architecture docs:
docs/about-nemo-relay/architecture.mdx - Registration examples:
docs/instrument-applications/advanced-guide.mdx
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.

