Mastering Python Skill
SpillwaveSolutions/agent-brain
Modern Python coaching covering language foundations through advanced production patterns.
Add a custom Python tool to an AG2 beta Agent using the @tool decorator.
$ npx skills add ag2ai/build-with-ag2 --skill ag2-add-custom-tool -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install ag2ai/build-with-ag2 ag2-add-custom-tool --agent claude-codeProject scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).
$ git clone --depth 1 https://github.com/ag2ai/build-with-ag2.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/ag2-add-custom-tool .claude/skills/ag2-add-custom-tool && rm -rf skills-srcUse ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.
Claude Code skills documentation · loads skills from .claude/skills/
Install the "ag2-add-custom-tool" agent skill from https://github.com/ag2ai/build-with-ag2/tree/main/.agents/skills/ag2-add-custom-tool into .claude/skills/ag2-add-custom-tool/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "ag2-add-custom-tool", then confirm the skill loads.Claude Code copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$skill-installer install https://github.com/ag2ai/build-with-ag2/tree/main/.agents/skills/ag2-add-custom-toolType this inside Codex. $skill-installer <name> installs a curated skill from openai/skills. The installer writes to $CODEX_HOME/skills (default ~/.codex/skills). Restart Codex if the skill does not show up.
$ npx skills add ag2ai/build-with-ag2 --skill ag2-add-custom-tool -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install ag2ai/build-with-ag2 ag2-add-custom-tool --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/ag2ai/build-with-ag2.git skills-src && mkdir -p .agents/skills && cp -r skills-src/.agents/skills/ag2-add-custom-tool .agents/skills/ag2-add-custom-tool && rm -rf skills-srcUse ~/.agents/skills/ instead of .agents/skills for a personal install.
Codex skills documentation · loads skills from .agents/skills/
Install the "ag2-add-custom-tool" agent skill from https://github.com/ag2ai/build-with-ag2/tree/main/.agents/skills/ag2-add-custom-tool into .agents/skills/ag2-add-custom-tool/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "ag2-add-custom-tool", then confirm the skill loads.Codex copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add ag2ai/build-with-ag2 --skill ag2-add-custom-tool -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install ag2ai/build-with-ag2 ag2-add-custom-tool --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/ag2ai/build-with-ag2.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/.agents/skills/ag2-add-custom-tool .cursor/skills/ag2-add-custom-tool && rm -rf skills-srcUse ~/.cursor/skills/ instead of .cursor/skills for a personal install.
Cursor skills documentation · loads skills from .cursor/skills/, .agents/skills/, .claude/skills/, .codex/skills/
Install the "ag2-add-custom-tool" agent skill from https://github.com/ag2ai/build-with-ag2/tree/main/.agents/skills/ag2-add-custom-tool into .cursor/skills/ag2-add-custom-tool/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "ag2-add-custom-tool", then confirm the skill loads.Cursor copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gemini skills install https://github.com/ag2ai/build-with-ag2.git --path .agents/skills/ag2-add-custom-tool--scope user (default) or --scope workspace; --path is the subfolder of the repo that holds the skill; --consent skips the security confirmation prompt.
$ npx skills add ag2ai/build-with-ag2 --skill ag2-add-custom-tool -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install ag2ai/build-with-ag2 ag2-add-custom-tool --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/ag2ai/build-with-ag2.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/.agents/skills/ag2-add-custom-tool .gemini/skills/ag2-add-custom-tool && rm -rf skills-srcUse ~/.gemini/skills/ instead of .gemini/skills for a personal install, then run /skills reload.
Gemini CLI skills documentation · loads skills from .gemini/skills/, .agents/skills/
Install the "ag2-add-custom-tool" agent skill from https://github.com/ag2ai/build-with-ag2/tree/main/.agents/skills/ag2-add-custom-tool into .gemini/skills/ag2-add-custom-tool/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "ag2-add-custom-tool", then confirm the skill loads.Gemini CLI copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gh skill install ag2ai/build-with-ag2 ag2-add-custom-toolInstalls for Copilot at project scope by default; add --scope user for a personal install. Preview a skill first with gh skill preview. Needs GitHub CLI 2.90.0 or later (public preview).
$ npx skills add ag2ai/build-with-ag2 --skill ag2-add-custom-tool -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/ag2ai/build-with-ag2.git skills-src && mkdir -p .github/skills && cp -r skills-src/.agents/skills/ag2-add-custom-tool .github/skills/ag2-add-custom-tool && rm -rf skills-srcUse ~/.copilot/skills/ instead of .github/skills for a personal install. Commit .github/skills so cloud agent and code review can use it.
GitHub Copilot skills documentation · loads skills from .github/skills/, .claude/skills/, .agents/skills/
Install the "ag2-add-custom-tool" agent skill from https://github.com/ag2ai/build-with-ag2/tree/main/.agents/skills/ag2-add-custom-tool into .github/skills/ag2-add-custom-tool/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "ag2-add-custom-tool", then confirm the skill loads.GitHub Copilot copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add ag2ai/build-with-ag2 --skill ag2-add-custom-tool -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install ag2ai/build-with-ag2 ag2-add-custom-tool --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/ag2ai/build-with-ag2.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/.agents/skills/ag2-add-custom-tool .opencode/skills/ag2-add-custom-tool && rm -rf skills-srcUse ~/.config/opencode/skills/ instead of .opencode/skills for a personal install.
OpenCode skills documentation · loads skills from .opencode/skills/, .claude/skills/, .agents/skills/
Install the "ag2-add-custom-tool" agent skill from https://github.com/ag2ai/build-with-ag2/tree/main/.agents/skills/ag2-add-custom-tool into .opencode/skills/ag2-add-custom-tool/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "ag2-add-custom-tool", then confirm the skill loads.OpenCode copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
ag2-add-custom-toolAdd a custom Python tool to an AG2 beta Agent using the @tool decorator.
Ag2 Add Custom Tool is an agent skill from ag2ai/build-with-ag2. Add a custom Python tool to an AG2 beta Agent using the @tool decorator. Use when the user wants to give an Agent a new capability backed by Python code (API calls, DB queries, computations, file ops). Covers sync and async tools, parameter typing, Pydantic schema customisation, returning typed Input / ToolResult (text / data / images / binary), final=True early-exit, and dependency injection via Context / Inject / Variable / Depends.
Its SKILL.md is about 1.9k tokens, which your agent loads only when the skill is triggered. The skill folder holds 2 other files, including reference files (for example `references/dependency_injection.md`).
It sits in Development, covering Design patterns. It works with Python and Pydantic. The repository describes itself as: Sample code and application showcases to get you going with AG2 (formally AutoGen). The licence is Apache-2.0.
Read from SKILL.md and the folder at commit 29eeac3. It shows what the files ask for, not the result of running them.
Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.
From allowed-tools in the SKILL.md frontmatter.
No scripts in the folder and no shell commands in SKILL.md (its code samples are python).
From the folder's file list and the shell code blocks in SKILL.md.
No URLs in SKILL.md.
From URLs in SKILL.md, links to its own repository left out.
Names no API keys, tokens, secrets or passwords.
From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.
Ag2 Add Custom Tool loads about 1.9k tokens when it runs, and up to ~3.2k if it reads all its reference files. Until then it costs about 119 tokens; SKILL.md has 495 words of instructions outside code blocks.
Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.
The automated check found no risky patterns in SKILL.md.
Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.
The full file from ag2ai/build-with-ag2 at commit 29eeac3, republished under its Apache-2.0 licence (© ag2ai). 495 words, ~1,863 tokens.
.claude/skills/ag2-add-custom-tool/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.The user wants their Agent to take a real-world action: hit an API, query a database, compute something, return an image. If they want shipped tools (web search, code exec, shell), see ag2-use-builtin-tools and ag2-shell-tool instead.
from autogen.beta import Agent, tool
from autogen.beta.config import OpenAIConfig
@tool
def calculate_shipping_cost(destination: str, weight_kg: float) -> str:
"""Calculates shipping cost for a package to a destination."""
return "$15.00"
agent = Agent(
"shipping",
prompt="Use tools when helpful.",
config=OpenAIConfig(model="gpt-4o-mini"),
tools=[calculate_shipping_cost],
)The @tool decorator generates the LLM-facing schema from the function signature, type hints, and docstring. The docstring is the description the LLM sees — write it for an LLM reader, not just a human.
You can also pass plain undecorated functions in tools=[...] and AG2 wraps them automatically:
def get_weather(location: str) -> str:
"""Returns the current weather for a given location."""
return "Sunny, 22°C"
agent = Agent("weather", tools=[get_weather])Or attach a tool to an existing agent with @agent.tool:
agent = Agent("calc")
@agent.tool
def multiply(a: int, b: int) -> int:
"""Multiplies two integers and returns the result."""
return a * bBoth def and async def are supported. Synchronous tools run in a thread by default so blocking I/O does not freeze the event loop. For ultra-fast pure-Python tools, opt out:
@tool(sync_to_thread=False)
def format_name(first: str, last: str) -> str:
"""Formats a full name."""
return f"{last.upper()}, {first.capitalize()}"Native async tools run in the main event loop directly:
import aiohttp
@tool
async def fetch(url: str) -> str:
"""Fetches a URL with aiohttp."""
async with aiohttp.ClientSession() as session:
async with session.get(url) as r:
return await r.text()FieldUse Annotated[T, Field(...)] to give the LLM strict bounds. The framework forwards these into the JSON Schema:
from typing import Annotated
from pydantic import Field
from autogen.beta import tool
@tool
def set_temperature(
temp: Annotated[int, Field(description="Target temperature.", ge=10, le=30)],
mode: Annotated[str, Field(description="Mode.", pattern="^(heat|cool|auto)$")],
) -> str:
"""Sets the thermostat."""
return f"Set to {temp}°C in {mode} mode."You can also override the tool name and description on the decorator:
@tool(name="custom_math_tool", description="Performs advanced math.")
def math_op(a: int, b: int) -> int:
return a + bInput / ToolResultA plain str return is wrapped in TextInput automatically. For richer payloads, return an Input subtype or compose with ToolResult:
from autogen.beta import DataInput, ImageInput, TextInput, ToolResult, tool
@tool
def get_status(task_id: str) -> TextInput:
return TextInput(f"Task {task_id} is in progress.")
@tool
def get_user_profile(user_id: str) -> DataInput:
return DataInput({"id": user_id, "name": "Alice", "role": "admin"})
@tool
def fetch_chart(chart_id: str) -> ImageInput:
return ImageInput(f"https://charts.example.com/{chart_id}.png")
@tool
def analyze_product(product_id: str) -> ToolResult:
"""Returns image + structured metadata in one tool call."""
return ToolResult(
ImageInput(f"https://cdn.example.com/products/{product_id}.jpg"),
{"id": product_id, "name": "Widget Pro", "stock": 42},
)For raw bytes of arbitrary format, use BinaryInput(data=..., media_type="application/pdf").
final=TrueWhen the tool already knows the exact final answer, skip the extra LLM round-trip:
from autogen.beta import ToolResult, tool
@tool
def handoff_to_human(ticket_id: str) -> ToolResult:
"""Escalates and returns the final user-facing message verbatim."""
return ToolResult(f"Ticket {ticket_id} was escalated.", final=True)A final=True ToolResult must contain exactly one part (TextInput or DataInput).
Tools can pull execution-time values without exposing them to the LLM. See references/dependency_injection.md for the full table; the basics:
from typing import Annotated
from autogen.beta import Context, Inject, Variable, tool
@tool
def query_db(query: str, ctx: Context) -> str:
"""Runs a SQL query."""
db = ctx.dependencies["db"]
return db.execute(query)
@tool
def fetch(url: str, http: Annotated[object, Inject("http_session")]) -> str:
"""Fetches with a shared HTTP session."""
return http.get(url).text
@tool
def send(text: str, api_key: Annotated[str, Variable()]) -> str:
"""Sends a message via the configured channel."""
...Inject annotations are stripped from the LLM-facing schema — they're an internal injection mechanism.
references/dependency_injection.md — Context vs Inject vs Variable vs Depends, defaults, factories, mutability, overrides.website/docs/beta/tools/tools.mdx — full @tool reference, including the synthesized JSON Schema.website/docs/beta/depends.mdx — Depends lifecycle, yield-based teardown, caching, test overrides.website/docs/beta/inputs/inputs.mdx — the Input factory hierarchy and provider support matrix.website/docs/beta/tools/toolkits.mdx — bundle related tools into a reusable Toolkit.website/docs/beta/tools/tool_middleware.mdx — async hooks around a single tool (validation, redaction, approval — see also ag2-hitl).def (sync) tool with heavy CPU or network and pass sync_to_thread=False, the loop blocks. Default behaviour (run in a thread) is safe; only opt out for cheap pure-Python work.import to module top.dict directly when you wanted structured data — wrap it in DataInput(...) so the framework treats it as structured rather than coercing to text.final=True requires exactly one part — combining multiple Inputs with final=True will raise.© ag2ai, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file
SKILL.md and 1 other file (references) in .agents/skills/ag2-add-custom-tool of ag2ai/build-with-ag2.
Open the folder on GitHubat commit 29eeac3
Ag2 Add Custom Tool next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.
| Skill | Stars | Used in | Tokens | Auto-check | Licence | Repo updated |
|---|---|---|---|---|---|---|
| Ag2 Add Custom Tool this skillag2ai/build-with-ag2 | 252 | — | ~1.9k | Automated safety check: Pass | Apache-2.0 | |
| Mastering Python SkillSpillwaveSolutions/agent-brain | 119 | — | ~1.4k | Automated safety check: Notes | MIT | |
| Framework Migration AssistantArabelaTso/Skills-4-SE | 253 | — | ~1.9k | Automated safety check: Pass | Apache-2.0 | |
| Pydantic AIdavila7/claude-code-templates | 33k | 3 repos | ~2.9k | Automated safety check: Pass | MIT | |
| Fastapi Backendcohen-liel/hivemind | 110 | — | ~710 | Automated safety check: Pass | Apache-2.0 | |
| Python Fastapi Patternsaiskillstore/marketplace | 433 | 1 repos | ~1.3k | Automated safety check: Notes | None |
SpillwaveSolutions/agent-brain
Modern Python coaching covering language foundations through advanced production patterns.
ArabelaTso/Skills-4-SE
Automatically migrate Python web applications between frameworks (Flask → FastAPI, Django → FastAPI).
davila7/claude-code-templates
Build production-ready AI agents with PydanticAI — type-safe tool use, structured outputs, dependency injection, and multi-model support.
cohen-liel/hivemind
FastAPI best practices for building production Python backends.
aiskillstore/marketplace
FastAPI web framework patterns. An agent skill from aiskillstore/marketplace.
Kilo-Org/kilo-marketplace
FastAPI Python framework. An agent skill from Kilo-Org/kilo-marketplace.
ag2ai/build-with-ag2
Intercept the AG2 beta agent loop with BaseMiddleware — wrap full turns (onturn), each LLM call (onllmcall), each tool execution (ontoolexecution), or each human-input request (onhumaninput).
ag2ai/build-with-ag2
Wire AG2 beta's shipped tools into an Agent — both provider-native server-side tools (web search, web fetch, code execution, MCP, image generation, memory) and locally-executed common toolkits…
ag2ai/build-with-ag2
Persist agent state across runs, shape what the LLM sees per turn, and cap history to fit a context window.
ag2ai/build-with-ag2
Monitor an AG2 beta agent's stream — log events, detect repeated tool calls, track token spend, build trigger-driven observers, route observer alerts to the model, and halt on FATAL conditions.
ag2ai/build-with-ag2
Build a minimal AG2 beta Agent end to end — pick a model provider, set a prompt, call agent.ask(), then continue the conversation with reply.ask() (multi-turn).
ag2ai/build-with-ag2
Get a typed Python value back from an AG2 beta Agent instead of free text.
Categories
Add a custom Python tool to an AG2 beta Agent using the @tool decorator. Ag2 Add Custom Tool is an agent skill from ag2ai/build-with-ag2. Add a custom Python tool to an AG2 beta Agent using the @tool decorator.
Ag2 Add Custom Tool fits situations like: the user wants to give an Agent a new capability backed by Python code (API calls; tasks that involve Design patterns.
Run `npx skills add ag2ai/build-with-ag2 --skill ag2-add-custom-tool -a claude-code`. Or copy the skill folder (.agents/skills/ag2-add-custom-tool in ag2ai/build-with-ag2) into .claude/skills/ag2-add-custom-tool in your project. Claude Code loads it when a task matches its description.
Run `npx skills add ag2ai/build-with-ag2 --skill ag2-add-custom-tool -a codex`. Or copy the skill folder (.agents/skills/ag2-add-custom-tool in ag2ai/build-with-ag2) into .agents/skills/ag2-add-custom-tool in your project. Codex loads it when a task matches its description.
Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add ag2ai/build-with-ag2 --skill ag2-add-custom-tool -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/ag2-add-custom-tool, .gemini/skills/ag2-add-custom-tool, .github/skills/ag2-add-custom-tool and .opencode/skills/ag2-add-custom-tool in your project.
SKILL.md names no scripts, command-line tools or credentials: Ag2 Add Custom Tool is instructions for the agent only. Our summary lists: Python 3.
SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.
Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.
Ag2 Add Custom Tool is published under the Apache-2.0 licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.
About 1.9k tokens (SKILL.md is roughly 7.5k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 1.3k tokens, read only when the agent opens those files.
Skills that share tags, products or a category with Ag2 Add Custom Tool: Mastering Python Skill (SpillwaveSolutions/agent-brain, 119 stars), Framework Migration Assistant (ArabelaTso/Skills-4-SE, 253 stars), Pydantic AI (davila7/claude-code-templates, 33k stars) and Fastapi Backend (cohen-liel/hivemind, 110 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.
ag2ai (a GitHub organization) maintains it in ag2ai/build-with-ag2, which has 252 GitHub stars. The repository holds 16 skills in this directory. The repository was last updated on September 6, 2026.
Source: ag2ai/build-with-ag2 on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.