@@ -421,6 +421,54 @@ public function scheduleMessageGeneration(?string $userId, int $sessionId, int $
421421 return $ taskId ;
422422 }
423423
424+ /**
425+ * @throws InternalException
426+ * @throws BadRequestException
427+ * @throws NotFoundException
428+ * @throws UnauthorizedException
429+ */
430+ public function scheduleAssignmentMessageGeneration (?string $ userId , int $ sessionId ): int {
431+ if ($ userId === null ) {
432+ throw new UnauthorizedException ($ this ->l10n ->t ('Unauthorized ' ));
433+ }
434+ try {
435+ $ sessionExists = $ this ->sessionMapper ->exists ($ userId , $ sessionId );
436+ } catch (Exception $ e ) {
437+ throw new InternalException (previous: $ e );
438+ }
439+ if (!$ sessionExists ) {
440+ throw new NotFoundException ($ this ->l10n ->t ('Session not found ' ));
441+ }
442+
443+ if (!$ this ->isContextAgentAvailable ()) {
444+ throw new BadRequestException ('context_agent_not_available ' );
445+ }
446+ try {
447+ $ lastUserMessage = $ this ->messageMapper ->getLastHumanMessage ($ sessionId );
448+ } catch (DoesNotExistException $ e ) {
449+ throw new NotFoundException ($ this ->l10n ->t ('No user message found in this session ' ), previous: $ e );
450+ } catch (MultipleObjectsReturnedException |Exception $ e ) {
451+ throw new InternalException (previous: $ e );
452+ }
453+
454+
455+ try {
456+ $ session = $ this ->sessionMapper ->getUserSession ($ userId , $ sessionId );
457+ } catch (DoesNotExistException $ e ) {
458+ throw new NotFoundException ($ this ->l10n ->t ('Session not found ' ), previous: $ e );
459+ } catch (MultipleObjectsReturnedException |Exception $ e ) {
460+ throw new InternalException (previous: $ e );
461+ }
462+ // We reset the context for each interaction, because this is an assignment,
463+ // the assistant does not remember things between assignment runs
464+ $ lastConversationToken = '{} ' ;
465+
466+ // classic agency
467+ $ prompt = $ lastUserMessage ->getContent ();
468+ $ taskId = $ this ->scheduleAgencyTask ($ userId , $ prompt , 0 , $ lastConversationToken , $ sessionId );
469+ return $ taskId ;
470+ }
471+
424472 /**
425473 * @throws BadRequestException
426474 * @throws InternalException
@@ -494,7 +542,7 @@ private function getAudioHistory(array $history): array {
494542 'role ' => $ message ->getRole (),
495543 ];
496544 $ attachments = $ message ->jsonSerialize ()['attachments ' ];
497- if ($ message ->getRole () === ' assistant '
545+ if ($ message ->getRole () === Message:: ROLE_ASSISTANT
498546 && count ($ attachments ) > 0
499547 && $ attachments [0 ]['type ' ] === 'Audio '
500548 && isset ($ attachments [0 ]['remote_audio_id ' ])
0 commit comments