More clear AgentMessageResult handling to fix stuck AgentParticipants (#1011)#1057
More clear AgentMessageResult handling to fix stuck AgentParticipants (#1011)#1057rasmi wants to merge 1 commit intoPAIR-code:mainfrom
Conversation
| /** Result of an agent's attempt to send a chat message. */ | ||
| export enum AgentMessageResult { | ||
| SENT = 'sent', | ||
| DECLINED = 'declined', |
There was a problem hiding this comment.
I'm guessing DECLINED means that the mediator decided not to respond? It took me a while to figure that out, so let's make that more clear. The comment as-is implies that the agent attempted to send a message, but for DECLINED it didn't.
|
|
||
| const allMediatorsDone = | ||
| mediators.length === 0 || | ||
| results.every((r) => r === AgentMessageResult.DECLINED); |
There was a problem hiding this comment.
So we're determining whether a mediator is done based entirely on whether it declined to respond on its last message, right? Does that mean we're not checking a mediator's readyToEndChat anywhere? Should we still be asking them for that field after this change?
| ).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('does NOT advance when all mediators return error', async () => { |
There was a problem hiding this comment.
Is this the correct behavior? If an agent participant is chatting with a mediator and the mediator gets an error responding, won't we still get stuck? Or if that actually does trigger the agent participant to respond, then can we verify that in this test?
Fixes #1011
Agent participants get stuck indefinitely in private chat stages when all mediators stop responding. The trigger (
onPrivateChatMessageCreated) is event-driven -- when no mediator writes a new message, no trigger fires, and the agent has no opportunity to advance.A secondary issue: in private chats,
shouldRespond: falseunconditionally forcedreadyToEndChat: trueon agent participants, conflating a per-turn skip with a conversation-ending signal.Changes
functions/src/chat/chat.agent.tsAgentMessageResultenum (SENT,DECLINED,ERROR) replacing boolean returns fromcreateAgentChatMessageFromPromptshouldRespondfromreadyToEndChat— respect the model's actualreadyToEndChatvalue instead of forcing itif (!shouldRespond)block from Enable chatting with models that produce images #846functions/src/triggers/chat.triggers.tscurrentStageId(prevent double-advancement),participant.agentConfig(no effect on human participants)What this does NOT change