@@ -229,8 +229,25 @@ async def process_request(
229229 type: string
230230 description: Error message
231231 """
232-
233- if not await rai_success (input_task .description ):
232+ try :
233+ memory_store = await DatabaseFactory .get_database (user_id = user_id )
234+ user_current_team = await memory_store .get_current_team (user_id = user_id )
235+ team_id = None
236+ if user_current_team :
237+ team_id = user_current_team .team_id
238+ team = await memory_store .get_team_by_id (team_id = team_id )
239+ if not team :
240+ raise HTTPException (
241+ status_code = 404 ,
242+ detail = f"Team configuration '{ team_id } ' not found or access denied" ,
243+ )
244+ except Exception as e :
245+ raise HTTPException (
246+ status_code = 400 ,
247+ detail = f"Error retrieving team configuration: { e } " ,
248+ ) from e
249+
250+ if not await rai_success (input_task .description , team , memory_store ):
234251 track_event_if_configured (
235252 "RAI failed" ,
236253 {
@@ -264,17 +281,6 @@ async def process_request(
264281 try :
265282 plan_id = str (uuid .uuid4 ())
266283 # Initialize memory store and service
267- memory_store = await DatabaseFactory .get_database (user_id = user_id )
268- user_current_team = await memory_store .get_current_team (user_id = user_id )
269- team_id = None
270- if user_current_team :
271- team_id = user_current_team .team_id
272- team = await memory_store .get_team_by_id (team_id = team_id )
273- if not team :
274- raise HTTPException (
275- status_code = 404 ,
276- detail = f"Team configuration '{ team_id } ' not found or access denied" ,
277- )
278284 plan = Plan (
279285 id = plan_id ,
280286 plan_id = plan_id ,
@@ -507,11 +513,28 @@ async def user_clarification(
507513 raise HTTPException (
508514 status_code = 401 , detail = "Missing or invalid user information"
509515 )
516+ try :
517+ memory_store = await DatabaseFactory .get_database (user_id = user_id )
518+ user_current_team = await memory_store .get_current_team (user_id = user_id )
519+ team_id = None
520+ if user_current_team :
521+ team_id = user_current_team .team_id
522+ team = await memory_store .get_team_by_id (team_id = team_id )
523+ if not team :
524+ raise HTTPException (
525+ status_code = 404 ,
526+ detail = f"Team configuration '{ team_id } ' not found or access denied" ,
527+ )
528+ except Exception as e :
529+ raise HTTPException (
530+ status_code = 400 ,
531+ detail = f"Error retrieving team configuration: { e } " ,
532+ ) from e
510533 # Set the approval in the orchestration config
511534 if user_id and human_feedback .request_id :
512535 # validate rai
513536 if human_feedback .answer is not None or human_feedback .answer != "" :
514- if not await rai_success (human_feedback .answer ):
537+ if not await rai_success (human_feedback .answer , team , memory_store ):
515538 track_event_if_configured (
516539 "RAI failed" ,
517540 {
0 commit comments