# Sessions & Memory ## Sessions ### Sessions कैसे काम करते हैं एक agent के साथ हर conversation एक **session** में होती है। Sessions keys द्वारा identified होती हैं जो context encode करती हैं, कौन सा agent, कौन सा channel, कौन सा chat। Sessions सभी messages, tool calls, और results का एक complete transcript (append-only JSONL) maintain करती हैं। यह transcript ही है जो agents को ongoing conversation के बारे में context देता है। ### Session Keys Sessions context के आधार पर automatically route होती हैं: | Pattern | अर्थ | |---------|---------| | `agent:main:main` | Main direct conversation | | `agent:::group:` | Specific channel पर Group chat | | `agent:::channel:` | Channel/room conversation | | `cron:` | Scheduled job execution | | `hook:` | Webhook-triggered execution | ### Session Lifecycle - **Daily reset**, Sessions configurable time पर automatically reset होती हैं (default 4 AM local)। यह history preserve करते हुए प्रत्येक दिन एक fresh conversation context बनाता है। - **Idle expiry**, Sessions जो एक configurable period के लिए active नहीं रही हैं auto-reset हो सकती हैं। - **Manual reset**, `/new` या `/reset` command के साथ कभी भी fresh start करें। ### Token Tracking Sessions cumulative token usage (input, output, cache read, cache write) cost monitoring और context window management के लिए track करती हैं। --- ## Compaction ### Compaction क्या है? जब एक conversation model के context window limit के करीब पहुंचती है, Neotask इसे **compact** करता है, पुराने messages को एक condensed overview में summarize करता है और उस summary plus recent messages के साथ एक new session शुरू करता है। ### यह कैसे काम करता है 1. **Detection**, Context usage monitor करें (default trigger: context window का 80%) 2. **Summarization**, Older messages को एक compaction entry में summarize किया जाता है 3. **New session**, Top पर summary inject के साथ एक fresh session शुरू होती है 4. **Preservation**, Old transcripts history के लिए preserved हैं लेकिन अब context में load नहीं होते ### Configuration - **Enabled/disabled**, Auto-compaction toggle करें - **Threshold**, Context window का percentage जो compaction trigger करता है (default 80%) - **Minimum messages**, N से कम messages होने पर compact न करें ### Manual Compaction आप `/compact` command के साथ किसी भी समय compaction manually trigger कर सकते हैं। यह तब useful है जब आप important information खोए बिना context reset करना चाहते हैं। --- ## Memory ### Agent Memory प्रत्येक agent के पास sessions में important information persist करने के लिए एक memory system है: - **MEMORY.md**, Agent के workspace में एक markdown file जहां important facts, preferences, और context stored होते हैं - **Memory directory**, Structured knowledge के लिए `memory/` में Additional files ### Vector Search Neotask agent memory पर vector similarity search support करता है: 1. **Indexing**, Memory files embeddings का उपयोग करके indexed होती हैं 2. **Search**, Agents natural language के साथ memory query करते हैं ("User ने अपनी API preferences के बारे में क्या कहा था?") 3. **Recall**, Relevant memories similarity द्वारा ranked return होती हैं ### Memory Plugin (LanceDB) LanceDB memory plugin advanced vector storage provide करता है: - Persistent vector database - Configurable chunk size और overlap - Efficient similarity search - Memory files change होने पर Automatic re-indexing ### Automatic Recall Session start पर, relevant memories automatically recalled और agent के context में inject की जा सकती हैं। यह agents को entire conversation histories load किए बिना sessions में continuity देता है। --- ## Session Persistence सभी session data locally stored होता है: - **Session metadata**, `sessions.json` active sessions, last activity, token counts, और config track करता है - **Transcripts**, Individual session transcripts `.jsonl` files के रूप में stored - **Recovery**, Sessions data loss के बिना Gateway restarts survive करती हैं ### Cleanup - एक configurable period (default 30 days) के लिए access नहीं की गई Sessions cleanup के लिए eligible हैं - Manual session management UI या API के माध्यम से available है - Compacted transcripts archived होते हैं लेकिन review किए जा सकते हैं