Skip to content

feat(session): persist message IDs, reply threading, and author identity in session history#1709

Open
dimonb wants to merge 12 commits intosipeed:mainfrom
dimonb:pr/01-message-history
Open

feat(session): persist message IDs, reply threading, and author identity in session history#1709
dimonb wants to merge 12 commits intosipeed:mainfrom
dimonb:pr/01-message-history

Conversation

@dimonb
Copy link
Contributor

@dimonb dimonb commented Mar 17, 2026

📝 Description

Persists structured metadata alongside messages in JSONL session history so the LLM can navigate thread structure and address participants by name across restarts.

What this adds:

  • MessageIDs []string and ReplyToMessageID on providers.Message — session history preserves thread structure instead of flattening conversations to plain text
  • ReplyToMessageID promoted to a first-class field on bus.InboundMessage (was metadata-only); Telegram now populates it from message.ReplyToMessage
  • User messages carry the inbound platform message_id when appended to history
  • Assistant messages are written to history only after confirmed delivery, so the outbound platform message_id can be stored in MessageIDs; placeholder edits count as delivered
  • MessageSender{Username, FirstName, LastName} struct stored with user messages — surfaced to the LLM as [from:Alice Example (@alice); msgs:#5,#6; reply_to:#3] annotations on history replay
  • FirstName/LastName extracted from Telegram user and stored in bus.SenderInfo
  • Channel.Send now returns ([]string, error) instead of error — delivered message IDs flow back through OutboundMessage.OnDelivered; the MessageIDsSender optional interface is removed
  • All four channels that support delivery IDs (Telegram, Discord, Slack, QQ) return them from Send; all others return nil
  • bus.MessageBus.SubscribeOutbound helper added (blocks until next outbound message or ctx done)

🗣️ Type of Change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

⚠️ Channel.Send signature change is breaking for external Channel implementors — all in-tree channels updated.

🤖 AI Code Generation

  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)

🔗 Related Issue

📚 Technical Context (Skip for Docs)

  • Reference URL: https://core.telegram.org/bots/api#message (MessageID / reply_to_message)
  • Reasoning: In multi-user Telegram group chats, session history loses context about who said what and which messages are replies. Without MessageIDs/ReplyToMessageID in the JSONL store, the LLM cannot reconstruct thread structure after a restart. Without storing assistant delivery IDs, outbound turns still lose their platform identity after restart. Without MessageSender, it cannot address participants by name.

🧪 Test Environment

  • Hardware: PC (x86_64)
  • OS: macOS 15 / Linux (Debian 12)
  • Model/Provider: Claude Sonnet, OpenAI GPT-4o
  • Channels: Telegram, Discord, Slack, QQ

📸 Evidence (Optional)

Click to view Logs/Screenshots

All existing tests pass (go test ./...) and lint passes (make lint).

☑️ Checklist

  • My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • I have updated the documentation accordingly.

@dimonb
Copy link
Contributor Author

dimonb commented Mar 17, 2026

Hi, guys. The idea of this PR is to preserve more information in the session history to give the LLM more context to implement threading, reactions, etc.

My plan is to gradually submit more PRs to the community to support reactions, more complex history compaction, and other cool features that I’ve implemented in my fork. It’s a little messy right now and needs some improvements in loop.go, so I’ll wait.

@dimonb dimonb force-pushed the pr/01-message-history branch from 359fcfa to 273ea9c Compare March 17, 2026 17:27
@dimonb dimonb marked this pull request as draft March 17, 2026 18:14
@sipeed-bot sipeed-bot bot added type: enhancement New feature or request domain: channel domain: agent go Pull requests that update go code labels Mar 19, 2026
@dimonb dimonb force-pushed the pr/01-message-history branch 2 times, most recently from 8898497 to be8c87b Compare March 23, 2026 09:11
dimonb added 11 commits March 23, 2026 11:33
…Sender

Replace the optional MessageIDsSender interface with a direct return value
on Send. Channels that support delivery IDs (Telegram, Discord, Slack, QQ)
return them from Send; all others return nil. Manager.sendWithRetry drops
the type-assertion branch and calls Send uniformly.
- Remove unused messageThreadAnnotation (superseded by messageHistoryAnnotation)
- Remove unused publishResponseIfNeeded (superseded by publishAgentResponseIfNeeded)
- Reformat fakeChannel method alignment broken by Send signature change
- Wrap long line in steering_test.go
@dimonb dimonb force-pushed the pr/01-message-history branch from 3f37ec6 to 4d267d9 Compare March 23, 2026 09:35
@dimonb dimonb marked this pull request as ready for review March 23, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: agent domain: channel go Pull requests that update go code type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant