LangGraph ToolNode 사용 방법
여기에 입력하면 된다.
ToolNode 란
ToolNode 란 도구 호출을 위한 LangGraph 의 pre-built 된 함수이다. ToolNod 는 메시지 목록이 포함된 그래프 상태를 입력으로 받아 도구 호출 결과로 상태를 업데이트하는 LangChain Runnable 이다.
StateGraph 와 함께 사용하는 경우 적절한 리듀서가 있는 messages 키를 포함하고 있어야한다.
Define Tools
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from langchain_core.messages import AIMessage
from langchain_core.tools import tool
from langgraph.prebuilt import ToolNode
@tool
def get_weather(location: str):
"""Call to get the current weather."""
if location.lower() in ["sf", "san francisco"]:
return "It's 60 degrees and foggy."
else:
return "It's 90 degrees and sunny."
@tool
def get_coolest_cities():
"""Get a list of coolest cities"""
return "nyc, sf"
tools = [get_weather, get_coolest_cities]
tool_node = ToolNode(tools)
ToolNode 수동으로 호출하기
ToolNode는 메시지 목록을 포함한 그래프 상태에서 작동한다. 메시지 목록의 마지막 메시지는AIMessage여야 하며,tool_calls매개변수를 포함하고 있어야 한다.
1
2
3
4
5
6
7
8
9
10
11
12
13
message_with_single_tool_call = AIMessage(
content='',
tool_calls=[
{
'name': 'get_weather',
'args': {'location': 'sf'},
'id': 'tool_call_id',
'type': 'tool_call'
}
]
)
tool_node.invoke({'messages': [message_with_single_tool_call]})
1
Google AdSense — Post Ad
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.
Comments powered by Disqus.