도구 준비

도구 준비 (Prepare Tools)

PrepareToolsPrepareOutputToolsToolsPrepareFunc캐퍼빌리티로 감싸서, 스텝마다 도구 정의를 필터링하거나 수정하게 해 줘요. PrepareTools는 함수 도구를, PrepareOutputTools출력 도구를 다룹니다.

출처: 문서

본문

from pydantic_ai import Agent, RunContext, ToolDefinition
from pydantic_ai.capabilities import PrepareTools


async def hide_dangerous(ctx: RunContext, tool_defs: list[ToolDefinition]) -> list[ToolDefinition]:
    return [td for td in tool_defs if not td.name.startswith('delete_')]


agent = Agent('openai:gpt-5.2', capabilities=[PrepareTools(hide_dangerous)])


@agent.tool_plain
def delete_file(path: str) -> str:
    """Delete a file."""
    return f'deleted {path}'


@agent.tool_plain
def read_file(path: str) -> str:
    """Read a file."""
    return f'contents of {path}'


result = agent.run_sync('hello')
# The model only sees `read_file`, not `delete_file`

더 복잡한 도구 준비 로직이 필요하다면, 라이프사이클 훅의 Tool preparation을 참고하세요.

더 알아보기 (Learn more)