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 agentmods add rules/altaidevorg/rules-for-ai/stategit clone --depth 1 https://github.com/altaidevorg/rules-for-aiWhat 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 | $0.00000 | $0.03324 |
| Opus 5 | $0.00000 | $0.01662 |
| Sonnet 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 yesterday.
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.
- yesterday 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
angular-20
This rule provides comprehensive best practices and coding standards for Angular development, focusing on modern TypeScript, standalone components, signals, and performance optimizations.
dev-standard
Apache Superset development standards and guidelines for Cursor IDE.
typescript
Changes to these high-fan-out internals can affect every message, delta, element, or rerun. Keep work in them minimal, and benchmark changes with representative stress-test apps.
coolify-ai-docs
Master reference to all Coolify AI documentation in .ai/ directory.
python_lib
Tips and guidelines specific to the development of the Streamlit Python library, not applicable to scripts and e2e tests.
specs
This directory contains product and tech specs for Streamlit features.