Skip to main content

add-tool

Add a properly typed and registered tool function to an existing AG2 agent setup. Generates the function with schema, type annotations, and correct registration on both caller and executor agents.

소스 정보

저장소
ag2ai/cursor-plugin
최근 소스 활동
2026년 3월 11일 22:30
감지된 SKILL.md 언어
영어
스타
0
포크
0

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
add-tool
description
Add a properly typed and registered tool function to an existing AG2 agent setup. Generates the function with schema, type annotations, and correct registration on both caller and executor agents.
# Add Tool to AG2 Agent You are an expert at adding tools to AG2 agents. When the user asks to add a tool/function: ## 1. Understand the Requirements - What should the tool do? - Which agent should CALL it (register_for_llm)? - Which agent should EXECUTE it (register_for_execution)? - What parameters does it need? - What does it return? ## 2. Generate the Tool Follow this pattern exactly: ```python from typing import Annotated @executor_agent.register_for_execution() @caller_agent.register_for_llm(description="Clear description of what this tool does") def tool_name( param1: Annotated[str, "Description of param1"], param2: Annotated[int, "Description of param2"] = default_value, ) -> str: """Detailed description used as the tool's description for the LLM.""" # Implementation return result ``` ## 3. Rules - Always use `Annotated[type, "description"]` for every parameter — this generates the JSON schema - The function docstring becomes the tool description if no `description=` is passed to `register_for_llm()` - Return type should be `str` for simple tools — LLMs work best with string outputs - `@register_for_llm()` must be the INNER decorator (closest to `def`) - `@register_for_execution()` must be the OUTER decorator - For complex return types, serialize to JSON string - If the tool needs conversation context, use dependency injection: ```python from autogen.tools import ChatContext, Depends @executor.register_for_execution() @caller.register_for_llm(description="Context-aware tool") def my_tool( query: Annotated[str, "The query"], context: ChatContext = Depends(ChatContext), ) -> str: messages = context.chat_messages return process(query, messages) ``` ## 4. Alternative: Tool Class If the user prefers explicit Tool objects: ```python from autogen.tools import Tool tool = Tool( name="tool_name", description="What it does", func_or_tool=my_function, ) tool.register_for_llm(caller_agent) tool.register_for_execution(executor_agent) # Or: tool.register_tool(agent) # registers both on same agent ``` ## 5. Verify After generating, check: - [ ] Type annotations on all parameters - [ ] Descriptive `Annotated` strings for each parameter - [ ] Decorator order is correct (execution outer, llm inner) - [ ] Return type is specified - [ ] Description clearly tells the LLM WHEN to use this tool
GitHub에서 보기