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.02310 |
| Opus 5.5 | $0.00018 | $0.00924 |
| Sonnet 5.5 | $0.00009 | $0.00462 |
| Haiku 4.5 | $0.00005 | $0.00231 |
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 2d 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 — 143 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 innermost; existing middleware stays outermost.
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.
- 2d ago Changed · +1 lines 981fa574572d
- 11d ago Changed b610bbbf131a
- 14d ago Changed · +17 lines 6b0ba8a1dede
- 22d ago Changed · +24 tokens per session d0d8cf143154
- 24d ago First seen · 125 lines · 21 tokens per session scan A 4e757de91056
middleware is a skill published in the GitHub repository RailtownAI/railtracks (233 stars, last pushed today), licensed MIT. It adds 45 tokens to every session and 2,310 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.
Other skills, from other repositories
first-reader
Beta readers for any draft, run by simulating how a real reader experiences it, moment by moment. A skim gate, a no-lookahead timed read producing an attention transcript with quit points, a recall test of what a reader remembers the next day, and a trust ledger of the implied author. Use when the user asks for a beta…
mcp-apps-builder
MANDATORY for ALL MCP server work - mcp-use framework best practices and patterns. READ THIS FIRST before any MCP server work, including: Creating new MCP servers Modifying existing MCP servers (adding/updating tools, resources, prompts, widgets) Debugging MCP server issues or errors Reviewing MCP server code for…
project-graveyard
Scans the developer's machine for dead side projects, autopsies each one from its git history (died at the payments wall, killed by a newer project, finished but never shipped), surfaces their personal death patterns, and picks the corpse most worth resurrecting — then helps ship it. Use when the user mentions…
commit-archaeologist
Reconstructs why code exists from local git history, including the introducing commit, later changes, current authors, repeated companion files, and likely intent. Use when the user asks "why does this code exist", "who wrote this function and why", or to "explain the history of this function" before a rewrite…
dependency-doctor
Checks requirements.txt, pyproject.toml, and package.json dependency manifests for surface-level direct-dependency footguns: standard-library shadowing pins, abandoned backports, unpinned dependencies, and obvious intra-manifest conflicts, plus opt-in PyPI yanked releases. Use when the user asks to check a manifest…
scope-creep-detector
Analyzes git diffs against a stated intent to detect scope creep, unrelated files, broad pull requests, changes that grew beyond a fix, dependency additions, public API renames, config or CI edits, oversized hunks, and formatting-only files. Use when the user asks whether a change grew beyond the fix, a PR is too…