Inject Agent Message

Send a message to immediately trigger an Agent statement.

Voice Agent

Some common ways to use the injectAgentMessage are:

  • Informing the user that the agent is working on a lengthy function call (“Hold on while I look that up for you”)
  • Prompting the user to continue if the user hasn’t spoken for a while (“Are you still on the line?“)

What is the InjectAgentMessage

TheInjectAgentMessage message is a JSON command you can send to immediately trigger an agent statement. If the injection request arrives while the user is speaking, or while the server is in the middle of sending audio for an agent response, then the request will be ignored and the server will reply with anInjectionRefused. The client should only try to inject agent messages during silent portions of the conversation.

Sending InjectAgentMessage

To send the InjectAgentMessage message, you need to send the following JSON message to the server:

JSON
1{
2 "type": "InjectAgentMessage",
3 "message": "" // The statement the agent should say
4}

InjectAgentMessage Confirmation

The server will send an AgentAudioDone message immediately after it sends the last audio message in a piece of agent speech. See Agent Audio Done for more details.

JSON
1{
2 "type": "AgentAudioDone"
3}

InjectAgentMessage Refused

The server will send an InjectionRefused message when an InjectAgentMessage request is ignored because it arrived while the user was speaking or while the server was sending audio for an agent response.

JSON
1{
2 "type": "InjectionRefused"
3}

Conclusion

The InjectAgentMessage message provides a way to immediately trigger an agent response during a conversation. However, it must be carefully timed, as the request will be ignored if the user is speaking or if the agent is already responding. To ensure successful injection, the client should only attempt it during silent moments, avoiding interruptions and potential InjectionRefused errors.

Built with