Files
archie/internal/memory/lifecycle.go
T
sam bc1caf67aa feat: BasePlatformAdapter interface + Session types (16.3, 16.5, 16.9, 16.10, 16.11)
adapter.go — SendResult struct (success, message_id, error, retryable,
retry_after, continuation_message_ids, error_kind), ChatInfo struct
(name, type, chat_id, thread_id), BasePlatformAdapter interface
(Connect, Disconnect, Send, ChatInfo).

session.go — SessionSource (platform, chat_id/name/type, user_id/name,
thread_id, guild_id, scope_id, profile, is_bot, metadata) with Key()
for deterministic session key. SessionContext wrapping source with
connected_platforms, home_channels, session_key/id, timestamps.

session_store.go — SessionStore interface (GetOrCreate, Get, Reset,
List, GetByChannel, Touch, Delete, Close) + nellSessionStore backed
by nell.DocDB with mutex-guarded Save/Delete for race safety.

Verification: 4 findings fixed (gofmt alignment, race on mutex,
!= true anti-pattern, missing zero-value assertions). 58 tests pass
(incl -race), go vet + gofmt + golangci-lint clean.

Closes: archie-core-abg.16.3, 16.5, 16.9, 16.10, 16.11
2026-07-26 01:29:36 +10:00

65 lines
2.9 KiB
Go

package memory
// ── Lifecycle hook interfaces ─────────────────────────────────────────────
//
// Each hook is a separate sub-interface. Providers opt in by implementing
// the hooks they need. The MemoryManager discovers them via type assertion
// and calls them at the appropriate points in the agent lifecycle.
//
// All hooks are called asynchronously (fire-and-forget) to avoid blocking
// the main agent loop. Hook errors are logged but do not interrupt the
// agent's operation.
// TurnStartHook is called at the beginning of each agent turn. Providers
// can use this to load fresh context, refresh caches, or prepare
// session-scoped state before the agent processes a new user message.
type TurnStartHook interface {
// OnTurnStart is invoked when a new turn begins for the given session.
OnTurnStart(sessionID string) error
}
// SessionEndHook is called when an agent session ends (normal termination
// or shutdown). Providers can use this to persist final state, flush
// writes, or archive session data.
type SessionEndHook interface {
// OnSessionEnd is invoked when the session identified by sessionID ends.
OnSessionEnd(sessionID string) error
}
// SessionSwitchHook is called when the agent switches to a different
// session context (e.g., a conversation fork or a user-initiated session
// change). Providers can use this to unload the old session's state and
// prepare for the new session.
type SessionSwitchHook interface {
// OnSessionSwitch is invoked when the agent switches to a new session.
// oldSessionID is the session being left; newSessionID is the session
// being entered.
OnSessionSwitch(oldSessionID, newSessionID string) error
}
// PreCompressHook is called just before the agent's context is compacted
// (summarized). Providers can use this to persist volatile context that
// would otherwise be lost, or to influence what gets compacted.
type PreCompressHook interface {
// OnPreCompress is invoked before context compaction for the given
// session. The provider should ensure any important state is persisted.
OnPreCompress(sessionID string) error
}
// MemoryWriteHook is called whenever new content is written to memory.
// Providers can use this to update indexes, invalidate caches, or trigger
// downstream processing of the newly written content.
type MemoryWriteHook interface {
// OnMemoryWrite is invoked after content has been written to memory.
// content is the full text that was stored.
OnMemoryWrite(content string) error
}
// DelegationHook is called when the agent delegates work to a sub-agent
// or another provider. Providers can use this to track delegation chains
// or set up context for the delegated agent.
type DelegationHook interface {
// OnDelegation is invoked when a delegation occurs for the given session.
OnDelegation(sessionID string) error
}