Add tool execution result to ToolUsageFinishedEvent

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-03-22 00:55:25 +00:00
parent bb3829a9ed
commit 23aeaf67ba
3 changed files with 5 additions and 1 deletions

View File

@@ -244,6 +244,7 @@ class ToolUsage:
tool_calling=calling,
from_cache=from_cache,
started_at=started_at,
result=result, # Pass the result
)
if (
@@ -492,7 +493,7 @@ class ToolUsage:
crewai_event_bus.emit(self, ToolUsageErrorEvent(**{**event_data, "error": e}))
def on_tool_use_finished(
self, tool: Any, tool_calling: ToolCalling, from_cache: bool, started_at: float
self, tool: Any, tool_calling: ToolCalling, from_cache: bool, started_at: float, result: Any = None
) -> None:
finished_at = time.time()
event_data = self._prepare_event_data(tool, tool_calling)
@@ -501,6 +502,7 @@ class ToolUsage:
"started_at": datetime.datetime.fromtimestamp(started_at),
"finished_at": datetime.datetime.fromtimestamp(finished_at),
"from_cache": from_cache,
"result": result, # Add the result to the event data
}
)
crewai_event_bus.emit(self, ToolUsageFinishedEvent(**event_data))

View File

@@ -30,6 +30,7 @@ class ToolUsageFinishedEvent(ToolUsageEvent):
started_at: datetime
finished_at: datetime
from_cache: bool = False
result: Any = None # Add this field
type: str = "tool_usage_finished"

View File

@@ -358,6 +358,7 @@ def test_tools_emits_finished_events():
assert received_events[0].tool_args == {}
assert received_events[0].type == "tool_usage_finished"
assert isinstance(received_events[0].timestamp, datetime)
assert received_events[0].result == "hi" # The SayHiTool returns "hi"
@pytest.mark.vcr(filter_headers=["authorization"])