ag2 AGENTS.md

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

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 instructions/ag2ai/ag2/agents-md
Clone the repo
git clone --depth 1 https://github.com/ag2ai/ag2

Made for: Codex, OpenCode.

Per session 3,671 This file is loaded in full into every session.
When invoked 3,671 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.03671 $0.03671
Opus 5 $0.01835 $0.01835
Sonnet 5 $0.00734 $0.00734
Haiku 4.5 $0.00367 $0.00367

Measured 2d ago against content hash b3aa0e039a71, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, 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 2d 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 · 242 lines

How it starts

The opening of the file, as written. The whole thing — 242 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 · 242 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. 2d 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 (4,896 stars, last pushed today), licensed Apache-2.0. It adds 3,671 tokens to every session, about $0.0184 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-30.

Related

Other instructions, from other repositories