
Ag2 Quickstart
- 35 installs
- 8 repo stars
- Updated July 27, 2026
- ag2ai/ag2-skills
ag2-quickstart is a Claude Code skill that builds a minimal AG2 beta Agent end to end and shows multi-turn conversation chaining.
About
This skill builds a minimal AG2 beta Agent end to end: pick a model provider, set a prompt, call agent.ask(), then chain follow-up turns with reply.ask() to preserve context. A developer uses it when starting a new AG2 beta project or when unsure which provider config to use. It covers OpenAIConfig, AnthropicConfig, GeminiConfig, OllamaConfig, env-var fallback for API keys, and OpenAI-compatible endpoints.
- Builds a minimal AG2 beta Agent end to end: pick a model, set a prompt, call ask()
- Covers OpenAI, Anthropic, Gemini, Ollama and other provider configs
- Shows multi-turn chaining with reply.ask() to preserve context
Ag2 Quickstart by the numbers
- 35 all-time installs (skills.sh)
- Ranked #8,710 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 1, 2026 (Skillselion catalog sync)
ag2-quickstart capabilities & compatibility
Free skill; requires an LLM provider API key (or local Ollama, no key).
- Capabilities
- agent quickstart · model config · multi turn chaining
- Works with
- openai · anthropic
- Use cases
- orchestration
- Pricing
- Bring your own API key
What ag2-quickstart says it does
The user is starting from a blank file and wants a working AG2 beta agent.
`reply.ask()` keeps the prior turns in scope so the LLM remembers the constraints.
npx skills add https://github.com/ag2ai/ag2-skills --skill ag2-quickstartAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 35 |
|---|---|
| repo stars | ★ 8 |
| Last updated | July 27, 2026 |
| Repository | ag2ai/ag2-skills ↗ |
What it does
Build a first working AG2 beta agent and chain multi-turn conversation with reply.ask().
Who is it for?
Developers starting a new AG2 beta project or unsure which provider config to use.
Skip if: Projects not built on AG2 beta (autogen.beta).
When should I use this skill?
The user is starting a new AG2 beta project, has no working Agent yet, or needs the multi-turn chaining pattern.
What you get
A working AG2 agent answers a first turn and chains follow-up turns with preserved context.
By the numbers
- 6 provider configs in the prerequisites table (OpenAI, Anthropic, Gemini, Vertex, Ollama, DashScope)
Files
Quickstart: build your first AG2 beta Agent
When to use
- The user is starting from a blank file and wants a working AG2 beta agent.
- The user is unsure which provider config to use.
- The user wants to chain follow-up turns without losing conversation context.
- A larger task needs the basic Agent setup as its skeleton — start here, then layer the relevant feature skill on top.
Prerequisites
Required step: install dependencies before finishing.
After writing AG2 code, install the matching provider extra (plus any feature extra the task needs, e.g.ag-ui,tracing). Run the install:
>
```bash
pip install "ag2[openai]" # swap in the provider/extra you used
```
>
If you cannot run commands, state the exact pip install command. This is part of finishing the task, not an optional note.>
For a multi-file project (more than a throwaway script), also drop arequirements.txtpinningag2with the extras you used (e.g.ag2[openai]>=0.13.4) so the environment is reproducible.
Install the right provider extra and have a key for it. Each *Config requires its provider SDK — without the matching extra you'll see ImportError: ... requires optional dependencies. Install with pip install "ag2[<provider>]".
| Provider | Install | Env var | Config class |
|---|---|---|---|
| OpenAI | pip install "ag2[openai]" | OPENAI_API_KEY | OpenAIConfig, OpenAIResponsesConfig |
| Anthropic | pip install "ag2[anthropic]" | ANTHROPIC_API_KEY | AnthropicConfig |
| Gemini (API key) | pip install "ag2[gemini]" | GEMINI_API_KEY (or GOOGLE_API_KEY) | GeminiConfig |
| Vertex AI (Gemini) | pip install "ag2[gemini]" | service-account / ADC | VertexAIConfig |
| Ollama (local) | pip install "ag2[ollama]" | — | OllamaConfig |
| DashScope (Qwen) | pip install "ag2[dashscope]" | DASHSCOPE_API_KEY | DashScopeConfig |
Load env vars from a project-root .env with python-dotenv so scripts pick up keys without exporting them in your shell:
from dotenv import load_dotenv
load_dotenv() # reads .env at project rootQuick sanity-check before debugging weird import errors — make sure you're running against the ag2 you think:
python -c "import sys, autogen; print(sys.executable); print('ag2', autogen.__version__)"60-second recipe
import asyncio
from autogen.beta import Agent
from autogen.beta.config import OpenAIConfig
async def main() -> None:
agent = Agent(
"assistant",
prompt="You are a helpful assistant. Reply in one sentence.",
config=OpenAIConfig(model="gpt-4o-mini"),
)
# First turn
reply = await agent.ask("What is the capital of France?")
print(reply.body)
# Continue the same conversation — context is preserved
reply = await reply.ask("And of Germany?")
print(reply.body)
asyncio.run(main())Agent.ask(...) starts a new turn and returns an AgentReply. AgentReply.ask(...) continues the same conversation, preserving its context and history. The reply text is in reply.body; for typed output see the ag2-structured-output skill (reply.content()).
Picking a provider
Each provider has its own config class in autogen.beta.config. All accept model=, optional api_key=, and (where supported) streaming=True. Streaming is recommended — AG2 beta is async- and streaming-first.
from autogen.beta.config import OpenAIConfig # gpt-4o, gpt-5-*, o-series, etc.
from autogen.beta.config import OpenAIResponsesConfig # OpenAI Responses API (image gen, file_id support)
from autogen.beta.config import AnthropicConfig # claude-sonnet-4-6, claude-opus-4-7, etc.
from autogen.beta.config import GeminiConfig # Gemini Developer API (api_key)
from autogen.beta.config import VertexAIConfig # Gemini on Google Vertex AI (project + location)
from autogen.beta.config import OllamaConfig # local Ollama
from autogen.beta.config import DashScopeConfig # Alibaba Qwen
config = AnthropicConfig(model="claude-sonnet-4-6", streaming=True)If api_key= is omitted, the config reads the standard env var — OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY (or GOOGLE_API_KEY), etc.
For OpenAI-compatible endpoints (vLLM, LM Studio, Together, NVIDIA NIM, etc.) use OpenAIConfig with base_url= set:
config = OpenAIConfig(
model="qwen-3",
base_url="http://localhost:8000/v1",
api_key="NotRequired", # pragma: allowlist secret
)Multi-turn — chain reply.ask()
agent = Agent("planner", prompt="...", config=config)
reply = await agent.ask("Plan a 5-day Japan trip in late April.")
reply = await reply.ask("Budget is $2500 per person, two travellers.")
reply = await reply.ask("Prefer trains. Day-by-day itinerary.")
print(reply.body)reply.ask() keeps the prior turns in scope so the LLM remembers the constraints. Calling agent.ask(...) again instead would start a fresh conversation. See assets/multi_turn.py for the full travel-planner example.
Reusing model configs
Configs are immutable. Use .copy(...) to fork one with overrides:
base = OpenAIConfig(model="gpt-5")
hot = base.copy(temperature=0.8)
cheap = base.copy(model="gpt-5-mini")You can also override the model per ask — useful when the user brings their own API key per request:
agent = Agent("assistant", prompt="Help.")
reply = await agent.ask("Hello!", config=OpenAIConfig(model="gpt-5", api_key="sk-...")) # pragma: allowlist secretThe per-ask config completely replaces the agent's config for that turn.
Going deeper
- Working starter (single-turn):
assets/hello_agent.py(mirrorscode_examples/01). - Multi-turn starter:
assets/multi_turn.py(mirrorscode_examples/03). - Full provider reference, including
VertexAIConfigauth,extra_body, customhttpxclient, env-var fallback table:website/docs/beta/model_configuration.mdx. - Agent communication API surface (events, observing, HITL):
website/docs/beta/agents.mdx. - Static, dynamic, per-turn prompts:
website/docs/beta/system_prompts.mdx.
Common pitfalls
- Forgetting to `await` — every method on
Agent/AgentReplyis async. Wrap inasyncio.run(main())for scripts. - Calling `agent.ask()` twice expecting context to carry — it doesn't; use
reply.ask()instead. - Hardcoding API keys — prefer env-var fallback (
OPENAI_API_KEY, etc.) so configs commit cleanly. - Skipping `streaming=True` — AG2 beta is streaming-first; you'll get a worse user experience without it on supported providers.
- Per-ask `config=` is total override, not a partial merge — be deliberate about which knobs you set.
"""Hello Agent — minimal AG2 beta example.
Mirrors website/docs/beta/code_examples/01_hello_agent.mdx. The smallest
possible end-to-end: instantiate an Agent with one model config, call ask(),
print the reply, then reuse the same Agent for a second turn.
Run::
python hello_agent.py
"""
import asyncio
from dotenv import load_dotenv
from autogen.beta import Agent
from autogen.beta.config import GeminiConfig
# Load API keys from a .env file at the project root (GEMINI_API_KEY here).
# Swap GeminiConfig for OpenAIConfig / AnthropicConfig if that's the key you have.
load_dotenv()
def section(title: str) -> None:
print(f"\n── {title} ───")
async def main() -> None:
config = GeminiConfig(model="gemini-3-flash-preview", temperature=0)
section("Bare Agent — ask and print")
agent = Agent(
"greeter",
prompt="You are a friendly but concise assistant. Reply in one sentence.",
config=config,
)
reply = await agent.ask("Give me a single tip for learning to play chess.")
print(reply.body)
section("Reuse the Agent for another ask")
reply2 = await agent.ask("And a tip for learning poker, in one sentence.")
print(reply2.body)
if __name__ == "__main__":
asyncio.run(main())
"""Travel planner — multi-turn conversation via reply.ask() chaining.
Mirrors website/docs/beta/code_examples/03_travel_planner.mdx. Chained
``reply.ask()`` builds on the same conversation history. The planner remembers
constraints from earlier turns without the caller re-supplying context.
Run::
python multi_turn.py
"""
import asyncio
from dotenv import load_dotenv
from autogen.beta import Agent
from autogen.beta.config import GeminiConfig
# Load API keys from a .env file at the project root (GEMINI_API_KEY here).
# Swap GeminiConfig for OpenAIConfig / AnthropicConfig if that's the key you have.
load_dotenv()
def section(title: str) -> None:
print(f"\n── {title} ───")
TURNS = [
"I want to plan a 5-day trip to Japan in late April. Just cherry-blossom season.",
"Budget is around $2500 per person, two travellers. Optimise for sightseeing, not luxury.",
"We prefer trains to flights once we're in Japan. Draft a day-by-day itinerary.",
"Looks great. For day 3, swap the shopping stop for something outdoorsy in or near Kyoto.",
"Summarize the final itinerary in a single bullet list, one line per day.",
]
async def main() -> None:
config = GeminiConfig(model="gemini-3-flash-preview", temperature=0)
agent = Agent(
"travel-planner",
prompt=(
"You are a detail-oriented travel planner. When the user adds "
"constraints, update the plan rather than starting over. Be "
"concrete and concise."
),
config=config,
)
section("Turn 1 — kick off")
reply = await agent.ask(TURNS[0])
print(reply.body)
for i, question in enumerate(TURNS[1:], start=2):
section(f"Turn {i} — {question}")
reply = await reply.ask(question)
print(reply.body)
if __name__ == "__main__":
asyncio.run(main())
Related skills
FAQ
How do I continue the same conversation?
Call reply.ask(); it keeps prior turns in scope, while agent.ask() again starts a fresh conversation.
Where does the API key come from if I omit api_key?
The config reads the standard env var like OPENAI_API_KEY or ANTHROPIC_API_KEY.