refactor: replace AgentExecutionErrorEvent with TaskFailedEvent for LLM call handling

- Updated Agent class to emit TaskFailedEvent instead of AgentExecutionErrorEvent when LLM calls are blocked.
- Removed unnecessary LLMCallBlockedError handling from CrewAgentExecutor.
- Enhanced test cases to ensure proper exception handling for blocked LLM calls.
- Improved code clarity and consistency in event handling across agent execution.
This commit is contained in:
lorenzejay
2025-12-21 22:05:11 -08:00
parent 05c42791c9
commit f39379ddd5
3 changed files with 7 additions and 22 deletions

View File

@@ -5,6 +5,7 @@ from __future__ import annotations
from unittest.mock import Mock
from crewai.hooks import (
LLMCallBlockedError,
clear_all_llm_call_hooks,
unregister_after_llm_call_hook,
unregister_before_llm_call_hook,
@@ -118,16 +119,9 @@ class TestLLMCallHookContext:
agent=agent,
)
crew = Crew(agents=[agent], tasks=[task], verbose=True)
result = crew.kickoff()
print('result', result)
assert 1 + 1 == 3
assert hook_called["before"] is True, "Before hook should have been called"
assert "blocked" in result.raw.lower(), "Result should indicate LLM call was blocked" # type: ignore
with pytest.raises(LLMCallBlockedError):
crew = Crew(agents=[agent], tasks=[task], verbose=True)
crew.kickoff()
finally:
unregister_before_llm_call_hook(blocking_hook)