{"product_id":"ai-agent-session-manager-with-webhooks-ttl-handoff-n8n","title":"AI Agent Session Manager with Webhooks, TTL \u0026 Handoff (n8n)","description":"\u003ch3\u003eManage AI agent sessions automatically with webhooks, TTL expiry, and human handoff in n8n\u003c\/h3\u003e\n\u003cp\u003eThis n8n workflow provides two \u003cstrong\u003ePOST webhooks\u003c\/strong\u003e that create, resume, pause, and close AI agent sessions stored in an \u003cstrong\u003en8n Data Table\u003c\/strong\u003e. It also supports \u003cstrong\u003eTTL-based expiration\u003c\/strong\u003e, optional \u003cstrong\u003emessage deduplication\u003c\/strong\u003e via message_id, and \u003cstrong\u003ehuman handoff\u003c\/strong\u003e routing—returning a clear session context payload for downstream automation.\u003c\/p\u003e\n\n\u003ch3\u003eWhat this workflow does\u003c\/h3\u003e\n\u003cp\u003e\u003cstrong\u003eWebhook 1: Session lifecycle (message in)\u003c\/strong\u003e\u003c\/p\u003e\n\u003cul\u003e\n  \u003cli\u003eAccepts an incoming message payload and normalizes it (expects \u003ccode\u003euser_key\u003c\/code\u003e, \u003ccode\u003emessage\u003c\/code\u003e, and optional \u003ccode\u003emessage_id\u003c\/code\u003e).\u003c\/li\u003e\n  \u003cli\u003eLoads session configuration such as \u003cstrong\u003eTTL\u003c\/strong\u003e, pause defaults, and whether to enable \u003cstrong\u003emessage deduplication\u003c\/strong\u003e.\u003c\/li\u003e\n  \u003cli\u003eLooks up the latest session for the user in the Data Table and evaluates session state.\u003c\/li\u003e\n  \u003cli\u003eDecides the next action: create a new session, continue an active session, ignore duplicate \u003ccode\u003emessage_id\u003c\/code\u003e, \u003cstrong\u003eauto-resume after pause\u003c\/strong\u003e, or start a new session if the previous one is expired\/closed.\u003c\/li\u003e\n  \u003cli\u003eWrites the resulting session state back to the Data Table (insert new session or update existing status; marks old sessions as expired when needed).\u003c\/li\u003e\n  \u003cli\u003eReturns a session context response including \u003cstrong\u003eaction\u003c\/strong\u003e, \u003cstrong\u003ethread_key\u003c\/strong\u003e, \u003cstrong\u003estatus\u003c\/strong\u003e, and expiry\/pause metadata for downstream agent execution or waiting\/handoff.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003cp\u003e\u003cstrong\u003eWebhook 2: Control commands (pause\/handoff\/resume\/close)\u003c\/strong\u003e\u003c\/p\u003e\n\u003cul\u003e\n  \u003cli\u003eReceives control commands via a second POST webhook (pause, handoff, resume, close).\u003c\/li\u003e\n  \u003cli\u003eUpdates the session state in the Data Table and returns a control result payload.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eUse cases\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003eCustomer support AI that pauses for escalation and triggers \u003cstrong\u003ehuman handoff\u003c\/strong\u003e when needed.\u003c\/li\u003e\n  \u003cli\u003eChat agents that safely handle retries and prevent double-processing with \u003cstrong\u003emessage deduplication\u003c\/strong\u003e.\u003c\/li\u003e\n  \u003cli\u003eSession-based assistants where \u003cstrong\u003eTTL expiration\u003c\/strong\u003e automatically starts fresh threads after inactivity or closure.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eTechnical details\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003eImplemented with nodes: \u003cstrong\u003ecode\u003c\/strong\u003e, \u003cstrong\u003eswitch\u003c\/strong\u003e, \u003cstrong\u003ewebhook\u003c\/strong\u003e, \u003cstrong\u003edata table\u003c\/strong\u003e, and \u003cstrong\u003esticky note\u003c\/strong\u003e.\u003c\/li\u003e\n  \u003cli\u003eRequires an n8n Data Table named \u003cstrong\u003eagent_sessions\u003c\/strong\u003e with columns including \u003ccode\u003euser_key\u003c\/code\u003e, \u003ccode\u003esession_id\u003c\/code\u003e, \u003ccode\u003ethread_key\u003c\/code\u003e, \u003ccode\u003estatus\u003c\/code\u003e, timestamps, handoff\/close fields, and \u003ccode\u003elast_message_id\u003c\/code\u003e.\u003c\/li\u003e\n\u003c\/ul\u003e","brand":"N8N Commerce","offers":[{"title":"Default Title","offer_id":45938300715187,"sku":"N8N-18940","price":75.99,"currency_code":"GBP","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0749\/6279\/6723\/files\/ZtA0KoNkZg8nj4bJYSxAe_NuBKuPaQ.png?v=1788341414","url":"https:\/\/buyflowscripts.com\/products\/ai-agent-session-manager-with-webhooks-ttl-handoff-n8n","provider":"N8N Commerce","version":"1.0","type":"link"}