1- from typing import Callable , AsyncGenerator
1+ from typing import Callable , AsyncGenerator , override
22from contextlib import asynccontextmanager
33
44from fastapi import FastAPI
@@ -31,6 +31,7 @@ def __init__(
3131 self ._temporal_address = temporal_address
3232
3333 @classmethod
34+ @override
3435 def create (cls , temporal_address : str ) -> "TemporalACP" :
3536 logger .info ("Initializing TemporalACP instance" )
3637
@@ -40,7 +41,7 @@ def create(cls, temporal_address: str) -> "TemporalACP":
4041 logger .info ("TemporalACP instance initialized now" )
4142 return temporal_acp
4243
43- # This is to override the lifespan function of the base
44+ @ override
4445 def get_lifespan_function (self ) -> Callable [[FastAPI ], AsyncGenerator [None , None ]]:
4546 @asynccontextmanager
4647 async def lifespan (app : FastAPI ):
@@ -59,29 +60,32 @@ async def lifespan(app: FastAPI):
5960 )
6061
6162 # Call parent lifespan for agent registration
62- async with super ().get_lifespan_function ()(app ):
63+ async with super ().get_lifespan_function ()(app ): # type: ignore[misc]
6364 yield
6465
6566 return lifespan
6667
68+ @override
6769 def _setup_handlers (self ):
6870 """Set up the handlers for temporal workflow operations"""
6971
7072 @self .on_task_create
7173 async def handle_task_create (params : CreateTaskParams ) -> None :
7274 """Default create task handler - logs the task"""
7375 logger .info (f"TemporalACP received task create rpc call for task { params .task .id } " )
74- await self ._temporal_task_service .submit_task (agent = params .agent , task = params .task , params = params .params )
76+ if self ._temporal_task_service is not None :
77+ await self ._temporal_task_service .submit_task (agent = params .agent , task = params .task , params = params .params )
7578
7679 @self .on_task_event_send
7780 async def handle_event_send (params : SendEventParams ) -> None :
7881 """Forward messages to running workflows via TaskService"""
7982 try :
80- await self ._temporal_task_service .send_event (
81- agent = params .agent ,
82- task = params .task ,
83- event = params .event ,
84- )
83+ if self ._temporal_task_service is not None :
84+ await self ._temporal_task_service .send_event (
85+ agent = params .agent ,
86+ task = params .task ,
87+ event = params .event ,
88+ )
8589
8690 except Exception as e :
8791 logger .error (f"Failed to send message: { e } " )
0 commit comments