feat: context engine plugins, scaffolding, and pricing fixes (#6)
* feat: add 4 context engine plugins
- topic-memory: keyword clustering for topic-aware memory recall
- episodic-memory: conversation segmentation and cross-session recall
- user-profile: persistent user profiling from conversation patterns
- context-decay: time-based memory decay with reinforcement dynamics
All plugins use the ingest/after_turn hook protocol with stdin/stdout JSON.
* chore: add plugin scaffolding, update docs and templates
- Add plugin.toml template with {{NAME}} placeholder
- Add new-plugin Makefile target with hooks/ scaffolding
- Update plugins/README.md with all 10 plugins
- Update README.md stats (10 plugins, 220+ models)
- Add Plugin checkbox and checklist to PR template
- Add Plugin to issue template content type dropdown
- Fix CONTRIBUTING.md: last_verified is recommended, not required
* fix: correct model pricing and remove deprecated entries
- openrouter/gemma-2-9b-it: fix pricing from 0.0 to 0.03/0.09 per M tokens
(free variant correctly stays at 0.0)
- github-copilot: remove deprecated copilot/gpt-4 model entry
(GPT-4 retired in favor of GPT-4o for Copilot)
* docs: annotate kimi-coding as membership-gated
Kimi Code CLI uses quota-based membership model (not per-token billing).
Free tier has limited weekly requests; underlying model is K2.5.
Pricing kept at 0.0 consistent with other subscription providers
(chatgpt, github-copilot) but with explanatory comments.
* style: fix trailing newline in github-copilot.toml
* fix: correct Moonshot/Kimi model pricing from official sources
All 5 models had incorrect pricing:
- moonshot-v1-8k: 0.10/0.10 → 0.20/2.00
- moonshot-v1-32k: 0.30/0.30 → 1.00/3.00
- moonshot-v1-128k: 0.80/0.80 → 2.00/5.00
- kimi-k2: 2.00/8.00 → 0.60/2.50
- kimi-k2.5: 2.00/8.00 → 0.45/2.20
Sources: platform.moonshot.ai/docs/pricing/chat, costgoat.com, getmaxim.ai
* feat: add MiniMax M2.7 and M2.7-highspeed models
Released 2026-03-18, MiniMax's latest flagship text model.
10B activated params, 200K context, 128K output, tool use, streaming.
Pricing: $0.30/$1.20 per M tokens (input/output).
Added to both international (minimax.io) and China (minimaxi.com) providers.
This commit is contained in:
33 files changed
+2085
-36
No files matched your search
@@ -0,0 +1,134 @@
|
||||
#!/usr/bin/env python3
|
||||
"""User-profile ingest hook.
|
||||
|
||||
Reads the persisted user profile for the given agent and, when enough
|
||||
interaction data has been collected (>= 5 interactions), returns a
|
||||
compact profile summary as injected memory so the agent can personalise
|
||||
its responses.
|
||||
|
||||
This hook is READ-ONLY -- it never modifies the profile store.
|
||||
|
||||
Receives via stdin:
|
||||
{"type": "ingest", "agent_id": "...", "message": "user message text"}
|
||||
|
||||
Prints to stdout:
|
||||
{"type": "ingest_result", "memories": [{"content": "..."}]}
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Constants
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
STORE_DIR = os.path.join(
|
||||
os.path.expanduser("~"), ".librefang", "plugins", "user-profile"
|
||||
)
|
||||
|
||||
MIN_INTERACTIONS = 5
|
||||
MAX_SUMMARY_LEN = 200
|
||||
TOP_EXPERTISE = 5
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def empty_result():
|
||||
"""Return an empty ingest result."""
|
||||
return json.dumps({"type": "ingest_result", "memories": []})
|
||||
|
||||
|
||||
def load_profile(agent_id):
|
||||
"""Load the profile JSON for an agent. Returns None on any error."""
|
||||
path = os.path.join(STORE_DIR, f"{agent_id}.json")
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
if isinstance(data, dict) and isinstance(data.get("interaction_count"), int):
|
||||
return data
|
||||
except (OSError, json.JSONDecodeError, ValueError):
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
def message_length_bucket(avg_len):
|
||||
"""Classify average message length into a human-readable bucket."""
|
||||
if avg_len < 50:
|
||||
return "brief"
|
||||
elif avg_len <= 200:
|
||||
return "moderate"
|
||||
else:
|
||||
return "detailed"
|
||||
|
||||
|
||||
def build_summary(profile):
|
||||
"""Build a compact profile summary string (max MAX_SUMMARY_LEN chars)."""
|
||||
parts = []
|
||||
|
||||
# Top expertise areas
|
||||
expertise = profile.get("expertise_areas", {})
|
||||
if expertise:
|
||||
sorted_areas = sorted(expertise.items(), key=lambda x: x[1], reverse=True)
|
||||
top = [area for area, _count in sorted_areas[:TOP_EXPERTISE]]
|
||||
parts.append("expertise=" + ",".join(top))
|
||||
|
||||
# Communication style
|
||||
avg_len = profile.get("avg_message_length", 0)
|
||||
parts.append("style=" + message_length_bucket(avg_len))
|
||||
|
||||
# Technical level
|
||||
tech_level = profile.get("technical_level", "")
|
||||
if tech_level:
|
||||
parts.append("level=" + tech_level)
|
||||
|
||||
# Question ratio
|
||||
q_ratio = profile.get("question_ratio", 0.0)
|
||||
if q_ratio > 0.5:
|
||||
parts.append("asks-many-questions")
|
||||
|
||||
summary = "; ".join(parts)
|
||||
if len(summary) > MAX_SUMMARY_LEN:
|
||||
summary = summary[:MAX_SUMMARY_LEN - 3] + "..."
|
||||
return summary
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Main
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
request = json.loads(sys.stdin.read())
|
||||
except (json.JSONDecodeError, ValueError):
|
||||
print(empty_result())
|
||||
return
|
||||
|
||||
agent_id = request.get("agent_id", "")
|
||||
if not agent_id:
|
||||
print(empty_result())
|
||||
return
|
||||
|
||||
profile = load_profile(agent_id)
|
||||
if profile is None:
|
||||
print(empty_result())
|
||||
return
|
||||
|
||||
interaction_count = profile.get("interaction_count", 0)
|
||||
if interaction_count < MIN_INTERACTIONS:
|
||||
print(empty_result())
|
||||
return
|
||||
|
||||
summary = build_summary(profile)
|
||||
if not summary:
|
||||
print(empty_result())
|
||||
return
|
||||
|
||||
memory = {"content": f"[user-profile] User context: {summary}"}
|
||||
print(json.dumps({"type": "ingest_result", "memories": [memory]}))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user