Skip to content

Commit 89b945a

Browse files
committed
capture tool use for crew agents
1 parent a4cf7e2 commit 89b945a

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

agentstack/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
This it the beginning of the agentstack public API.
33
44
Methods that have been imported into this file are expected to be used by the
5-
end user inside of their project.
5+
end user inside their project.
66
"""
77

88
from typing import Callable
@@ -40,5 +40,4 @@ class ToolLoader:
4040
def __getitem__(self, tool_name: str) -> list[Callable]:
4141
return frameworks.get_tool_callables(tool_name)
4242

43-
4443
tools = ToolLoader()

agentstack/cli/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typing import Optional, List
22
import sys
33
import traceback
44
from pathlib import Path
@@ -93,7 +93,7 @@ def _import_project_module(path: Path):
9393
return project_module
9494

9595

96-
def run_project(command: str = 'run', cli_args: Optional[str] = None):
96+
def run_project(command: str = 'run', cli_args: Optional[List[str]] = None):
9797
"""Validate that the project is ready to run and then run it."""
9898
verify_agentstack_project()
9999

agentstack/frameworks/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def validate_project():
116116
def add_tool(tool: ToolConfig, agent_name: str):
117117
"""
118118
Add a tool to the user's project.
119-
The tool will have aready been installed in the user's application and have
119+
The tool will have already been installed in the user's application and have
120120
all dependencies installed. We're just handling code generation here.
121121
"""
122122
return get_framework_module(get_framework()).add_tool(tool, agent_name)

agentstack/frameworks/crewai.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def add_agent_tools(self, agent_name: str, tool: ToolConfig):
181181
"""
182182
Add new tools to be used by an agent.
183183
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.
185185
The method returns a new class instance with the tools as a list of callables
186186
under the kwarg `tools`.
187187
"""
@@ -330,6 +330,24 @@ def get_tool_callables(tool_name: str) -> list[Callable]:
330330
except ImportError:
331331
raise ValidationError("Could not import `crewai`. Is this an AgentStack CrewAI project?")
332332

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+
333351
tool_funcs = []
334352
tool_config = ToolConfig.from_tool_name(tool_name)
335353
for tool_func_name in tool_config.tools:
@@ -338,6 +356,10 @@ def get_tool_callables(tool_name: str) -> list[Callable]:
338356
assert callable(tool_func), f"Tool function {tool_func_name} is not callable."
339357
assert tool_func.__doc__, f"Tool function {tool_func_name} is missing a docstring."
340358

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+
343365
return tool_funcs

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "agentstack"
7-
version = "0.2.5"
7+
version = "0.2.5.1"
88
description = "The fastest way to build robust AI agents"
99
authors = [
1010
{ name="Braelyn Boynton", email="[email protected]" },

0 commit comments

Comments
 (0)