forked from plastic-labs/openclaw-honcho
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
126 lines (109 loc) · 4.23 KB
/
Copy pathindex.ts
File metadata and controls
126 lines (109 loc) · 4.23 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* OpenClaw Memory (Honcho) Plugin
*
* AI-native memory with dialectic reasoning for OpenClaw.
* Uses Honcho's peer paradigm for multi-party conversation memory.
*/
// @ts-ignore - resolved by openclaw runtime
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
// @ts-ignore - resolved by openclaw runtime
import type { MemoryPromptSectionBuilder } from "openclaw/plugin-sdk/memory-core";
import { honchoConfigSchema } from "./config.js";
import { createPluginState } from "./state.js";
import { registerGatewayHook } from "./hooks/gateway.js";
import { registerContextHook } from "./hooks/context.js";
import { registerCaptureHook } from "./hooks/capture.js";
import { registerSubagentHooks } from "./hooks/subagent.js";
import { registerSessionTool } from "./tools/session.js";
import { registerSearchTool } from "./tools/search.js";
import { registerContextTool } from "./tools/context.js";
import { registerAskTool } from "./tools/ask.js";
import { registerMemoryPassthrough } from "./tools/memory-passthrough.js";
import { registerMessageSearchTool } from "./tools/message-search.js";
import { registerCli } from "./commands/cli.js";
import { registerHonchoMemoryRuntime } from "./runtime.js";
/**
* Memory prompt section builder for Honcho tools.
* This is the single place for tool-selection guidance — tool descriptions
* themselves stay short to minimize per-turn token overhead.
*/
export const buildPromptSection: MemoryPromptSectionBuilder = ({
availableTools,
}) => {
const hasSession = availableTools.has("honcho_session");
const hasContext = availableTools.has("honcho_context");
const hasSearch = availableTools.has("honcho_search_conclusions");
const hasAsk = availableTools.has("honcho_ask");
const hasMessageSearch = availableTools.has("honcho_search_messages");
const anyTool = hasSession || hasContext || hasSearch || hasAsk || hasMessageSearch;
if (!anyTool) return [];
const lines: string[] = ["## Honcho Memory"];
lines.push("Choose the right Honcho tool based on what you need:");
if (hasContext) {
lines.push(
"- honcho_context: Quick user facts (detail='card') or full representation (detail='full'). Cheap, no LLM."
);
}
if (hasSearch) {
lines.push(
"- honcho_search_conclusions: Find specific past context by semantic query. Raw results, no LLM."
);
}
if (hasAsk) {
lines.push(
"- honcho_ask: Ask a question and get a direct answer. depth='quick' for facts, 'thorough' for synthesis."
);
}
if (hasMessageSearch) {
lines.push(
"- honcho_search_messages: Find specific messages across all sessions. Filter by sender (user/agent/all), date, metadata."
);
}
if (hasSession) {
lines.push(
"- honcho_session: Current session history and summary only. Not cross-session."
);
}
lines.push(
"",
"Prefer data tools (context, search) when you can reason over the results yourself. Use honcho_ask when you need Honcho to synthesize an answer.",
""
);
return lines;
};
let _loggedLoaded = false;
export default definePluginEntry({
id: "openclaw-honcho",
name: "Memory (Honcho)",
description: "AI-native memory with dialectic reasoning",
kind: "memory",
configSchema: honchoConfigSchema,
register(api) {
const state = createPluginState(api);
// Register memory prompt section — tool selection guidance lives here,
// not in individual tool descriptions.
api.registerMemoryPromptSection(buildPromptSection);
// Memory runtime adapter — wires Honcho into OpenClaw's memory-core slot.
registerHonchoMemoryRuntime(api, state);
// Hooks
registerGatewayHook(api, state);
registerSubagentHooks(api);
registerContextHook(api, state);
registerCaptureHook(api, state);
// Tools (5 core + 2 passthrough)
registerSessionTool(api, state);
registerContextTool(api, state);
registerSearchTool(api, state);
registerAskTool(api, state);
registerMessageSearchTool(api, state);
registerMemoryPassthrough(api, state);
// CLI
registerCli(api, state);
if (!_loggedLoaded) {
api.logger.info("Honcho memory plugin loaded");
_loggedLoaded = true;
} else {
api.logger.debug("Honcho memory plugin registered for workspace");
}
},
});