ag2-quickstart
Skill12 starsChanged 8 days agoApache-2.0View on GitHub
Build a minimal AG2 `Agent` end to end — pick a model provider config, set a prompt, call `agent.ask()`, read `reply.body`, then continue the conversation with `reply.ask()` (multi-turn). Use when the user is starting a new AG2 project, has no working `Agent` yet, needs the multi-turn chaining pattern, or asks which provider config to use. Covers `OpenAIResponsesConfig` (OpenAI default), `OpenAICompletionsConfig` (Chat Completions and OpenAI-compatible `base_url` endpoints such as vLLM / LM Studio), `AnthropicConfig`, `GeminiConfig`, `VertexAIConfig`, `BedrockConfig`, `MistralConfig`, `XAIConfig`, `ZAIConfig`, `OllamaConfig`, `DashScopeConfig`, `config.copy(...)`, per-ask `config=`, and env-var fallback for API keys. For tools see `ag2-add-custom-tool`; typed output `ag2-structured-output`; images/files `ag2-multimodal-input`; tests `ag2-testing`.
- Reads credentials
- Installs packages
1 other project uses a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- ag2ai/build-with-ag2edited, first seen Oct 9, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 1
- ag2ai/build-with-ag2★ 25219% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository27 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- ag2-a2aSkill
- ag2-acpSkill
- ag2-add-custom-toolSkill
- ag2-ag-uiSkill
- ag2-eval-comparisonSkill
- ag2-evaluationSkill
- ag2-hitlSkill
- ag2-knowledge-and-memorySkill
- ag2-liveSkill
- ag2-mcpSkill
- ag2-middlewareSkill
- ag2-multimodal-inputSkill
- ag2-network-discussionSkill
- ag2-network-governanceSkill
- ag2-network-quickstartSkill
- ag2-network-tools-and-viewsSkill
- ag2-network-workflowSkill
- ag2-observers-and-alertsSkill
- ag2-overviewSkill
- ag2-shell-toolSkill
- ag2-structured-outputSkill
- ag2-subagent-delegationSkill
- ag2-telemetrySkill
- ag2-testingSkill
- ag2-use-builtin-toolsSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 44
All live in ag2.config. Load keys from a project-root .env with from dotenv import load_dotenv.
- Very specific: line 74
Every config takes model=, optional api_key= (falls back to the env var), and streaming=True where supported — enable streaming, AG2 is …
- Very specific: line 96
Anthropic: don't pass temperature / top_p / top_k — deprecated (removed in 1.4.0.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Quickstart: build your first AG2 Agent
When to use
- Starting from a blank file and needing a working AG2 agent.
- Unsure which provider config class to use.
- Chaining follow-up turns without losing conversation context.
- A larger task needs the basic Agent skeleton — start here, then layer a feature skill on top.
Prerequisites
Required step: install dependencies before finishing. Install the provider extra (plus any feature extra the task needs, e.g.
ag-ui,tracing):pip install "ag2[openai]" # swap in the provider/extra you usedIf you cannot run commands, state the exact
pip installcommand. For a multi-file project also add arequirements.txt, e.g.ag2[openai]>=1.3.0.
Without the matching extra a config raises ImportError: ... Install with pip install "ag2[<provider>]".
| Provider | Extra | Env var | Config class |
| OpenAI (Responses API — default) | openai | OPENAI_API_KEY | OpenAIResponsesConfig |
| OpenAI Chat Completions / OpenAI-compatible | openai | OPENAI_API_KEY | OpenAICompletionsConfig |
| Anthropic | anthropic | ANTHROPIC_API_KEY | AnthropicConfig |
| Gemini (API key) | gemini | GEMINI_API_KEY / GOOGLE_API_KEY | GeminiConfig |
| Gemini on Vertex AI | gemini | ADC / service account | VertexAIConfig |
| Amazon Bedrock | bedrock | AWS creds or AWS_BEARER_TOKEN_BEDROCK | BedrockConfig |
| Mistral | mistral | MISTRAL_API_KEY | MistralConfig |
| xAI (Grok) | xai | XAI_API_KEY | XAIConfig |
| Z.AI (GLM) | zai | ZAI_API_KEY | ZAIConfig |
| Ollama (local) | ollama | — | OllamaConfig |
| DashScope (Qwen) | dashscope | DASHSCOPE_API_KEY | DashScopeConfig |
All live in ag2.config. Load keys from a project-root .env with from dotenv import load_dotenv; load_dotenv().
Migration note:
OpenAIConfigis deprecated in 1.3.0 (emitsDeprecationWarning) and becomes an alias ofOpenAIResponsesConfigin 1.4.0. Don't write new code with it.
60-second recipe
import asyncio
from ag2 import Agent
from ag2.config import OpenAIResponsesConfig
async def main() -> None:
agent = Agent(
"assistant",
prompt="You are a helpful assistant. Reply in one sentence.",
config=OpenAIResponsesConfig(model="gpt-4.1-mini", streaming=True),
)
reply = await agent.ask("What is the capital of France?")
print(reply.body) # str | None — the text answer
reply = await reply.ask("And of Germany?") # same conversation
print(reply.body)
asyncio.run(main())Reading the answer: reply.body is the raw text (sync property). await reply.content() returns the typed value when a response_schema is set (see ag2-structured-output); without a schema it just returns reply.body. Use reply.body for plain text.
Picking a provider
Every config takes model=, optional api_key= (falls back to the env var), and streaming=True where supported — enable streaming, AG2 is streaming-first.
from ag2.config import OpenAIResponsesConfig, OpenAICompletionsConfig, AnthropicConfig, GeminiConfig
OpenAIResponsesConfig(model="gpt-4.1-mini", streaming=True) # new OpenAI code
OpenAICompletionsConfig(model="gpt-4.1-mini", streaming=True) # explicit Chat Completions
AnthropicConfig(model="claude-haiku-4-5", streaming=True)
GeminiConfig(model="gemini-3.6-flash", streaming=True)OpenAI-compatible endpoints (vLLM, LM Studio, Together, NVIDIA NIM…) speak Chat Completions — use OpenAICompletionsConfig with base_url=:
config = OpenAICompletionsConfig(
model="qwen-3",
base_url="http://localhost:8000/v1",
api_key="NotRequired", # pragma: allowlist secret
)Provider gotchas:
- Anthropic: don't pass
temperature/top_p/top_k— deprecated (removed in 1.4.0; the anthropic 2.x API rejects them). Customhttp_client=must be anhttpx2.AsyncClient. - OpenAI reasoning:
OpenAIResponsesConfig(reasoning={"effort": "low"})vsOpenAICompletionsConfig(reasoning_effort="low"). Responses usesmax_output_tokens(notmax_tokens). - Reasoning models (
gpt-5*,o*) rejecttemperature; use it ongpt-4.1*/ Gemini.
Multi-turn — chain reply.ask()
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 prior turns in scope. Calling agent.ask(...) again starts a fresh conversation. Full example: assets/multi_turn.py.
Reusing model configs
Configs are immutable; fork with .copy(...):
base = OpenAIResponsesConfig(model="gpt-4.1-mini")
hot = base.copy(temperature=0.8)
cheap = base.copy(model="gpt-5-nano")Override the model per ask (e.g. bring-your-own-key per request) — this fully replaces the agent's config for that turn, no merge:
agent = Agent("assistant", prompt="Help.")
reply = await agent.ask("Hello!", config=OpenAIResponsesConfig(model="gpt-4.1-mini", api_key=user_key))Going deeper
- Starters:
assets/hello_agent.py,assets/multi_turn.py. - Full provider reference (Vertex auth, Bedrock auth,
extra_body,httpx2clients, OpenAI Decisions / TypeSafe):website/docs/user-guide/model_configuration.mdx. - Agent API (events, streaming, HITL):
website/docs/user-guide/agents.mdx; prompts:system_prompts.mdx.
Common pitfalls
- Forgetting
await— allAgent/AgentReplymethods are async; wrap scripts inasyncio.run(main()). - Expecting
agent.ask()to remember — usereply.ask(). - Hardcoding API keys — rely on env-var fallback.
reply.content()withoutawait— it's a coroutine; for plain text just usereply.body.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

