2222
2323import sentry_sdk
2424from sentry_sdk import start_transaction
25+ from sentry_sdk .utils import package_version
2526from sentry_sdk .integrations .langchain import (
2627 LangchainIntegration ,
2728 SentryLangchainCallback ,
3233try :
3334 # langchain v1+
3435 from langchain .tools import tool
36+ from langchain .agents import create_agent
3537 from langchain_classic .agents import AgentExecutor , create_openai_tools_agent # type: ignore[import-not-found]
3638except ImportError :
3739 # langchain <v1
3840 from langchain .agents import tool , AgentExecutor , create_openai_tools_agent
3941
4042from langchain_core .prompts import ChatPromptTemplate , MessagesPlaceholder
41- from langchain .agents import create_agent
4243from langchain_core .messages import HumanMessage , SystemMessage
4344
4445from openai .types .chat .chat_completion_chunk import (
5556 PromptTokensDetails ,
5657)
5758
59+ LANGCHAIN_VERSION = package_version ("langchain" )
60+
5861
5962@tool
6063def get_word_length (word : str ) -> int :
@@ -82,6 +85,10 @@ def _llm_type(self) -> str:
8285 return llm_type
8386
8487
88+ @pytest .mark .skipif (
89+ LANGCHAIN_VERSION < (1 ,),
90+ reason = "LangChain 1.0+ required (ONE AGENT refactor)" ,
91+ )
8592@pytest .mark .parametrize (
8693 "send_default_pii, include_prompts" ,
8794 [
@@ -205,12 +212,12 @@ def test_langchain_create_agent(
205212
206213
207214@pytest .mark .parametrize (
208- "send_default_pii, include_prompts, use_unknown_llm_type " ,
215+ "send_default_pii, include_prompts" ,
209216 [
210- (True , True , False ),
211- (True , False , False ),
212- (False , True , False ),
213- (False , False , True ),
217+ (True , True ),
218+ (True , False ),
219+ (False , True ),
220+ (False , False ),
214221 ],
215222)
216223@pytest .mark .parametrize (
@@ -230,15 +237,11 @@ def test_langchain_openai_tools_agent(
230237 capture_events ,
231238 send_default_pii ,
232239 include_prompts ,
233- use_unknown_llm_type ,
234240 system_instructions_content ,
235241 request ,
236242 get_model_response ,
237243 server_side_event_chunks ,
238244):
239- global llm_type
240- llm_type = "acme-llm" if use_unknown_llm_type else "openai-chat"
241-
242245 sentry_init (
243246 integrations = [
244247 LangchainIntegration (
0 commit comments