スキル一覧に戻る
abhishekmmgn

gemini-session-management

by abhishekmmgn

agent skills

0🍴 0📅 2026年1月20日
GitHubで見るManusで実行

SKILL.md


name: gemini-session-management description: strategies for managing agent sessions, handling conversation history (events), and implementing compaction (summarization/truncation) to prevent context overflow.

Gemini Session Management Strategies

Goal

Manage the "Session"—the turn-by-turn record of a conversation—to ensure the agent maintains immediate context without exceeding token limits or incurring high latency.

Core Concepts

1. The Session Object

  • Definition: A stateful container for a single, continuous conversation with a specific user. It isolates data so one user never sees another's context.
  • Components:
    • Events: The chronological log of interactions (User Input, Agent Response, Tool Calls, Tool Outputs).
    • State: A structured "scratchpad" for temporary working memory (e.g., items in a shopping cart) that persists only for the session duration.

Compaction Strategies (Managing Long Context)

As conversations grow, they risk "context rot" (model forgetting early details) and high latency. Use these strategies to manage history:

Strategy A: Sliding Window (Truncation)

  • Mechanism: Keep only the last $N$ turns (e.g., last 10 messages). Discard everything older.
  • Best For: Simple, reactive agents where long-term history doesn't matter.
  • Implementation:
    # Example logic
    if len(history) > 10:
        history = history[-10:]
    

Strategy B: Recursive Summarization

  • Mechanism: Periodically use an LLM to summarize the oldest part of the conversation and replace the raw messages with that summary.
  • Structure:
    1. System Prompt: (Static instructions)
    2. Summary: "Previously, the user asked about X and we determined Y..."
    3. Recent History: (Last 5-10 verbatim messages)
  • Trigger: Run this process asynchronously in the background when the turn count exceeds a threshold (e.g., every 5 turns).

Production Best Practices

  • Async Processing: Never block the user while saving the session. Upload context to storage (database) as a background event after the response is sent.
  • PII Redaction: Always redact sensitive data (names, credit cards) before writing the session to persistent storage.
  • Immutability: Treat the chronological order of events as immutable to ensure data integrity.

スコア

総合スコア

40/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です