runner

The component that runs an AI agent interaction from start to finish. It manages the conversation session, stored state, files, memory, agent selection, and streamed responses.

In plain words
What is it for?
Use it as the main entry point for sending user input to an agent, continuing conversations, selecting between agents, and returning responses.
Why use it?
It coordinates the many steps around an agent so application code does not have to manage each step separately.

Cursor rule

Install

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.

agentmods
npx agentmods add rules/altaidevorg/rules-for-ai/runner
Clone the repo
git clone --depth 1 https://github.com/altaidevorg/rules-for-ai
Per session 3,155 This file is loaded in full into every session.
When invoked 3,155 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

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.

ModelPer sessionOnce invoked
Fable 5 $0.03155 $0.03155
Opus 5 $0.01577 $0.01577
Sonnet 5 $0.00631 $0.00631
Haiku 4.5 $0.00315 $0.00315

Measured yesterday against content hash 0cbfbc2f89b9, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

runner 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.

examples/google-adk/runner.mdc · 235 lines

How it starts

The opening of the file, as written. The whole thing — 235 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Chapter 1: Runner

Welcome to the google-adk tutorial! This first chapter introduces the Runner, a fundamental component responsible for managing the entire lifecycle of an agent interaction within the framework.

Motivation and Use Case

Imagine you have built an agent, perhaps using an LLM, that can interact with users. How do you actually run this agent? You need a system that can:

  1. Receive user input.
  2. Maintain the conversation history (Session).
  3. Manage persistent state (State).
  4. Handle file uploads/downloads (Artifacts).
  5. Potentially retrieve relevant long-term memories.
  6. Invoke the correct agent logic.
  7. Stream back the agent's response (Events).
  8. In complex systems with multiple agents, decide which agent should handle the current turn.

The Runner is the orchestrator that handles all these tasks. It acts as the main entry point for interacting with any agent built using google-adk.

Central Use Case: A user sends a message ("What's the weather in London?") to your weather agent via an application. The application uses a Runner instance. The Runner retrieves the ongoing conversation session, appends the new user message, determines the weather agent should handle it, calls the agent's execution logic, and streams the resulting events (like the agent thinking, calling a weather tool, and finally responding) back to the application.

Key Concepts

  • Orchestration: The Runner coordinates the flow of information and control between the user, the agent(s), and various backing services.
  • Agent Execution: It provides methods like run_async (asynchronous, recommended for production) and run (synchronous wrapper for testing) to execute an agent turn. It also supports an experimental run_live for real-time streaming interactions (e.g., voice).
  • Service Integration: It requires and utilizes services for managing different aspects of the interaction:
    • BaseSessionService: Manages conversational Sessions, including history (Events) and State.
    • BaseArtifactService: Handles storage and retrieval of binary data (e.g., files uploaded by the user or generated by the agent). (Optional)
    • BaseMemoryService: Provides access to long-term memory for the agent. (Optional)
  • Agent Selection: In systems with a hierarchy of agents (an agent containing sub-agents), the Runner determines which agent is best suited to handle the current turn based on the session history and agent capabilities (using _find_agent_to_run). It checks if the last responding agent can "transfer" control back up the hierarchy if needed.
  • Input Processing: Before invoking the agent, the Runner processes the incoming user message (new_message). This includes potentially saving any attached binary data as artifacts (if save_input_blobs_as_artifacts is true in the RunConfig) and appending the user message as an Event to the Session.
  • Event Streaming: The run_async and run_live methods are asynchronous generators that yield Events as they occur during the agent's execution (e.g., intermediate thoughts, tool calls, final response parts).

Read the full file on GitHub · 235 lines

Changes

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.

  1. yesterday First seen · 235 lines · 3,155 tokens per session scan A 0cbfbc2f89b9

Subscribe to this mod's changes

runner is a cursor rule published in the GitHub repository altaidevorg/rules-for-ai (2 stars, last pushed 1y ago), licensed MIT. It adds 3,155 tokens to every session, about $0.0158 per session on Opus 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-08-31.