feat: LangChain drop-in with auto-provenance - #3
Merged
Conversation
MemorywireChatMessageHistory persists LangChain messages to memorywire, deriving source from message role (tool->tool_result untrusted; user/system/agent trusted) so recover works with zero manual tagging. Exposes .recover()/.arecover() scoped to conversation trust (purges tool-origin poison, keeps the conversation). [langchain] optional dep. 3 tests; full suite green (315). Docs + README.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the biggest seamlessness gap: a drop-in LangChain chat history that gives you recoverable, poison-cleanable agent memory with no manual provenance tagging.
What
MemorywireChatMessageHistory(BaseChatMessageHistory)— persists every message to memorywire, auto-derivingsourcefrom the message role:HumanMessage→user,SystemMessage→system,AIMessage→agent(trusted)ToolMessage/FunctionMessage→tool_result(untrusted — the injection vector)BaseChatMessageHistory(e.g.RunnableWithMessageHistory). Sync + async..recover()/.arecover()— cleans the session, scoped to conversation trust ({user, system, agent}): purges tool-origin poison without deleting the conversation.dry_rundefaults to True.[langchain]optional dep (langchain-core>=0.3).Why it matters
recover's power depends on thesourcefield. Until now that was the developer's job to set. This makes it automatic in the biggest agent framework — turningrecoverfrom "works if you instrument everything" into "works out of the box."Tests
3 new (
tests/unit/test_langchain.py) — role→source mapping; aToolMessagebecomes purge-flagged while user/ai/system stay; clear forgets. Full unit suite green (315). A test caught (and we fixed) that the agent's own replies must be trusted in a conversation, else recover would nuke them.Additive; docs in
docs/langchain.md.