tu101 commited on
Commit
b3534d9
·
verified ·
1 Parent(s): bbd26e0
Files changed (1) hide show
  1. real_agent.py +42 -39
real_agent.py CHANGED
@@ -19,44 +19,47 @@ os.environ["LANGFUSE_HOST"] = "https://us.cloud.langfuse.com"
19
 
20
  os.environ["OPENAI_API_KEY"] = "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"
21
 
22
- langfuse_handler = CallbackHandler()
23
 
24
- # Initialize the web search tool
25
- new_search_tool = DuckDuckGoSearchRun()
26
-
27
-
28
- # Generate the chat interface, including the tools
29
- #llm = ChatOpenAI(model="gpt-4o")
30
-
31
- chat = ChatOpenAI(model="gpt-4o")
32
- tools = [guest_info_tool, new_search_tool, weather_info_tool, hub_stats_tool]
33
- chat_with_tools = chat.bind_tools(tools)
34
- #llm_with_tools = llm.bind_tools(tools, parallel_tool_calls=False)
35
-
36
- # Generate the AgentState and Agent graph
37
- class AgentState(TypedDict):
38
- messages: Annotated[list[AnyMessage], add_messages]
39
-
40
- def assistant(state: AgentState):
41
- return {
42
- "messages": [chat_with_tools.invoke(state["messages"])],
43
- }
44
-
45
- ## The graph
46
- builder = StateGraph(AgentState)
47
-
48
- # Define nodes: these do the work
49
- builder.add_node("assistant", assistant)
50
- builder.add_node("tools", ToolNode(tools))
51
-
52
- # Define edges: these determine how the control flow moves
53
- builder.add_edge(START, "assistant")
54
- builder.add_conditional_edges(
55
- "assistant",
56
- # If the latest message requires a tool, route to tools
57
- # Otherwise, provide a direct response
58
- tools_condition,
59
- )
60
- builder.add_edge("tools", "assistant")
61
- alfred = builder.compile()
 
 
 
 
62
 
 
19
 
20
  os.environ["OPENAI_API_KEY"] = "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"
21
 
 
22
 
23
+ def call_build():
24
+ langfuse_handler = CallbackHandler()
25
+
26
+ # Initialize the web search tool
27
+ new_search_tool = DuckDuckGoSearchRun()
28
+
29
+
30
+ # Generate the chat interface, including the tools
31
+ #llm = ChatOpenAI(model="gpt-4o")
32
+
33
+ chat = ChatOpenAI(model="gpt-4o")
34
+ tools = [guest_info_tool, new_search_tool, weather_info_tool, hub_stats_tool]
35
+ chat_with_tools = chat.bind_tools(tools)
36
+ #llm_with_tools = llm.bind_tools(tools, parallel_tool_calls=False)
37
+
38
+ # Generate the AgentState and Agent graph
39
+ class AgentState(TypedDict):
40
+ messages: Annotated[list[AnyMessage], add_messages]
41
+
42
+ def assistant(state: AgentState):
43
+ return {
44
+ "messages": [chat_with_tools.invoke(state["messages"])],
45
+ }
46
+
47
+ ## The graph
48
+ builder = StateGraph(AgentState)
49
+
50
+ # Define nodes: these do the work
51
+ builder.add_node("assistant", assistant)
52
+ builder.add_node("tools", ToolNode(tools))
53
+
54
+ # Define edges: these determine how the control flow moves
55
+ builder.add_edge(START, "assistant")
56
+ builder.add_conditional_edges(
57
+ "assistant",
58
+ # If the latest message requires a tool, route to tools
59
+ # Otherwise, provide a direct response
60
+ tools_condition,
61
+ )
62
+ builder.add_edge("tools", "assistant")
63
+
64
+ return builder.compile()
65