Skip to content

Commit aa1730a

Browse files
Merge pull request #4 from getsentry/constantinius/feat/langchain/v1-updates
feat: updates for langchain v1
2 parents 9ec1e16 + 7814bb2 commit aa1730a

File tree

4 files changed

+578
-967
lines changed

4 files changed

+578
-967
lines changed

test-langchain2/main_tool.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from langchain_openai import ChatOpenAI
44
from langchain_core.messages import HumanMessage, SystemMessage
55
from langchain_core.tools import tool
6-
from langchain.agents import create_tool_calling_agent, AgentExecutor
6+
from langchain.agents import create_agent
77
from langchain_core.prompts import ChatPromptTemplate
88

99
import sentry_sdk
@@ -27,35 +27,36 @@ def calculate_tip(bill_amount: float, tip_percentage: float) -> float:
2727
def 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

test-langchain2/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ requires-python = ">=3.12"
55

66
dependencies = [
77
"ipdb>=0.13.13",
8-
"langchain>=0.3.27",
9-
"langchain-community>=0.3.27",
10-
"langchain-openai>=0.3.28",
8+
"langchain>=1.0.3",
9+
# "langchain-community>=0.3.27",
10+
"langchain-openai>=1.0.2",
1111
"pudb>=2025.1",
1212
"sentry-sdk",
1313
"tiktoken>=0.10.0",

test-langchain2/run_tool.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)