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.
git clone --depth 1 https://github.com/altaidevorg/rules-for-aiWrote 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/rules/altaidevorg/rules-for-ai/state)<a href="https://agentmods.dev/rules/altaidevorg/rules-for-ai/state"><img src="https://agentmods.dev/badge/rules/altaidevorg/rules-for-ai/state/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/rules/altaidevorg/rules-for-ai/state"><img src="https://agentmods.dev/badge/rules/altaidevorg/rules-for-ai/state.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.00000 | $0.03324 |
| Opus 5.5 | $0.00000 | $0.01330 |
| Sonnet 5.5 | $0.00000 | $0.00665 |
| Haiku 4.5 | $0.00000 | $0.00332 |
Grade A, and why
state 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 2mo 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 — 237 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Chapter 4: State
In the previous chapter, we saw how the Session object holds conversational history (events) and a state dictionary to maintain context across turns. This chapter dives deep into that state dictionary's wrapper: the State object. It's designed to provide a consistent view of the session's state while meticulously tracking changes made during a specific agent turn or callback execution.
Motivation and Use Case
When an agent processes a request, it often needs to:
- Read existing information: What did the user previously specify as their destination?
- Store new information: The agent just identified the user's budget.
- Track intermediate changes: A tool call successfully fetched flight options, which need to be stored temporarily before being presented to the user or used in the next LLM call.
- Manage different scopes: Some information might be relevant only to the current chat (session state), while other details (like user preferences) should persist across different chats (user state).
Managing this directly within a simple dictionary passed around can be error-prone. How do we ensure that changes made during a complex turn (involving callbacks, LLM calls, tool executions) are correctly captured and associated with the final outcome (Event) for persistence?
The State object addresses this by acting as a smart dictionary wrapper. It provides access to the underlying session state but records any modifications made during the current context (e.g., a callback or tool execution) into a separate "delta". This delta is then attached to the resulting Event, ensuring the Session (Session / BaseSessionService) can accurately update the persistent state.
Central Use Case: Consider our travel agent bot.
- The
Sessionstarts withstate = {'origin': 'London'}. - The agent's
run_asyncis called. AnInvocationContextis created. - Inside a
before_model_callback, we accessctx.state.ctx.state['origin']returns 'London'. - The callback sets a temporary flag:
ctx.state[State.TEMP_PREFIX + 'needs_clarification'] = True. This is added to the delta but won't be persisted. - The LLM runs and invokes a
find_flightstool. - Inside the tool's execution, it accesses
ctx.stateviaToolContext. It finds flights and updates the state:ctx.state['available_flights'] = [...]. This change is recorded in the delta.ctx.state['origin']still returns 'London'. - The tool yields an Event. This event's
actions.state_deltanow contains{'available_flights': [...]}. Thetemp:key is not included for persistence. - The Runner calls
session_service.append_eventwith this event. The service updates the persistent session state by merging thestate_delta. - In the next turn, when the
Sessionis loaded, its basestatewill include{'origin': 'London', 'available_flights': [...]}.
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.
- 2mo ago First seen · 237 lines · 0 tokens per session scan A c905a8b13976
state is a cursor rule published in the GitHub repository altaidevorg/rules-for-ai (2 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 3,324 tokens. 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-08-31.
Other cursor rules, from other repositories
mempalace-recall-always
Always-on MemPalace recall — search the palace before answering about past work, people, projects, or prior decisions.
dreamd-recall
Search dreamd at the start of a task and quote a hit. Append when the user corrects you or states a decision.
session-memory
Use at conversation wrap-up or when the user explicitly indicates end-of-session — capture residual lessons not captured in-flight.
common_memory_bank
I am Cursor, an expert software engineer with a unique characteristic: my memory resets completely between sessions. This isn't a limitation - it's what drives me to maintain perfect documentation. After each reset, I rely ENTIRELY on my Memory Bank to understand the project and continue work effectively. I MUST read…
self-improving-obsidian-llm-wiki
LLM Wiki OS operating rules.
memsprout
Cursor rule "memsprout" from memsprout/agents, covering using memsprout, search first, capturing, spaces and topics and files.