mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 08:38:30 +00:00
Add tool execution result to ToolUsageFinishedEvent
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -244,6 +244,7 @@ class ToolUsage:
|
|||||||
tool_calling=calling,
|
tool_calling=calling,
|
||||||
from_cache=from_cache,
|
from_cache=from_cache,
|
||||||
started_at=started_at,
|
started_at=started_at,
|
||||||
|
result=result, # Pass the result
|
||||||
)
|
)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -492,7 +493,7 @@ class ToolUsage:
|
|||||||
crewai_event_bus.emit(self, ToolUsageErrorEvent(**{**event_data, "error": e}))
|
crewai_event_bus.emit(self, ToolUsageErrorEvent(**{**event_data, "error": e}))
|
||||||
|
|
||||||
def on_tool_use_finished(
|
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:
|
) -> None:
|
||||||
finished_at = time.time()
|
finished_at = time.time()
|
||||||
event_data = self._prepare_event_data(tool, tool_calling)
|
event_data = self._prepare_event_data(tool, tool_calling)
|
||||||
@@ -501,6 +502,7 @@ class ToolUsage:
|
|||||||
"started_at": datetime.datetime.fromtimestamp(started_at),
|
"started_at": datetime.datetime.fromtimestamp(started_at),
|
||||||
"finished_at": datetime.datetime.fromtimestamp(finished_at),
|
"finished_at": datetime.datetime.fromtimestamp(finished_at),
|
||||||
"from_cache": from_cache,
|
"from_cache": from_cache,
|
||||||
|
"result": result, # Add the result to the event data
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
crewai_event_bus.emit(self, ToolUsageFinishedEvent(**event_data))
|
crewai_event_bus.emit(self, ToolUsageFinishedEvent(**event_data))
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class ToolUsageFinishedEvent(ToolUsageEvent):
|
|||||||
started_at: datetime
|
started_at: datetime
|
||||||
finished_at: datetime
|
finished_at: datetime
|
||||||
from_cache: bool = False
|
from_cache: bool = False
|
||||||
|
result: Any = None # Add this field
|
||||||
type: str = "tool_usage_finished"
|
type: str = "tool_usage_finished"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -358,6 +358,7 @@ def test_tools_emits_finished_events():
|
|||||||
assert received_events[0].tool_args == {}
|
assert received_events[0].tool_args == {}
|
||||||
assert received_events[0].type == "tool_usage_finished"
|
assert received_events[0].type == "tool_usage_finished"
|
||||||
assert isinstance(received_events[0].timestamp, datetime)
|
assert isinstance(received_events[0].timestamp, datetime)
|
||||||
|
assert received_events[0].result == "hi" # The SayHiTool returns "hi"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||||
|
|||||||
Reference in New Issue
Block a user