66from langchain .tools import BaseTool
77from langchain_core .messages import ToolCall
88from langchain_core .tools import StructuredTool
9+ from tenacity import (
10+ retry ,
11+ retry_if_exception ,
12+ stop_after_attempt ,
13+ wait_exponential_jitter ,
14+ )
915from uipath .agent .models .agent import AgentIntegrationToolResourceConfig
1016from uipath .eval .mocks import mockable
1117from uipath .platform import UiPath
1218from uipath .platform .connections import ActivityMetadata , ActivityParameterLocationInfo
19+ from uipath .platform .errors import EnrichedException
1320from uipath .runtime .errors import UiPathErrorCategory
14-
1521from uipath_langchain .agent .exceptions import AgentStartupError , AgentStartupErrorCode
1622from uipath_langchain .agent .react .jsonschema_pydantic_converter import create_model
1723from uipath_langchain .agent .react .types import AgentGraphState
@@ -165,6 +171,18 @@ def create_integration_tool(
165171
166172 sdk = UiPath ()
167173
174+ def _is_429 (exc : BaseException ) -> bool :
175+ return (
176+ isinstance (exc , EnrichedException )
177+ and getattr (exc , "status_code" , None ) == 429
178+ )
179+
180+ @retry (
181+ retry = retry_if_exception (_is_429 ),
182+ wait = wait_exponential_jitter (initial = 10 , max = 120 , jitter = 5 ),
183+ stop = stop_after_attempt (5 ),
184+ reraise = True ,
185+ )
168186 @mockable (
169187 name = resource .name ,
170188 description = resource .description ,
@@ -173,15 +191,11 @@ def create_integration_tool(
173191 example_calls = resource .properties .example_calls ,
174192 )
175193 async def integration_tool_fn (** kwargs : Any ):
176- try :
177- result = await sdk .connections .invoke_activity_async (
178- activity_metadata = activity_metadata ,
179- connection_id = connection_id ,
180- activity_input = sanitize_dict_for_serialization (kwargs ),
181- )
182- except Exception :
183- raise
184-
194+ result = await sdk .connections .invoke_activity_async (
195+ activity_metadata = activity_metadata ,
196+ connection_id = connection_id ,
197+ activity_input = sanitize_dict_for_serialization (kwargs ),
198+ )
185199 return result
186200
187201 async def integration_tool_wrapper (
0 commit comments