Set Last Agent ID

Node

Set Last Agent ID

Description

The Set Last Agent ID node image-20250813-150613.png extracts the last agent’s ID from the most recent conversation when routing policy allows, and writes it to the message.

Execution & Payload Details:

  • Reads from:

    • msg.payload.recent_conversation.agents: array of agent objects; last element’s id is used.

    • msg.payload.session.channel.channelConfig.routingPolicy.routeToLastAgent: boolean flag to enable this behavior.

  • Writes to:

    • msg.payload.last_agent_id: string/number or null.

  • Logic:

    • If both recent_conversation and session exist, and routeToLastAgent === true:

    • Sets last_agent_id to the id of the last agent in recent_conversation.agents.

    • Otherwise sets last_agent_id = null.

  • Behavior:

    • On success, forwards the message with payload.last_agent_id set.

    • On error, logs and raises a node error; message is not forwarded.

  • Example:

    • Input: payload.recent_conversation.agents = [{id:"A1"},{id:"A2"}], payload.session.channel.channelConfig.routingPolicy.routeToLastAgent = true

    • Output: payload.last_agent_id = "A2"