tools.short_term_notes module

Per-channel ephemeral short-term notes (v3)

Notes are stored in a Redis sorted set with configurable TTL. They are internal/secret and auto-injected into context.

async tools.short_term_notes.store_short_term_note_for_channel(redis_client, channel_id, note_content, ttl_preset='1day', *, merge_key_ttl=False)[source]

Append one short-term note for channel_id using the standard Redis encoding.

Returns (member_json, note_id) for optional precise removal via remove_short_term_note_member(), or None when ttl_preset is invalid.

Return type:

tuple[str, str] | None

Parameters:
  • channel_id (str)

  • note_content (str)

  • ttl_preset (str)

  • merge_key_ttl (bool)

async tools.short_term_notes.remove_short_term_note_member(redis_client, channel_id, member_json)[source]

Remove one specific short-term note from a channel by its exact member.

Deletes a single note whose canonical JSON string (the value returned alongside the note id by store_short_term_note_for_channel()) is used as the sorted-set member, enabling precise removal of just that note rather than clearing the channel. If removing it empties the zset, the key is deleted outright so no empty container lingers in Redis.

Operates on the channel notes key via the async Redis client (ZREM, then ZCARD and a conditional DELETE); no other state is touched. Defined for callers that stored a note and kept the member string for later cleanup; no in-repo callers invoke it directly at present.

Parameters:
  • redis_client – Async Redis client used for the zset operations.

  • channel_id (str) – Channel whose notes key to operate on (coerced to str).

  • member_json (str) – The exact JSON member string to remove from the zset.

Return type:

None

async tools.short_term_notes.format_channel_short_term_notes_for_prompt(redis_client, channel_id)[source]

Render a channel’s live short-term notes as prompt-ready text.

Reads every unexpired note for the channel and formats each one as a [Short-term Note]: line so the result can be dropped straight into an LLM prompt. Notes with empty or missing content, and members that fail to parse as JSON, are skipped; blocks are separated by blank lines and an empty string is returned when the channel has no notes.

Reads the channel notes zset via the async Redis client (ZRANGE with scores) and performs no writes. Called by tools.admin_whisper._admin_whisper() to fold any existing channel notes into the secret admin-whisper prompt before the LLM call.

Parameters:
  • redis_client – Async Redis client used to read the notes zset.

  • channel_id (str) – Channel whose notes to format (coerced to str).

Returns:

Newline-separated [Short-term Note]: lines, or "" when the channel has no active notes.

Return type:

str