@@ -181,7 +181,7 @@ def add_agent_tools(self, agent_name: str, tool: ToolConfig):
181
181
"""
182
182
Add new tools to be used by an agent.
183
183
184
- Tool definitions are inside of the methods marked with an `@agent` decorator.
184
+ Tool definitions are inside the methods marked with an `@agent` decorator.
185
185
The method returns a new class instance with the tools as a list of callables
186
186
under the kwarg `tools`.
187
187
"""
@@ -330,6 +330,24 @@ def get_tool_callables(tool_name: str) -> list[Callable]:
330
330
except ImportError :
331
331
raise ValidationError ("Could not import `crewai`. Is this an AgentStack CrewAI project?" )
332
332
333
+ # TODO: remove after agentops fixes their issue
334
+ # wrap method with agentops tool event
335
+ def wrap_method (method : Callable ) -> Callable :
336
+ def wrapped_method (* args , ** kwargs ):
337
+ import agentops
338
+ tool_event = agentops .ToolEvent (method .__name__ )
339
+ result = method (* args , ** kwargs )
340
+ agentops .record (tool_event )
341
+ return result
342
+
343
+ # Preserve all original attributes
344
+ wrapped_method .__name__ = method .__name__
345
+ wrapped_method .__doc__ = method .__doc__
346
+ wrapped_method .__module__ = method .__module__
347
+ wrapped_method .__qualname__ = method .__qualname__
348
+ wrapped_method .__annotations__ = getattr (method , '__annotations__' , {})
349
+ return wrapped_method
350
+
333
351
tool_funcs = []
334
352
tool_config = ToolConfig .from_tool_name (tool_name )
335
353
for tool_func_name in tool_config .tools :
@@ -338,6 +356,10 @@ def get_tool_callables(tool_name: str) -> list[Callable]:
338
356
assert callable (tool_func ), f"Tool function { tool_func_name } is not callable."
339
357
assert tool_func .__doc__ , f"Tool function { tool_func_name } is missing a docstring."
340
358
341
- # apply the CrewAI tool decorator to the tool function
342
- tool_funcs .append (_crewai_tool_decorator (tool_func ))
359
+ # First wrap with agentops
360
+ agentops_wrapped = wrap_method (tool_func )
361
+ # Then apply CrewAI decorator last so it properly inherits from BaseTool
362
+ crewai_wrapped = _crewai_tool_decorator (agentops_wrapped )
363
+ tool_funcs .append (crewai_wrapped )
364
+
343
365
return tool_funcs
0 commit comments