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
- Handle Incoming Message
- Normalize Message Input
- Fetch Latest Session
- Evaluate Session State
- Route by Session Status
- Expire Old Session
- Create New Session Record
- Log Activity Update
- Restore to Active Session
- Build Session Context
- Handle Control Request
- Normalize Command Input
- Fetch Session for Control
- Execute Session Command
18 steps in total.
Similar automations
Chatbots & Messaging BotsTelegram Chatbot with Multiple Sessions Using OpenAI31 stepsEmail AutomationManage client onboarding and project handoff with Google Sheets and Gmail23 stepsMonitoring, Ops & IncidentsTriage PostgreSQL blocking sessions with Ollama and Telegram approval15 stepsFinance, Invoices & AccountingFilter Stripe Checkout Sessions by Custom Field15 steps