From b8239fc345809ee5a33aa0a5b7f6956e9b6229c5 Mon Sep 17 00:00:00 2001 From: Jack Gerrits Date: Mon, 24 Jun 2024 13:19:40 -0400 Subject: [PATCH] remove generic from termination guide (#111) --- .../docs/src/guides/termination-with-intervention.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/python/docs/src/guides/termination-with-intervention.md b/python/docs/src/guides/termination-with-intervention.md index 26890d5170..9c95e69c4a 100644 --- a/python/docs/src/guides/termination-with-intervention.md +++ b/python/docs/src/guides/termination-with-intervention.md @@ -9,7 +9,7 @@ There are many different ways to handle termination in `agnext`. Ultimately, the ```python import asyncio from dataclasses import dataclass -from typing import Any, Generic, Type, TypeVar +from typing import Any from agnext.application import SingleThreadedAgentRuntime from agnext.components import TypeRoutedAgent, message_handler @@ -43,12 +43,9 @@ class AnAgent(TypeRoutedAgent): Next, we create an InterventionHandler that will detect the termination message and act on it. This one hooks into publishes and when it encounters `Termination` it alters its internal state to indicate that termination has been requested. ```python -T = TypeVar("T") +class TerminationHandler(DefaultInterventionHandler): -class TerminationHandler(Generic[T], DefaultInterventionHandler): - - def __init__(self, termination_type: Type[T]): - self.termination_type = termination_type + def __init__(self): self.termination_value: T | None = None async def on_publish(self, message: Any, *, sender: AgentId | None) -> Any: @@ -69,7 +66,7 @@ Finally, we add this handler to the runtime and use it to detect termination and ```python async def main() -> None: - termination_handler = TerminationHandler(Termination) + termination_handler = TerminationHandler() runtime = SingleThreadedAgentRuntime( before_send=termination_handler )