railtracks
AGENTS.md230 starsChanged 2 months agoMITView on GitHub
Railtracks (rt) is a Python framework for building agent harnesses: the loop, tools, context, controls, and record around a model, defined entirely in standard Python (no YAML/DSLs). This is a uv workspace monorepo: Full documentation is at https://docs.railtracks.org/ and is reachable without a checkout of this repo. The source is under docs/, with navigation in mkdocs.yml. Doc URLs mirror the source path, e.g. docs/documentation/invocation/flows.md -> https://docs.railtracks.org/documentation/invocation/flows/. To verify a docs change, run mkdocs build --strict, which fails on broken links…
- Installs packages
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository3 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- code-styleSkill
The file
We split this AGENTS.md into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 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.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 152
Don't create a Flow *and* a manual top-level await rt.call(...) for the same agent.
- Distinctive: line 153
Don't add tools an agent doesn't need.
- Very specific: line 154
Don't confuse middleware= (whole-node) with model_middleware= (per model-call), and don't assume middleware order is irrelevant: the first …
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md 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
Repository Overview
Railtracks (rt) is a Python framework for building agent harnesses: the loop, tools, context, controls, and record around a model, defined entirely in standard Python (no YAML/DSLs). This is a uv workspace monorepo:
Root
├── packages/railtracks/ # The actual "railtracks" PyPI package
│ ├── pyproject.toml # Package dependencies (add new deps here, in optional-dependencies for extras)
│ ├── src/railtracks/ # Source (module is railtracks, package dir uses underscore)
│ └── tests/ # unit_tests/, integration_tests/, end_to_end/, llm_live_tests/
├── pyproject.toml # Root workspace: dev-tooling deps only (docs/test/lint groups), NOT package deps
├── docs/ # mkdocs documentation source
├── examples/ # Example scripts
└── scripts/ # CI helper scripts (dependency sorting, license checks, docs validation)Accessing docs
Full documentation is at https://docs.railtracks.org/ and is reachable without a checkout of this repo. The source is under docs/, with navigation in mkdocs.yml. Doc URLs mirror the source path, e.g. docs/documentation/invocation/flows.md -> https://docs.railtracks.org/documentation/invocation/flows/. To verify a docs change, run mkdocs build --strict, which fails on broken links and nav entries.
Setup
Python 3.10+ (requires-python = ">=3.10", CI runs 3.10) and uv.
uv sync --group dev
uv pip install -e "packages/railtracks[all]" # or a specific extra, e.g. [visual], [retrieval][all] pulls in the whole RAG stack (connectors, OCR, vector-store backends). For the retrieval pipeline without that weight, [retrieval-core] is the lighter opt-in (chunking, embedding, in-memory store, local loaders).
Common Commands
# Lint / format (CI enforces both)
ruff check --fix
ruff format
# Unit tests only (fast, ~10s)
pytest packages/railtracks/tests/unit_tests/ -v --timeout=30
# Unit + integration tests (excludes llm_live_tests and end_to_end/retrieval, per root pyproject.toml addopts)
pytest -s -v packages/railtracks/tests/unit_tests/ packages/railtracks/tests/integration_tests/
# Single test file / test
pytest packages/railtracks/tests/unit_tests/nodes/test_x.py -v
pytest packages/railtracks/tests/unit_tests/nodes/test_x.py::test_name -v
# Dependency sort check (CI enforced)
python scripts/check_dependencies_sorted.py
# Docs
mkdocs serve # blocking preview server at localhost:8000; not a verification step
mkdocs build --strict --verbose
./scripts/docs_validation.sh # type-check the snippets under docs/scripts/CI (.github/workflows/pr_tests.yaml) runs ruff-lint and check-licenses in parallel, plus a changes job that path-filters which areas were touched. unit_tests (includes the integration tests and an inline dependency-sort check), retrieval_tests, documentation_validation (mkdocs build --strict), and a standalone pyproject_dependency_order job all wait on those three and only run when changes says their area is affected. Changes should pass ruff check --fix, ruff format, and the tests for the area touched.
Note: llm_live_tests and end_to_end/retrieval require real API keys/network and are excluded from the default pytest run via root pyproject.toml addopts; other end_to_end tests run by default. RAILTRACKS_TEST_MODE is auto-enabled during tests (via conftest.py) to disable session persistence to disk; opt into persistence testing with RAILTRACKS_ALLOW_PERSISTENCE=1 and the allow_persistence fixture.
Smoke test
A fast end-to-end sanity check after a change (needs no API key):
python -c "
import railtracks as rt
def number_of_chars(text: str) -> int:
'''Count the characters in some text.
Args:
text: The text to measure.
Returns:
The character count.
'''
return len(text)
CharCount = rt.function_node(number_of_chars)
flow = rt.Flow(name='Char Count', entry_point=CharCount)
assert flow.invoke('hello') == 5
print('✓ Basic functionality test passed!')
"CLI
The CLI ships inside the SDK at packages/railtracks/src/railtracks/cli/:
railtracks init # create .railtracks/ and download the visualizer UI
railtracks update # update the visualizer UI
railtracks viz # start the visualizer server, blocking (requires railtracks[visual])
railtracks add --list # list the bundled coding-assistant skills
railtracks add claude:agent-builder # install a bundled skill for an assistantThe bundled skills add installs (agent-builder, middleware, rag) live under cli/skills/<name>/ as skill directories (a SKILL.md plus any supporting files); add <tool>:<skill> projects each into the assistant's native layout (Claude, Codex, Copilot, Cursor) and <tool>:all installs every one.
Common issues
ModuleNotFoundErrorfor an optional dependency — heavy deps are gated behind extras and exposed via lazy module-level__getattr__imports. Install the extra that owns it (railtracks[retrieval],railtracks[visual], …) rather than adding a top-level import.railtracks initorrailtracks updatefails with a hostname error — both download visualizer assets from a CDN, so they fail without network access. This is expected, not a bug to fix.
Architecture
Core building blocks
For usage patterns (how to define tools/agents/flows, structured output, agent-as-tool, MCP tools), read packages/railtracks/src/railtracks/cli/skills/agent-builder/SKILL.md (the skill railtracks add <tool>:agent-builder installs for package users) or the doc linked on each entry. This list maps each concept to its source file:
- Harness: not a class, the assembled whole (loop + tool surface + context + controls + record). The page mapping each part to the primitive that covers it is
docs/documentation/harness/overview.md(Agent Harness), with runnable versions inexamples/harness/. Use it as the framing when someone asks "how do I build an agent that does X". - Tool (
rt.function_node):built_nodes/function/node.py. Function Tools. - Agent (
rt.agent_node):built_nodes/llm/node.py; always a single dynamically built node, no separate class pertool_nodes/output_schemacombination. Passing both raisesNodeCreationError. Agent Design. - Flow:
orchestration/flow.py. Flows. rt.call(...):interaction/_call.py, alongsidecall_batch/astream/broadcast/couple. Call.- Agent-as-tool:
rt.ToolManifest(...)innodes/manifest.py. Agents as Tools. - Middleware:
middleware/chain.py(see "Things to avoid" below for themiddleware=/model_middleware=gotcha). Usepre_llm/post_llm/post_nodein new code;before_llm/after_llm/after_nodeare deprecated aliases kept only for compatibility. Middleware. - Human-in-the-loop verifier:
rt.prebuilt.middleware.pre_verifier/post_verifier(prebuilt/middleware/pre_verifier.py/post_verifier.py);Verdict/VerifierRejectedErrorare inmiddleware/verdict.py. There is no top-levelrt.verifier; don't generate code that uses one. Human in the Loop.
Package layout under src/railtracks/
nodes/: baseNodeclass,ToolManifest, tool-callable protocol.built_nodes/: node factories,llm/(agent_node, node builder, model-call middleware) andfunction/(function_node,RTFunction).orchestration/:Flow,FlowConnection.execution/: coordinator/execution-strategy/task running the request graph.interaction/:rt.call,call_batch,astream,broadcast,couple(in-node calls to other nodes/agents).middleware/: generic node-levelMiddleware/wrap_node/post_node(after_nodedeprecated shim), plusVerdict/VerifierRejectedError. The human-in-the-loop gate itself is inprebuilt/.pubsub/: internal message bus (request creation/success/failure events).state/: execution state/forest tracking, session info.context/:rt.contextget/put/update/delete (run-scoped context vars).llm/: model abstractions (ModelBase, provider clients:AnthropicLLM,OpenAILLM,GeminiLLM,OpenAICompatibleProvider, etc.), messages, tool schemas.rt_mcp/: MCP client/server integration (connect_mcp,create_mcp_server).exceptions/: theRTErrorhierarchy (NodeCreationError,NodeInvocationError,LLMError,GlobalTimeOutError,ContextError,FatalError,VisualExtraRequiredError).guardrails/:input_guard/output_guard, guardrail decisions/traces.evaluations/:evaluate,JudgeEvaluator,ToolUseEvaluator, metrics.observability/: framework-agnostic event pipeline (Observer, writers,publish_event).observability_bridge/: bridges runtimeInternalContextscope intoobservabilityevents.events/: internal event definitions/registry/emit plumbing (distinct fromobservability).query/:connect/EventQueryfor querying recorded session/event data (DuckDB-backed).retrieval/: RAG subsystem,RetrievalRuntime, loaders, chunking, embedding,Store/VectorStore(install viarailtracks[retrieval]).human_in_the_loop/:HIL,HILMessage, optional local chat UI.prebuilt/: ready-made agents/middleware/guardrails/tools, includingpre_verifier.py/post_verifier.py(see above),lock.py(Lock), andmax_calls.py(MaxCalls).prompts/: prompt template helpers.validation/: node-creation/invocation-time checks (duplicate tool names/params, etc.).utils/: config, logging, serialization, profiling, context-injection helpers.cli/:railtracksCLI (init/viz/add) plus bundled skill docs distributed to end users viarailtracks add claude:<skill>, unrelated to this repo's own.claude/skills/.viz_api/is the DuckDB-backed query/route layer behind thevizcommand.integrations/: empty placeholder package; there is nothing in it to import.scope_manager.py:ScopeManagerprotocol for node/middleware scope tracking.paths.py:resolve_railtracks_home(), resolves the.railtracksdata directory (env var, then walk-up-from-cwd, then a warned fallback)._session.py:Session/session()decorator.
Things to avoid when writing or modifying agent code
- Don't create a
Flowand a manual top-levelawait rt.call(...)for the same agent; pick one entry point. - Don't add tools an agent doesn't need.
- Don't confuse
middleware=(whole-node) withmodel_middleware=(per model-call), and don't assume middleware order is irrelevant: the first entry in the list is outermost.
Code conventions
Follow the code-style conventions for every code change. Before writing or editing code, confirm the rule list under the # railtracks Code Style heading is in your context; this line and a code-style entry in a skill listing do not count. If it is not (a new session, or after the context was compacted), read .claude/skills/code-style/SKILL.md first. Check the diff against it before committing.
Notes on dependency structure
- Root
pyproject.toml= dev tooling only (docs/test/lintgroups viauv). Never add runtime package dependencies here. packages/railtracks/pyproject.toml= actual package dependencies. New optional integrations go under[project.optional-dependencies]there, and must stay alphabetically sorted (enforced byscripts/check_dependencies_sorted.py).
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.

