langchian과 langgraph의 도구는 4가지의 구성 요소를 갖고 있다.
print("자료형: ")
print(type(web_search))
print("-"*100)
print("name: ")
print(web_search.name)
print("-"*100)
print("description: ")
print(web_search.description)
print("-"*100)
print("schema: ")
print(web_search.args_schema.schema())
print("-"*100)
자료형:
<class 'langchain_community.tools.tavily_search.tool.TavilySearchResults'>
----------------------------------------------------------------------------------------------------
name:
tavily_search_results_json
----------------------------------------------------------------------------------------------------
description:
A search engine optimized for comprehensive, accurate, and trusted results. Useful for when you need to answer questions about current events. Input should be a search query.
----------------------------------------------------------------------------------------------------
schema:
{'description': 'Input for the Tavily tool.', 'properties': {'query': {'description': 'search query to look up', 'title': 'Query', 'type': 'string'}}, 'required': ['query'], 'title': 'TavilyInput', 'type': 'object'}
----------------------------------------------------------------------------------------------------
C:\\Users\\rhkdd\\AppData\\Local\\Temp\\ipykernel_27068\\2291713315.py:15: PydanticDeprecatedSince20: The `schema` method is deprecated; use `model_json_schema` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at <https://errors.pydantic.dev/2.11/migration/>
print(web_search.args_schema.schema())
사람의 자연어를 구조화된 JSON이나, 특정 함수가 사용하는 스키마로 변환하는 작업을 Tool Calling이라고 합니다. llm이 도구를 사용하는게 Tool Calling이 아님.
겉으로 봤을때는 도구 하나 들려주고 쓸 수 있게 하는 것 같지만, 내부적으로 일어나는 일은 입력된 자연어를 LLM이 사용할 수 있도록 특정 함수, API를 구조화 하는 것 (Structured Tool으로 변환해 LLM에 바인딩합니다.)
만약 어떤 자연어 입력이 들어왔는데, 도구가 사용가능해보이면 자연어를 해당 도구의 입력에 맞는 스키마로 변환해 함수든 API든 실행해버립니다.
만약 도구 사용이 필요없는 자연어라면 이 경우에는 도구를 호출하지 않고 일반적인 답변을 진행합니다.
즉 LLM은 도구를 사용할지 말지를 스스로 판단한다… 그리고 그런 존재를 에이전트라고 한다.
참고로 이 부분은 langchain 공식 문서에서도 살펴볼 수 있다.
https://python.langchain.com/docs/integrations/tools/tavily_search/