88from agentstack .agents import AgentConfig
99from agentstack .generation import asttools
1010from agentstack import graph
11+
1112if TYPE_CHECKING :
1213 from agentstack .generation import InsertionPoint
1314
@@ -19,6 +20,7 @@ class CrewFile(asttools.File):
1920 Parses and manipulates the CrewAI entrypoint file.
2021 All AST interactions should happen within the methods of this class.
2122 """
23+
2224 def write (self ):
2325 """
2426 Early versions of the crew entrypoint file used tabs instead of spaces.
@@ -65,7 +67,7 @@ def {task.name}(self) -> Task:
6567 return Task(
6668 config=self.tasks_config['{ task .name } '],
6769 )"""
68-
70+
6971 if not self .source [:pos ].endswith ('\n ' ):
7072 code = '\n \n ' + code
7173 if not self .source [pos :].startswith ('\n ' ):
@@ -95,7 +97,7 @@ def {agent.name}(self) -> Agent:
9597 tools=[], # add tools here or use `agentstack tools add <tool_name>
9698 verbose=True,
9799 )"""
98-
100+
99101 if not self .source [:pos ].endswith ('\n ' ):
100102 code = '\n \n ' + code
101103 if not self .source [pos :].startswith ('\n ' ):
@@ -280,7 +282,7 @@ def add_agent(agent: AgentConfig, position: Optional['InsertionPoint'] = None) -
280282 """
281283 if position is not None :
282284 raise NotImplementedError ("Agent insertion points are not supported in CrewAI." )
283-
285+
284286 with CrewFile (conf .PATH / ENTRYPOINT ) as crew_file :
285287 crew_file .add_agent_method (agent )
286288
@@ -302,52 +304,19 @@ def remove_tool(tool: ToolConfig, agent_name: str):
302304 crew_file .remove_agent_tools (agent_name , tool )
303305
304306
305- def get_tool_callables ( tool_name : str ) -> list [ Callable ] :
307+ def wrap_tool ( tool_func : Callable ) -> Callable :
306308 """
307- Get a tool implementations for use directly by a CrewAI agent .
309+ Wrap a tool function with framework-specific functionality .
308310 """
309311 try :
310312 from crewai .tools import tool as _crewai_tool_decorator
311313 except ImportError :
312314 raise ValidationError ("Could not import `crewai`. Is this an AgentStack CrewAI project?" )
313315
314- # TODO: remove after agentops fixes their issue
315- # wrap method with agentops tool event
316- def wrap_method (method : Callable ) -> Callable :
317- def wrapped_method (* args , ** kwargs ):
318- import agentops
319- tool_event = agentops .ToolEvent (method .__name__ )
320- result = method (* args , ** kwargs )
321- agentops .record (tool_event )
322- return result
323-
324- # Preserve all original attributes
325- wrapped_method .__name__ = method .__name__
326- wrapped_method .__doc__ = method .__doc__
327- wrapped_method .__module__ = method .__module__
328- wrapped_method .__qualname__ = method .__qualname__
329- wrapped_method .__annotations__ = getattr (method , '__annotations__' , {})
330- return wrapped_method
331-
332- tool_funcs = []
333- tool_config = ToolConfig .from_tool_name (tool_name )
334- for tool_func_name in tool_config .tools :
335- tool_func = getattr (tool_config .module , tool_func_name )
336-
337- assert callable (tool_func ), f"Tool function { tool_func_name } is not callable."
338- assert tool_func .__doc__ , f"Tool function { tool_func_name } is missing a docstring."
339-
340- # First wrap with agentops
341- agentops_wrapped = wrap_method (tool_func )
342- # Then apply CrewAI decorator last so it properly inherits from BaseTool
343- crewai_wrapped = _crewai_tool_decorator (agentops_wrapped )
344- tool_funcs .append (crewai_wrapped )
345-
346- return tool_funcs
316+ return _crewai_tool_decorator (tool_func )
347317
348318
349319def get_graph () -> list [graph .Edge ]:
350320 """Get the graph of the user's project."""
351321 log .debug ("CrewAI does not support graph generation." )
352322 return []
353-
0 commit comments