Преглед на файлове

fix: restore typed event consumers

Problem: typed stream kinds exposed Runtime and EventAgent consumers that still listened for the legacy event kind. Risk: legacy fixtures masked production-path regressions; focused tests now use typed constructors.
zhenyu.hu преди 2 седмици
родител
ревизия
47eb29f09d
променени са 4 файла, в които са добавени 17 реда и са изтрити 14 реда
  1. 4 1
      src/agent_lab/application/event_agent.py
  2. 2 2
      src/agent_lab/application/runtime.py
  3. 10 10
      tests/test_debug_runtime.py
  4. 1 1
      tests/test_event_agent.py

+ 4 - 1
src/agent_lab/application/event_agent.py

@@ -166,7 +166,10 @@ class EventAgent:
                 raw_chunks.append(item.raw_chunk)
                 continue
 
-            if item.kind == "event" and item.event is not None:
+            if (
+                item.kind in {"provider_tool_call", "event"}
+                and item.event is not None
+            ):
                 self._raw_chunks_by_event[event.id] = raw_chunks
                 return event.model_copy(
                     update={

+ 2 - 2
src/agent_lab/application/runtime.py

@@ -219,7 +219,7 @@ class DebugRuntime:
                     )
                     continue
 
-                if item.kind == "event" and item.event is not None:
+                if item.kind in {"text_event", "event"} and item.event is not None:
                     saw_event = True
                     event = self._event_name_only(item.event)
                     events.append(event)
@@ -491,7 +491,7 @@ class DebugRuntime:
                     )
                     continue
 
-                if item.kind == "event" and item.event is not None:
+                if item.kind in {"text_event", "event"} and item.event is not None:
                     saw_event = True
                     event = self._event_name_only(item.event)
                     events.append(event)

+ 10 - 10
tests/test_debug_runtime.py

@@ -55,7 +55,7 @@ def _event_tool_call_from_tools(
         "query": content,
         "title": content,
     }
-    return StreamItem.event(
+    return StreamItem.provider_tool_call(
         ToolCallEvent(
             id="event_agent_call_1",
             name=tool_name,
@@ -153,7 +153,7 @@ class FakeChatClient:
                     ]
                 }
             )
-            yield StreamItem.event(
+            yield StreamItem.text_event(
                 ToolCallEvent(
                     id="call_1",
                     name="handoff_note",
@@ -221,7 +221,7 @@ class StrictHistoryChatClient:
                     ]
                 }
             )
-            yield StreamItem.event(
+            yield StreamItem.text_event(
                 ToolCallEvent(
                     id="call_1",
                     name="handoff_note",
@@ -252,7 +252,7 @@ class MultiEventChatClient:
         self.calls += 1
         if self.calls == 1:
             yield StreamItem.message_delta("Checking events.")
-            yield StreamItem.event(
+            yield StreamItem.text_event(
                 ToolCallEvent(
                     id="call_1",
                     name="handoff_note",
@@ -260,7 +260,7 @@ class MultiEventChatClient:
                     raw_arguments='{"message":"ignored chat argument"}',
                 )
             )
-            yield StreamItem.event(
+            yield StreamItem.text_event(
                 ToolCallEvent(
                     id="call_2",
                     name="audit_note",
@@ -309,7 +309,7 @@ class EventLoopLimitChatClient:
         self.tools_by_call.append(list(tools))
         self.messages_by_call.append(list(messages))
         if self.calls == 1:
-            yield StreamItem.event(
+            yield StreamItem.text_event(
                 ToolCallEvent(
                     id="call_1",
                     name="handoff_note",
@@ -386,7 +386,7 @@ class EventRoundStatsChatClient:
                     ]
                 }
             )
-            yield StreamItem.event(
+            yield StreamItem.text_event(
                 ToolCallEvent(
                     id="call_1",
                     name="handoff_note",
@@ -433,7 +433,7 @@ class ContextBoundaryChatClient:
         self.calls += 1
         if self.calls == 1:
             yield StreamItem.message_delta("I will check.")
-            yield StreamItem.event(
+            yield StreamItem.text_event(
                 ToolCallEvent(
                     id="call_1",
                     name="handoff_note",
@@ -462,7 +462,7 @@ class TwoTurnSessionChatClient:
         self.calls += 1
         self.messages_by_call.append(list(messages))
         if self.calls in {1, 3}:
-            yield StreamItem.event(
+            yield StreamItem.text_event(
                 ToolCallEvent(
                     id=f"call_{self.calls}",
                     name="handoff_note",
@@ -493,7 +493,7 @@ class SlowAfterEventChatClient:
         self.calls += 1
         if self.calls == 1:
             yield StreamItem.message_delta("Need event.")
-            yield StreamItem.event(
+            yield StreamItem.text_event(
                 ToolCallEvent(
                     id="call_1",
                     name="handoff_note",

+ 1 - 1
tests/test_event_agent.py

@@ -46,7 +46,7 @@ class ToolCallingChatClient:
                 ]
             }
         )
-        yield StreamItem.event(
+        yield StreamItem.provider_tool_call(
             ToolCallEvent(
                 id="llm_call_1",
                 name=tool_name,