1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
-- blocks/session/init.lua — Conversation session persistence (StdPkg)
--
-- Thin wrapper around `std.kv` that round-trips an `agent.run` messages
-- array across process invocations. agent-block is single-run by design;
-- this block lets a caller keep one conversational thread alive without
-- introducing long-term memory / persona / vector-store concerns
-- (deliberately out of scope — handle those outside agent-block).
--
-- Usage:
-- local session = require("session")
-- local agent = require("agent")
--
-- local id = os.getenv("AGENT_ID") or "default"
-- local prior = session.load(id) -- empty table on first run
--
-- local r = agent.run({
-- prompt = "hello again",
-- history = prior, -- prepended to messages
-- system = "...",
-- })
--
-- session.save(id, r.messages) -- store full thread back
--
-- Trim / compaction / summarisation are caller's responsibility:
-- session.save(id, trim_last_n(r.messages, 20))
--
-- API:
-- session.load(id) → table (messages array; {} when absent)
-- session.save(id, msgs) → void
-- session.clear(id) → boolean (true if a row was deleted)
-- session.NS → namespace constant for advanced std.kv use
local M =
M. = "_agent_block_session"
local
--- Load the saved messages array for `id`.
--- @param id string
--- @return table Messages array. Empty table when no prior session.
--- Save the messages array for `id`. Overwrites any prior value.
--- @param id string
--- @param messages table
--- Delete the saved session for `id`.
--- @param id string
--- @return boolean true when a row was removed, false when none existed
return M