-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandalone_node.py
More file actions
37 lines (27 loc) · 1.04 KB
/
standalone_node.py
File metadata and controls
37 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# ruff: noqa: N801, N805
"""Standalone node — the simplest way to use langchain-agentkit.
Declare a class with the node metaclass and get a complete ReAct agent
with skill support. The result is a StateGraph — call .compile() to run it.
"""
from langchain_core.messages import HumanMessage
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
from langchain_agentkit import node
@tool
def web_search(query: str) -> str:
"""Search the web for information."""
return f"Results for: {query}"
class researcher(node):
llm = ChatOpenAI(model="gpt-4o")
tools = [web_search]
skills = "skills/"
async def handler(state, *, llm):
response = await llm.ainvoke(state["messages"])
return {"messages": [response], "sender": "researcher"}
# researcher is a StateGraph — compile and invoke
if __name__ == "__main__":
graph = researcher.compile()
result = graph.invoke(
{"messages": [HumanMessage("Size the B2B SaaS market in Europe")]}
)
print(result["messages"][-1].content)