Skip to content

Overview

End-to-end runnable scripts demonstrating ag2. Each example is self-contained, instantiates a GeminiConfig directly, and exercises one or two specific harness primitives so you can read it top-to-bottom and copy what you need.

Examples#

# Page Topic Primitives covered
01 Hello Agent Minimal Agent — one config, one ask Agent, GeminiConfig
02 Recipe Builder Tools + Pydantic structured output Agent, tools=, response_schema=
03 Travel Planner Multi-turn chat via chained reply.ask() agent.ask(), reply.ask()
04 Token Watchdog Built-in + custom observers, ObserverAlert BaseObserver, TokenMonitor, LoopDetector, EventWatch
05 Research Squad Parallel delegation + sibling delegation Agent.as_tool(), TaskStarted / TaskCompleted
06 Journal Companion Persistent memory across runs KnowledgePlugin, WorkingMemoryAggregate, WorkingMemoryPolicy
07 Long-Doc Chat Composing assembly policies + compaction Middleware(AssemblerMiddleware, policies=[...]), SlidingWindowPolicy, TokenBudgetPolicy, TailWindowCompact
08 Safety Guard FATAL alert → AlertPolicy → HaltEvent ObserverAlert(FATAL), AlertPolicy, HaltEvent

Set GEMINI_API_KEY (or swap in another provider's ModelConfig — AnthropicConfig, OpenAICompletionsConfig, etc.) before running.