@@ -60,6 +60,35 @@ async def ping():
6060
6161 @app .post ("/invocations" )
6262 async def invocations (request : dict , http_request : Request ):
63+
64+ @app .post ("/invocations/stream" )
65+ async def invocations_stream (request : dict , http_request : Request ):
66+ """AgentCore-compatible streaming endpoint"""
67+ from fastapi .responses import StreamingResponse
68+ from cx_agent_backend .domain .services .conversation_service import ConversationService
69+
70+ conversation_service = container .conversation_service ()
71+ input_data = request .get ("input" , {})
72+ prompt = input_data .get ("prompt" )
73+ conversation_id_str = input_data .get ("conversation_id" )
74+ user_id = input_data .get ("user_id" )
75+
76+ from uuid import UUID
77+ conversation_id = UUID (conversation_id_str ) if conversation_id_str else None
78+
79+ if not prompt :
80+ raise HTTPException (status_code = 400 , detail = "Prompt required for streaming" )
81+
82+ async def generate ():
83+ async for chunk in conversation_service .stream_message (
84+ conversation_id = conversation_id ,
85+ user_id = user_id ,
86+ content = prompt ,
87+ model = settings .default_model ,
88+ ):
89+ yield f"data: { chunk } \n \n "
90+
91+ return StreamingResponse (generate (), media_type = "text/plain" )
6392 """AgentCore-compatible endpoint to invoke the agent (send message & get response)"""
6493 from cx_agent_backend .domain .services .conversation_service import ConversationService
6594
0 commit comments