Quickstart
1. Install
pip install driftguard-ai
python -m spacy download en_core_web_sm
2. Record a mistake
from driftguard import DriftGuard
guard = DriftGuard()
guard.record(
action="increase salt",
feedback="too salty",
outcome="dish ruined",
)
3. Review before acting
review = guard.before_step("add more salt")
if review.warnings:
print(review.warnings[0].risk)
# → "too salty"
print(review.confidence)
# → 0.82
DriftGuard matched "add more salt" semantically to "increase salt" and surfaced the stored warning.
4. Check graph stats
print(guard.stats())
# → {'mistakes': {'nodes': 3, 'edges': 2}, 'successes': {'nodes': 0, 'edges': 0}}
guard.stats() reports the mistake graph and the success graph separately — see Success Memory for more on the latter.
5. Record a success
guard.record_success(
action="add more salt",
feedback="well seasoned",
outcome="dish praised",
)
review = guard.before_step("add a pinch of salt")
for reinforcement in review.reinforcements:
print(reinforcement.trigger, "->", reinforcement.recommendation)
# → "add more salt" -> "well seasoned"
6. Prune stale memories
guard.prune()
7. Run the MCP server
driftguard-mcp
What just happened
record()stored the causal chainaction → feedback → outcomeinto the in-memory mistake graph and persisted it to disk.before_step()embedded the query, retrieved similar action nodes from both graphs, walked their causal chains, and returned rankedwarnings(from the mistake graph) andreinforcements(from the success graph).record_success()stored a positive causal chain into the separate success graph.- Both graphs persist across restarts — DriftGuard remembers between sessions.
Next steps
- Read about Success Memory and positive reinforcement
- Configure Guard Policies to block or acknowledge risky steps
- Connect the MCP Server to Claude Desktop or any MCP client
- Drop the LangGraph Adapter into your planner graph
- Tune Configuration for your similarity thresholds and storage backend