Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add skills/latestaiagents/agent-skills/session-lifecyclenpx skills add latestaiagents/agent-skills --skill session-lifecyclegit clone --depth 1 https://github.com/latestaiagents/agent-skillsWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/latestaiagents/agent-skills/session-lifecycle)<a href="https://agentmods.dev/skills/latestaiagents/agent-skills/session-lifecycle"><img src="https://agentmods.dev/badge/skills/latestaiagents/agent-skills/session-lifecycle.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00095 | $0.01319 |
| Opus 5 | $0.00048 | $0.00660 |
| Sonnet 5 | $0.00019 | $0.00264 |
| Haiku 4.5 | $0.00010 | $0.00132 |
Grade A, and why
session-lifecycle scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 173 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Session Lifecycle
A session is a durable conversation thread between user and agent. Manage it well and you avoid blown context windows, lost state, and confused users.
When to Use
- Designing multi-turn agent UX
- Debugging context-loss or context-overflow
- Choosing when to fork vs resume vs start fresh
- Setting retention policies for session storage
Session States
[idle] → [running] → [idle] # user sends → agent responds → waits
[idle] → [compacting] → [idle] # background context reduction
[idle] → [archived] # user/TTL-triggered
Sessions are long-lived. A single session can span hours to weeks with compaction keeping context in budget.
Creating a Session
// SDK
const sessionId = crypto.randomUUID();
for await (const msg of query({ prompt: firstMessage, options: { sessionId } })) { /* ... */ }
// Managed
const session = await client.beta.sessions.create({ agent_id, metadata: { user_id } });
Always attach your own identifiers in metadata — user ID, tenant, feature flag — so you can filter and audit later.
Resuming
// SDK
for await (const msg of query({ prompt: followUp, options: { resume: sessionId } })) { /* ... */ }
// Managed
await client.beta.sessions.messages.create({ session_id, content: followUp });
Resume when:
- Same user, same topic — preserve context
- Debugging an earlier decision — replay state
- Continuing a long-running workflow
When to Start Fresh
Don't resume when:
- Topic changed completely (user pivoted to a new project)
- Session has stale or incorrect state you can't prompt-correct
- User logged in as a different identity
- Context is so full that compaction would lose critical recent info
Starting fresh is free. Resuming a bad session is expensive.
Compaction
When context approaches the model's limit, older messages are compressed into a summary. Two flavors:
- Auto-compaction (Managed default, SDK opt-in): system summarizes older turns
- Manual compaction: your app triggers it, optionally with custom instructions
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- yesterday First seen · 173 lines · 95 tokens per session scan A 53098f1beb4d
session-lifecycle is a skill published in the GitHub repository latestaiagents/agent-skills (5 stars, last pushed 4mo ago), licensed MIT. It adds 95 tokens to every session and 1,319 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.
Other skills, from other repositories
external-memory-plugin
Develop, adapt, review, test, and troubleshoot Nexent external memory provider plugins, including plugin.yaml manifests, searchable and ingestible provider protocols, error mapping, network-isolated unit tests, deployment configuration, and Mem0-based examples. Use when adding a new external memory vendor, changing an…
agent-memory-coordinator
Agent skill for memory-coordinator - invoke with $agent-memory-coordinator.
agent-collective-intelligence-coordinator
Agent skill for collective-intelligence-coordinator - invoke with $agent-collective-intelligence-coordinator.
knowledge-graph-management
Capture, validate, query, and sync architectural patterns and design decisions in the knowledge graph.
langchain-memory
LangChain memory integration including ConversationBufferMemory, ConversationSummaryMemory, and vector-based memory.
memory-summarization
Conversation summarization for memory compression and context management.