Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx skills add RailtownAI/railtracks --skill middlewaregit clone --depth 1 https://github.com/RailtownAI/railtracksWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/railtownai/railtracks/middleware)<a href="https://agentmods.dev/skills/railtownai/railtracks/middleware"><img src="https://agentmods.dev/badge/skills/railtownai/railtracks/middleware/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/railtownai/railtracks/middleware"><img src="https://agentmods.dev/badge/skills/railtownai/railtracks/middleware.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00045 | $0.02580 |
| Opus 5.5 | $0.00018 | $0.01032 |
| Sonnet 5.5 | $0.00009 | $0.00516 |
| Haiku 4.5 | $0.00005 | $0.00258 |
Grade A, and why
middleware scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 152 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Add Middleware to a Railtracks Agent or Node
The user wants to add middleware to a railtracks node/agent: $ARGUMENTS
Quick reference
| Decorator | Signature | Slot | Fires on failure? |
|---|---|---|---|
rt.wrap_node |
async fn(call, *args, **kwargs) -> result |
middleware= or model_middleware= |
Yes — you control the try/except |
rt.wrap_llm |
async fn(llm_call, message_history, schema, tools) -> Response |
model_middleware= only |
Yes |
rt.pre_llm |
fn(message_history, schema, tools) -> (message_history, schema, tools) (sync or async) |
model_middleware= only |
N/A (runs before the call) |
rt.post_llm |
fn(response) -> response (sync or async) |
model_middleware= only |
No — skipped on exception |
rt.post_node |
fn(result) -> result (sync or async) |
middleware= or model_middleware= |
No — skipped on exception |
- All five accept optional keyword-only
name=and work bare or called:@rt.pre_llm,@rt.post_node(name="print_after"). wrap_node/wrap_llmrequireasync def(TypeErrorotherwise).pre_llm/post_llm/post_nodeaccept sync or async.middleware=wraps the whole node call (an agent's full tool-calling loop, including every tool node it invokes).model_middleware=wraps one raw LLM call inside that loop.- Attach at creation —
rt.agent_node(..., middleware=[...], model_middleware=[...])— or after the fact without mutating the original —rt.couple(node, middleware=[...], model_middleware=[...]). - List order = wrapping order:
middleware=[A, B, C]→AwrapsBwrapsCwraps the node.rt.couple-ing more onto an already-middlewared node adds the new ones outermost; existing middleware stays innermost, closest to the node.
Best practices
1. Exception handling & retries
pre_llm,post_llm,post_nodeonly run on success — an exception skips them entirely. If you need to react to failure (cleanup, translation, fallback), usewrap_node/wrap_llmand put your owntry/exceptaroundawait call(...).- Where you put a retry changes what it re-executes:
model_middleware=retry only re-issues the raw LLM call — safe by default, no side effects beyond the model provider request.middleware=retry on an agent re-runs the entire node, including every tool call that already succeeded in that attempt. Only retry at this slot if the tools involved are safe to re-run (idempotent, or guarded by an idempotency key) — otherwise a transient failure after a non-idempotent tool call (e.g. "send email", "charge card") causes it to fire twice.- Default to retrying in
model_middleware=for provider flakiness (rate limits, timeouts). Reach formiddleware=retry only when you've confirmed the tools are safe to repeat.
- Prefer
railtracks.prebuilt.middleware.Retry(max_tries=..., approach=..., retry_on=...)over hand-rolling — it raises once attempts are exhausted rather than swallowing the failure, and lets you scoperetry_onto specific exception types instead of catching everything. - Don't swallow exceptions silently inside a
wrap_node/wrap_llmmiddleware (except Exception: return default) — that hides the failure from callers and from anything else in the chain. If you must return a fallback, do it deliberately (log it, tag it in the result) rather than as an unannounced side effect.
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 6d ago Changed 03dd51fef290
- 7d ago Changed · +2 lines a93e10b177be
- 29d ago Changed · +7 lines 30e6f365419d
- 1mo ago Changed · +1 lines 981fa574572d
- 1mo ago Changed b610bbbf131a
- 2mo ago Changed · +17 lines 6b0ba8a1dede
- 2mo ago Changed · +24 tokens per session d0d8cf143154
- 2mo ago First seen · 125 lines · 21 tokens per session scan A 4e757de91056
middleware is a skill published in the GitHub repository RailtownAI/railtracks (235 stars, last pushed today), licensed MIT. It adds 45 tokens to every session and 2,580 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-23.
middleware compared with skills from other repositories
| Mod | Type | Stars | Last push | Licence | Scan | Tokens | Works with |
|---|---|---|---|---|---|---|---|
| middlewareRailtownAI/railtracks | Skill | 235 | today | MIT | A | 45 | Claude Code |
| first-readerShubhamsaboo/awesome-llm-apps | Skill | 147k | yesterday | Apache-2.0 | A | 174 | Claude Code, Codex |
| mcp-apps-builderShubhamsaboo/awesome-llm-apps | Skill | 147k | yesterday | Apache-2.0 | A | 139 | Claude Code, Codex |
| project-graveyardShubhamsaboo/awesome-llm-apps | Skill | 147k | yesterday | Apache-2.0 | A | 127 | Claude Code, Codex |
| commit-archaeologistShubhamsaboo/awesome-llm-apps | Skill | 147k | yesterday | Apache-2.0 | A | 82 | Claude Code, Codex |
| dependency-doctorShubhamsaboo/awesome-llm-apps | Skill | 147k | yesterday | Apache-2.0 | A | 115 | Claude Code, Codex |
| scope-creep-detectorShubhamsaboo/awesome-llm-apps | Skill | 147k | yesterday | Apache-2.0 | A | 98 | Claude Code, Codex |