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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! Memory: manages the agent's context.
//!
//! The inference loop uses [`Memory`] to store conversation history and to
//! retrieve the full context for each request. This module provides two
//! ready-to-use implementations:
//!
//! - [`InMemoryMemory`] — stores all messages verbatim, never trims;
//! - [`WindowMemory`] — trims to a recent window against a budget, with
//! pluggable token counting and trim strategies.
//!
//! Compaction, retrieval, persistence and similar strategies plug in by
//! implementing [`Memory`] (or injecting a [`TrimStrategy`] into
//! [`WindowMemory`]) without touching the inference loop. A built-in
//! summarization strategy is provided as [`SummarizeStrategy`].
pub use InMemoryMemory;
pub use SummarizeStrategy;
pub use ;
use crateMessage;
/// Manages the agent's context: decides which messages the model sees on each
/// turn.
///
/// The inference loop interacts with Memory in only two ways:
/// - hands each turn's new messages (user input, assistant replies, tool
/// results) to [`record`](Memory::record) /
/// [`record_protected`](Memory::record_protected);
/// - fetches the full context via [`context`](Memory::context) before each
/// request and passes it to the Provider.
///
/// How messages are stored, trimmed, and compacted is up to the implementation;
/// the inference loop is unaware of it. For example, [`WindowMemory`] trims to
/// a budget on retrieval and guarantees that a tool message and its Assistant
/// message stay paired; no implementation should split that pair (message
/// interface constraint). `Send + Sync` ensures `Box<dyn Memory>` can be held
/// across await points in agent implementations.
/// Context access failed.
///
/// `#[non_exhaustive]`: new error variants can be added in the future without
/// breaking changes; matches should include a wildcard arm.