ag2: Instructions file for Codex

AGENTS.md

ag2 AGENTS.md is an instructions file for Codex, OpenCode from ag2ai/ag2. It costs 4,861 tokens per session, scanned A, original, Apache-2.0.

Development instructions for AG2, a software project for building systems with agents. They cover contribution rules, architecture decision records, code style, and the project's package layout.

In plain words
What is it for?
Use them when preparing a pull request, consulting past architecture decisions, editing public APIs, or working within AG2's package structure.
Why use it?
They help contributors follow the repository's review requirements and understand why important design choices were made before changing code.

Instructions file for CodexOpenCode

Written for Codex and OpenCode: the file is AGENTS.md. Also seen: mentions subagents.

This is ag2ai/ag2's own configuration. It tells Codex and OpenCode how to work on ag2 itself, so it is not a mod to install elsewhere. Copy it as a starting point and replace the rules that are about this project. Everything ag2 configures →

About the project

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.

ag2ai/ag2 · 5,047 stars · on GitHub · ag2.ai

Reuse

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.

Copy the file
curl -O https://raw.githubusercontent.com/ag2ai/ag2/main/AGENTS.md
Clone the repo
git clone --depth 1 https://github.com/ag2ai/ag2

Made for: Codex, OpenCode.

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

agentmods badge for ag2 AGENTS.md

README.md
[![agentmods](https://agentmods.dev/badge/instructions/ag2ai/ag2/agents-md/github.svg)](https://agentmods.dev/instructions/ag2ai/ag2/agents-md)
Your own site
<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.

agentmods 80×15 button for ag2 AGENTS.md

Your own site · 80×15
<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>
Per session 4,861 This file is loaded in full into every session.
When invoked 4,861 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.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

Measured 3d ago against content hash 1e9520f61ee1, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

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.

AGENTS.md · 288 lines

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.md records that the eval run_* API takes prebuilt Agent instances (not factories) and explicitly-built Suites. 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 as Generator[T] / AsyncGenerator[T], never Iterator[T] / AsyncIterator[T]. The decorator needs a real generator — it calls throw() / athrow() on it — so the iterator form is an under-specification that typeshed marks deprecated. Import them from collections.abc (not typing) and omit the default send type: AsyncGenerator[None], not AsyncGenerator[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.Path internally. Public signatures should accept str | 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 in await 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)
            ...
    

Read the full file on GitHub · 288 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. 3d ago Changed · +36 lines · +866 tokens per session 1e9520f61ee1
  2. 6d ago Changed · +10 lines · +324 tokens per session 7dd82f1e02e5
  3. 1mo ago Changed c2cc3ddf6b0d
  4. 2mo ago First seen · 242 lines · 3,671 tokens per session scan A b3aa0e039a71

Subscribe to this mod's changes

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.

Related

ag2 AGENTS.md compared with instructions from other repositories

ag2 AGENTS.md next to 6 instructions from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
ag2 AGENTS.mdag2ai/ag2Instructions file5.0kyesterdayApache-2.0A4,861Codex, OpenCode
vscode buildNext.instructions.mdmicrosoft/vscodeInstructions file195kyesterdayMITA9,719GitHub Copilot
next.js AGENTS.mdvercel/next.jsInstructions file143kyesterdayMITA7,461Codex, OpenCode
langchain AGENTS.mdlangchain-ai/langchainInstructions file149kyesterdayMITA4,680Codex, OpenCode
vscode oss-third-party-notices.instructions.mdmicrosoft/vscodeInstructions file195kyesterdayMITA5,516GitHub Copilot
vscode copilot-instructions.mdmicrosoft/vscodeInstructions file195kyesterdayMITA3,093GitHub Copilot
deepseek-harness AGENTS.mddeepseek-ai/deepseek-harnessInstructions file274k2d agoMITA4,313Codex, OpenCode