-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathagent.py
More file actions
60 lines (49 loc) · 1.84 KB
/
agent.py
File metadata and controls
60 lines (49 loc) · 1.84 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain.memory import ConversationBufferMemory
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_openai import ChatOpenAI
from hyperpocket_langchain import PocketLangchain
def agent(pocket: PocketLangchain):
tools = pocket.get_tools()
llm = ChatOpenAI(model="gpt-4o", api_key=os.getenv("OPENAI_API_KEY"))
prompt = ChatPromptTemplate.from_messages(
[
("placeholder", "{chat_history}"),
(
"system",
"You are a tool calling assistant. You can help the user by calling proper tools",
),
("placeholder", "{chat_history}"),
("user", "{input}"),
MessagesPlaceholder(variable_name="agent_scratchpad"),
]
)
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
agent = create_tool_calling_agent(llm, tools, prompt)
agent_executor = AgentExecutor(
agent=agent,
tools=tools,
memory=memory,
verbose=True,
handle_parsing_errors=True,
)
print("\n\n\n")
print("Hello, this is linkedin browseruse agent.")
while True:
print("user(q to quit) : ", end="")
user_input = input()
if user_input == "q":
print("Good bye!")
break
response = agent_executor.invoke({"input": user_input})
print("slack agent : ", response["output"])
print()
if __name__ == "__main__":
with PocketLangchain(
tools=[
"https://github.com/vessl-ai/hyperpocket/tree/kyle/tools/tools/linkedin/get-recent-connections",
"https://github.com/vessl-ai/hyperpocket/tree/kyle/tools/tools/linkedin/send-messages",
],
) as pocket:
agent(pocket)