머니페니 76e3220e77
All checks were successful
Deploy to Production / deploy (push) Successful in 3m10s
feat: 에이전트 기능 추가 (LLM 서비스, 에이전트 API, 테스트)
2026-05-06 20:56:45 +09:00

41 lines
1.3 KiB
Python

from __future__ import annotations
from typing import Any
from app.agents.tools.types import RegisteredTool, ToolResult
def create_web_search_tool() -> RegisteredTool:
"""웹 검색 도구를 생성합니다."""
async def execute(params: dict[str, Any]) -> ToolResult:
query: str = params["query"]
num_results: int = params.get("num_results", 5)
# TODO: settings에서 API 키 로드 후 Tavily/Exa/SerpAPI 연동
try:
from app.core.config import settings
api_key = getattr(settings, "web_search_api_key", None)
except Exception:
api_key = None
if not api_key:
return ToolResult(
data=f"검색 API 미설정: '{query}' (요청 결과 수: {num_results}). "
"web_search_api_key 환경변수를 설정해 주세요.",
)
# 향후 실제 검색 API 호출 구현
# async with httpx.AsyncClient() as client:
# response = await client.get(...)
return ToolResult(data=f"검색 결과 없음: '{query}'")
return RegisteredTool(
name="web_search",
description="웹 검색을 수행하여 최신 정보를 조회합니다",
compact_description="웹 검색",
concurrency_safe=True,
execute=execute,
)