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 agents/mozilla-ai/any-agent/callbacksgit clone --depth 1 https://github.com/mozilla-ai/any-agentWhat 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.02988 |
| Opus 5 | $0.00000 | $0.01494 |
| Sonnet 5 | $0.00000 | $0.00598 |
| Haiku 4.5 | $0.00000 | $0.00299 |
Grade A, and why
callbacks 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 — 389 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Agent Callbacks
Callbacks provide hooks into the lifecycle of an AnyAgent execution. Using callbacks, you can monitor, control, and extend agent behavior without modifying the core underlying agent logic.
Implementing Callbacks
All callbacks must inherit from the base Callback class and can choose to implement any subset of the available callback methods. These methods include:
| Callback Method | When It Fires | Example Use Cases |
|---|---|---|
| before_agent_invocation | Once at start, before any LLM calls | Initialize counters, validate inputs, set up logging |
| before_llm_call | Before each LLM API call | Content filtering, cost tracking, prompt inspection |
| after_llm_call | After LLM responds, before adding to history | Response validation, token counting, logging |
| before_tool_execution | Before each tool runs | Rate limiting, input validation, authorization checks |
| after_tool_execution | After tool completes | Result validation, metrics collection, error handling |
| after_agent_invocation | Once at end, before returning final response | Cleanup, final metrics, audit logging |
# Minimum valid implementation
def before_llm_call(self, context: Context, *args, **kwargs) -> Context:
return context # <--- Essential!
Managing State (Context)
During an agent run (agent.run_async or agent.run), a unique Context object is created and shared across all callbacks.
Use Context.shared (a dictionary) to persist data across different steps and callbacks.
Note: The
Contextobject is mutable. You should modifyContext.shareddirectly and return the same object.
any-agent populates the Context.current_span property so that callbacks can access information in a framework-agnostic way.
You can see what attributes are available for LLM Calls and Tool Executions by examining the GenAI class.
Common Pattern: Initialize a counter in one callback and check it in another.
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 · 389 lines · 0 tokens per session scan A baaa7d2c11be
callbacks is an agent published in the GitHub repository mozilla-ai/any-agent (1,197 stars, last pushed 1mo ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 2,988 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-30.
Other agents, from other repositories
a2a
One agent invoking another is delegation; A2A is the transport binding used when the target is outside your platform, and this page separates the two.
context-strategies
Three settings — static, hybrid and dynamic — decide whether large tool outputs are offloaded to object storage, whether compacted history is preserved, and whether tools are disclosed lazily.
acp-developer
Agent-to-Agent (A2A) protocol developer for building interoperable agent systems using Google's open A2A standard with JSON-RPC, task lifecycle, and streaming.
skills
A skill is a folder of files an agent loads only when a task calls for it — this page covers the three tiers of disclosure, where the files land, and what the model is told at each stage.
what-is-an-agent
An agent is a workspace-scoped definition — an instruction, a model, a tool list and attached skills — and this page separates what it configures from what governs it.
AGENTS
Agent Developer — objective: Implement higher-level behaviors by composing tools into responsible, auditable agents.