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/invocationcontextgit 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.03864 |
| Opus 5 | $0.00000 | $0.01932 |
| Sonnet 5 | $0.00000 | $0.00773 |
| Haiku 4.5 | $0.00000 | $0.00386 |
Grade A, and why
invocationcontext 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 — 288 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Chapter 9: InvocationContext
In the previous chapter, we explored BaseLlmFlow, the engine that orchestrates the complex interaction between an Agent (BaseAgent / LlmAgent) and the BaseLlm, especially when handling Tools (BaseTool). We saw that the flow logic often needs access to the current session, services, agent configuration, and more. Passing all these elements individually down the call stack (Runner -> Agent -> Flow -> Processors -> Callbacks -> Tools) would be cumbersome and error-prone. This chapter introduces InvocationContext, the object designed to solve this by encapsulating all necessary information for a single agent turn (invocation).
Motivation and Use Case
Consider a single turn initiated by a user message. Processing this message might involve:
- Retrieving the Session (Session / BaseSessionService) history and State.
- Knowing which specific Agent (BaseAgent / LlmAgent) is currently active (especially in hierarchical setups).
- Accessing services like
artifact_serviceorsession_service. - Applying runtime configurations (
RunConfig). - Tracking unique identifiers for logging and tracing.
- Signaling when the turn should end prematurely.
Instead of passing numerous parameters through every function call, InvocationContext acts as a "carrier" object. It bundles all this context together and is passed down through the execution hierarchy. This promotes cleaner code, ensures necessary information is available where needed without relying on global state, and simplifies the interfaces of core components like agents, flows, and tools.
Central Use Case: The Runner receives a user message for a specific session.
- The
Runnercreates anInvocationContextinstance, populating it with the fetchedSession, references to the configured services (session_service, etc.), the rootagent, theuser_content, a uniqueinvocation_id, and theRunConfig. - The
Runnerdetermines the correct agent to run (e.g.,agent_A) and callsagent_A.run_async(invocation_context). - Inside
agent_A, if it needs to call a sub-agent (agent_B), it creates a newInvocationContext(usually a copy of the parent's, updatingagenttoagent_Band appending tobranch) and callsagent_B.run_async(sub_context). - If
agent_B(anLlmAgent) uses its internal BaseLlmFlow, it passes itsInvocationContext(sub_context) to the flow. - If the flow triggers a Tool (BaseTool), it creates a ToolContext (which wraps the
InvocationContext) and passes it to the tool'srun_async. - Throughout this flow, any component (agent, flow, tool, callback) can access, for example,
ctx.session.stateorctx.session_servicevia the context object it received.
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 · 288 lines · 0 tokens per session scan A dd59e3c0e7a3
invocationcontext 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,864 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.