AG2 is an open-source programming framework for building AI agents that can use language models, call tools, and cooperate in multi-agent workflows. Developers and researchers use it for autonomous or human-supervised agent applications, with the catalogue entry providing an instruction for working with the framework.
Borrowing it
Nothing to install: this file belongs to ag2ai/ag2. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.
curl -O https://raw.githubusercontent.com/ag2ai/ag2/main/AGENTS.mdgit clone --depth 1 https://github.com/ag2ai/ag2Wrote 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/instructions/ag2ai/ag2/agents-md)<a href="https://agentmods.dev/instructions/ag2ai/ag2/agents-md"><img src="https://agentmods.dev/badge/instructions/ag2ai/ag2/agents-md/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/instructions/ag2ai/ag2/agents-md"><img src="https://agentmods.dev/badge/instructions/ag2ai/ag2/agents-md.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.04861 | $0.04861 |
| Opus 5.5 | $0.01944 | $0.01944 |
| Sonnet 5.5 | $0.00972 | $0.00972 |
| Haiku 4.5 | $0.00486 | $0.00486 |
Grade A, and why
ag2 AGENTS.md 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 3d 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 — 288 lines — stays where its author put it; the contents beside it link to each section on GitHub.
AG2 Development Guidelines
AI-assisted contribution policy
Before opening a PR, read and follow .github/AI_POLICY.md.
- Do not open PRs with unverified AI-generated code or text.
- Ensure the PR description explains the real problem or use case and accurately reflects the diff.
- Include validation and testing information in the PR body.
- Be prepared to explain and revise the contribution in response to reviewer questions.
- Write the PR description using
.github/PULL_REQUEST_TEMPLATE.md. Keep its section headings (## Why are these changes needed?,## Related issue number,## Checks,## AI assistance), fill each one in, and only check a checklist box once it is actually true.
Architecture Decision Records (ADR)
Cross-cutting and hard-to-reverse design decisions are recorded in docs/adr/, sequentially numbered (0001-*.md, 0002-*.md, …) with status / date frontmatter and a short Context / Decision / Consequences body.
- Consult them before changing established public API or architecture. They explain why something is the way it is — e.g.
0003-eval-run-api-takes-agent-instances.mdrecords that the evalrun_*API takes prebuiltAgentinstances (not factories) and explicitly-builtSuites. If a change contradicts an ADR, supersede it rather than silently reverting the code. - Add one when a decision qualifies: it is hard to reverse, surprising without context (a reader would assume the opposite), and the result of a real trade-off. Scan
docs/adr/for the highest number and increment. Keep it short — recording that a decision was made and why is the value.
Code Style Guidelines
- Do not use
from __future__ import annotations. - With
@contextmanager/@asynccontextmanager, annotate the return type asGenerator[T]/AsyncGenerator[T], neverIterator[T]/AsyncIterator[T]. The decorator needs a real generator — it callsthrow()/athrow()on it — so the iterator form is an under-specification that typeshed marks deprecated. Import them fromcollections.abc(nottyping) and omit the default send type:AsyncGenerator[None], notAsyncGenerator[None, None]. - Do not use global variables or top-level side-effect function calls unless the user explicitly allows it.
- For filesystem paths, use
pathlib.Pathinternally. Public signatures should acceptstr | os.PathLike[str]. - Top-level imports from
ag2.*are for common APIs that are broadly reusable across scenarios and core agent flows. Good:ag2.[Input]— common structures usable inawait agent.ask(Input())and as tool results. Bad:ag2.middleware.BaseMiddleware— this is advanced/specialized and should be imported only when implementing custom middleware. - Do not use function-level imports unless the user explicitly allows it.
# === BAD - import inside function === def execute_tool(): from .tool import Tool ... # === GOOD - top-level import === from .tool import Tool def execute_tool(): ... - Do not create nested functions inside runtime execution paths.
# === BAD - function will be created each call === def execute_tool(): def _inner_function(): pass _inner_function() # === GOOD - function created once, executed each call === def execute_tool(): _inner_function() def _inner_function(): pass # === GOOD - decorator executed import time, so we can use closure functions here === def decorator(func): def wrapper(): return func() return wrapper - Do not perform side effects in initialization methods. Apply side effects only at runtime.
# === BAD - create directory in initial method === class KnowledgeStore: def __init__(self, path: str | os.PathLike[str]) -> None: self.path = Path(path) # side effect - directory creation self.path.parent.mkdir(parents=True, exist_ok=True) def run(self) -> None: ... # === GOOD - create directory in runtime method === class KnowledgeStore: def __init__(self, path: str | os.PathLike[str]) -> None: self.path = Path(path) def run(self) -> None: self.path.parent.mkdir(parents=True, exist_ok=True) ...
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.
- 3d ago Changed · +36 lines · +866 tokens per session 1e9520f61ee1
- 6d ago Changed · +10 lines · +324 tokens per session 7dd82f1e02e5
- 1mo ago Changed c2cc3ddf6b0d
- 2mo ago First seen · 242 lines · 3,671 tokens per session scan A b3aa0e039a71
ag2 AGENTS.md is an instructions file published in the GitHub repository ag2ai/ag2 (5,047 stars, last pushed yesterday), licensed Apache-2.0. It adds 4,861 tokens to every session, about $0.0194 per session on Opus 5.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-30.
ag2 AGENTS.md compared with instructions from other repositories
| Mod | Type | Stars | Last push | Licence | Scan | Tokens | Works with |
|---|---|---|---|---|---|---|---|
| ag2 AGENTS.mdag2ai/ag2 | Instructions file | 5.0k | yesterday | Apache-2.0 | A | 4,861 | Codex, OpenCode |
| vscode buildNext.instructions.mdmicrosoft/vscode | Instructions file | 195k | yesterday | MIT | A | 9,719 | GitHub Copilot |
| next.js AGENTS.mdvercel/next.js | Instructions file | 143k | yesterday | MIT | A | 7,461 | Codex, OpenCode |
| langchain AGENTS.mdlangchain-ai/langchain | Instructions file | 149k | yesterday | MIT | A | 4,680 | Codex, OpenCode |
| vscode oss-third-party-notices.instructions.mdmicrosoft/vscode | Instructions file | 195k | yesterday | MIT | A | 5,516 | GitHub Copilot |
| vscode copilot-instructions.mdmicrosoft/vscode | Instructions file | 195k | yesterday | MIT | A | 3,093 | GitHub Copilot |
| deepseek-harness AGENTS.mddeepseek-ai/deepseek-harness | Instructions file | 274k | 2d ago | MIT | A | 4,313 | Codex, OpenCode |