Skip to content
NEWMeet Alaaddin, your AI genie with a voice. trig8n launches 1 January 2027. See what is new

Library / Chatbots & Messaging Bots

Chatbots & Messaging Bots

Manage AI agent chat sessions with timeouts, handoff, and webhooks

When an API call/webhook arrives, it answers chat messages with a bot using Data Table.

What it does

## AI Agent Session Manager with Timeout and Human Handoff ### How it works This workflow manages AI agent sessions from two webhook entry points: one for incoming user messages and one for control commands such as human handoff actions. It normalizes each request, loads shared configuration, routes the request to the correct branch, and uses data table records to evaluate, create, update, restore, or expire sessions. The control branch retrieves a target session, applies the requested state change, updates storage, and produces a control result. ### Setup steps - Configure the two webhook URLs for incoming messages and control requests in the systems that will call this workflow. - Set up the n8n Data Table used for session storage with fields required by the workflow, such as session ID, user/conversation identifiers, state, last activity time, timeout/expiry metadata, and handoff status. - Review the Load Configuration code node and set environment-specific values such as timeout duration, allowed commands, default session state, and table/field names. - Verify that the Normalize Input and Normalize Command nodes match the payload shapes sent by your messaging channel and control system. ### Customization Adjust the session timeout rules, command vocabulary, and session state transitions in the configuration and code nodes. You can also extend the control branch with additional human handoff commands or add downstream AI-response handling after Session Context.

The steps

  1. Handle Incoming Message
  2. Normalize Message Input
  3. Fetch Latest Session
  4. Evaluate Session State
  5. Route by Session Status
  6. Expire Old Session
  7. Create New Session Record
  8. Log Activity Update
  9. Restore to Active Session
  10. Build Session Context
  11. Handle Control Request
  12. Normalize Command Input
  13. Fetch Session for Control
  14. Execute Session Command

18 steps in total.

Similar automations