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
102
103
104
105
106
107
108
109
110
//! # harness-experience — learn from what you did before
//!
//! An **experience memory** layer for harness-rs. Where `harness-loop`'s memory
//! layer remembers *facts* ("the user likes dark roast"), this remembers
//! **episodes** — *how a situation was handled*:
//!
//! > situation faced → tools called to handle it → outcome
//!
//! Each run is recorded as an [`Episode`]; before the next run, episodes
//! similar to the current situation are recalled and injected, so the agent
//! can reuse an approach that worked ("last time I was asked to deploy, I read
//! the config then ran the deploy tool"). Recall is **semantic** when paired
//! with a semantic [`Memory`](harness_core::Memory) backend (e.g. a CortexDB-
//! or embeddings-backed one); with a keyword backend it's lexical.
//!
//! ## Pieces
//!
//! Recall (reactive — reuse what worked):
//!
//! - [`Episode`] — one unit of experience (situation, tools, outcome).
//! - [`ToolTrace`] — a `Hook` that captures the tools a run calls, in order.
//! - [`ExperienceStore`] — record/recall episodes over any `Memory`.
//! - [`ExperienceGuide`] — recall similar episodes and inject them each turn.
//! - [`ExperienceRecorder`] — ties them together; hand it to an `AgentLoop`.
//!
//! Skills (proactive — turn experience into procedure):
//!
//! - [`SkillDistiller`] — after a complex run that worked, draft a reusable
//! skill from it.
//! - [`SkillReviser`] — after a run that a skill misled, draft a fix for it.
//! - [`SkillUseTrace`] — record which skills a run followed (the reviser's
//! trigger).
//!
//! ## Wiring
//!
//! ```ignore
//! use harness_loop::experience::ExperienceRecorder;
//!
//! let recorder = ExperienceRecorder::new(memory); // any Memory backend
//! let loop_ = AgentLoop::new(model)
//! .with_hook(recorder.tool_trace_hook()) // capture tools used
//! .with_guide(Arc::new(recorder.guide().with_top_k(3))); // recall + inject
//! let outcome = loop_.run(task.clone(), &mut world).await?;
//! recorder.record(&task.description, outcome_text).await; // learn from it
//! ```
//!
//! The layer is backend-agnostic on purpose: it owns the *structure* of
//! experience (episodes + tool traces + recall injection); the *semantics* of
//! recall come from whichever `Memory` you plug in.
//!
//! ## The closed loop
//!
//! Recall alone plateaus: the agent keeps rediscovering the same approach from
//! the same three recalled episodes, and prompt space caps how much of that it
//! can carry. Distillation promotes a proven approach out of episodic memory
//! into a **skill** — a named, routable procedure that costs ~100 catalogue
//! tokens instead of a full episode, and that a human can read and correct.
//! Revision closes the loop the other way: when a skill misleads a run, the run
//! that exposed it is the evidence for the fix.
//!
//! Both are one model call, both run *after* the run they learn from (never on
//! its critical path), and neither writes to disk on its own — a multi-tenant
//! host has to scope the write per user, and may want a human to approve a
//! machine-authored skill before agents start following it.
//!
//! ```ignore
//! // After a run, with the episode in hand.
//! let existing = existing_skills_in(&user_skills_dir);
//! match distiller.distill(&episode, &existing).await? {
//! Distillation::Drafted(draft) => queue_for_review(user_id, draft),
//! Distillation::Skipped(why) => tracing::debug!(?why, "not worth a skill"),
//! }
//!
//! // …and when a run that followed a skill went wrong.
//! let req = RevisionRequest::from_dir(&user_skills_dir, skill, episode, complaint)?;
//! if let Revision::Revised(fix) = reviser.revise(&req).await? {
//! queue_for_review(user_id, *fix);
//! }
//! ```
pub use ;
pub use Episode;
pub use ExperienceGuide;
pub use ExperienceRecorder;
pub use ;
pub use ;
pub use ;
pub use ToolTrace;
pub use ;