33from langchain_openai import ChatOpenAI
44from langchain_core .messages import HumanMessage , SystemMessage
55from langchain_core .tools import tool
6- from langchain .agents import create_tool_calling_agent , AgentExecutor
6+ from langchain .agents import create_agent
77from langchain_core .prompts import ChatPromptTemplate
88
99import sentry_sdk
@@ -27,35 +27,36 @@ def calculate_tip(bill_amount: float, tip_percentage: float) -> float:
2727def my_pipeline (llm , tools ):
2828 with sentry_sdk .start_transaction (name = "langchain-sync-tool" ):
2929 # Create agent with tools
30- prompt = ChatPromptTemplate .from_messages ([
31- ("system" , "You are a helpful assistant that can use tools to help answer questions." ),
32- ("placeholder" , "{chat_history}" ),
33- ("human" , "{input}" ),
34- ("placeholder" , "{agent_scratchpad}" ),
35- ])
36-
37- agent = create_tool_calling_agent (llm , tools , prompt )
38- agent_executor = AgentExecutor (agent = agent , tools = tools , verbose = True )
30+ agent = create_agent (
31+ model = llm ,
32+ tools = tools ,
33+ system_prompt = "You are a helpful assistant that can use tools to help answer questions" ,
34+ ).with_config (config = {"run_name" : "MyAgent1" })
3935
4036 # Test with weather tool
41- result1 = agent_executor .invoke ({
42- "input" : "What's the weather like in San Francisco, CA?"
43- })
37+ result1 = agent .invoke (
38+ {
39+ "messages" : [
40+ {
41+ "role" : "user" ,
42+ "content" : "What's the weather like in San Francisco, CA?" ,
43+ }
44+ ]
45+ }
46+ )
4447 print ("Weather Result:" )
4548 print (result1 )
4649
4750 # Test with calculation tool
48- result2 = agent_executor .invoke ({
49- "input" : "Calculate a 18% tip on a $45.50 bill"
50- })
51+ result2 = agent .invoke ({"input" : "Calculate a 18% tip on a $45.50 bill" })
5152 print ("Tip Calculation Result:" )
5253 print (result2 )
5354
5455 # Test streaming with agent
5556 print ("Streaming Result:" )
56- for chunk in agent_executor .stream ({
57- "input" : "What's the weather in New York and calculate a 20% tip on $30?"
58- } ):
57+ for chunk in agent .stream (
58+ { "input" : "What's the weather in New York and calculate a 20% tip on $30?" }
59+ ):
5960 print (chunk )
6061
6162
0 commit comments