fix: ensure cache hit formatting; additional event types

This commit is contained in:
Greyson LaLonde
2026-01-20 02:14:08 -05:00
parent d78ee915dc
commit c8f9547816
2 changed files with 37 additions and 10 deletions

View File

@@ -68,7 +68,7 @@ def push_event_scope(event_id: str, event_type: str = "") -> None:
config = _event_context_config.get() or _default_config
stack = _event_id_stack.get()
if config.max_stack_depth > 0 and len(stack) >= config.max_stack_depth:
if 0 < config.max_stack_depth <= len(stack):
raise StackDepthExceededError(
f"Event stack depth limit ({config.max_stack_depth}) exceeded. "
f"This usually indicates missing ending events."
@@ -137,21 +137,24 @@ SCOPE_STARTING_EVENTS: frozenset[str] = frozenset(
"flow_started",
"method_execution_started",
"crew_kickoff_started",
"crew_train_started",
"crew_test_started",
"agent_execution_started",
"agent_evaluation_started",
"lite_agent_execution_started",
"task_started",
"llm_call_started",
"llm_guardrail_started",
"tool_usage_started",
"mcp_connection_started",
"mcp_tool_execution_started",
"memory_retrieval_started",
"memory_save_started",
"memory_query_started",
"knowledge_retrieval_started",
"knowledge_query_started",
"knowledge_search_query_started",
"a2a_delegation_started",
"a2a_conversation_started",
"a2a_polling_started",
"a2a_streaming_started",
"a2a_server_task_started",
"a2a_parallel_delegation_started",
"agent_reasoning_started",
@@ -166,8 +169,14 @@ SCOPE_ENDING_EVENTS: frozenset[str] = frozenset(
"method_execution_failed",
"crew_kickoff_completed",
"crew_kickoff_failed",
"crew_train_completed",
"crew_train_failed",
"crew_test_completed",
"crew_test_failed",
"agent_execution_completed",
"agent_execution_error",
"agent_evaluation_completed",
"agent_evaluation_failed",
"lite_agent_execution_completed",
"lite_agent_execution_error",
"task_completed",
@@ -175,20 +184,24 @@ SCOPE_ENDING_EVENTS: frozenset[str] = frozenset(
"llm_call_completed",
"llm_call_failed",
"llm_guardrail_completed",
"llm_guardrail_failed",
"tool_usage_finished",
"tool_usage_error",
"mcp_connection_completed",
"mcp_connection_failed",
"mcp_tool_execution_completed",
"mcp_tool_execution_failed",
"memory_retrieval_completed",
"memory_save_completed",
"memory_save_failed",
"memory_query_completed",
"memory_query_failed",
"knowledge_retrieval_completed",
"knowledge_query_completed",
"knowledge_query_failed",
"knowledge_search_query_completed",
"knowledge_search_query_failed",
"a2a_delegation_completed",
"a2a_conversation_completed",
"a2a_polling_completed",
"a2a_streaming_completed",
"a2a_server_task_completed",
"a2a_server_task_canceled",
"a2a_server_task_failed",
@@ -205,8 +218,14 @@ VALID_EVENT_PAIRS: dict[str, str] = {
"method_execution_failed": "method_execution_started",
"crew_kickoff_completed": "crew_kickoff_started",
"crew_kickoff_failed": "crew_kickoff_started",
"crew_train_completed": "crew_train_started",
"crew_train_failed": "crew_train_started",
"crew_test_completed": "crew_test_started",
"crew_test_failed": "crew_test_started",
"agent_execution_completed": "agent_execution_started",
"agent_execution_error": "agent_execution_started",
"agent_evaluation_completed": "agent_evaluation_started",
"agent_evaluation_failed": "agent_evaluation_started",
"lite_agent_execution_completed": "lite_agent_execution_started",
"lite_agent_execution_error": "lite_agent_execution_started",
"task_completed": "task_started",
@@ -214,20 +233,24 @@ VALID_EVENT_PAIRS: dict[str, str] = {
"llm_call_completed": "llm_call_started",
"llm_call_failed": "llm_call_started",
"llm_guardrail_completed": "llm_guardrail_started",
"llm_guardrail_failed": "llm_guardrail_started",
"tool_usage_finished": "tool_usage_started",
"tool_usage_error": "tool_usage_started",
"mcp_connection_completed": "mcp_connection_started",
"mcp_connection_failed": "mcp_connection_started",
"mcp_tool_execution_completed": "mcp_tool_execution_started",
"mcp_tool_execution_failed": "mcp_tool_execution_started",
"memory_retrieval_completed": "memory_retrieval_started",
"memory_save_completed": "memory_save_started",
"memory_save_failed": "memory_save_started",
"memory_query_completed": "memory_query_started",
"memory_query_failed": "memory_query_started",
"knowledge_retrieval_completed": "knowledge_retrieval_started",
"knowledge_query_completed": "knowledge_query_started",
"knowledge_query_failed": "knowledge_query_started",
"knowledge_search_query_completed": "knowledge_search_query_started",
"knowledge_search_query_failed": "knowledge_search_query_started",
"a2a_delegation_completed": "a2a_delegation_started",
"a2a_conversation_completed": "a2a_conversation_started",
"a2a_polling_completed": "a2a_polling_started",
"a2a_streaming_completed": "a2a_streaming_started",
"a2a_server_task_completed": "a2a_server_task_started",
"a2a_server_task_canceled": "a2a_server_task_started",
"a2a_server_task_failed": "a2a_server_task_started",

View File

@@ -401,6 +401,8 @@ class ToolUsage:
if self.task:
self.task.increment_tools_errors()
should_retry = True
else:
result = self._format_result(result=result)
finally:
if started_event_emitted:
@@ -602,6 +604,8 @@ class ToolUsage:
if self.task:
self.task.increment_tools_errors()
should_retry = True
else:
result = self._format_result(result=result)
finally:
if started_event_emitted: