Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Langchain memory support + ArtifactMemory #57

Merged
merged 34 commits into from
May 29, 2023
Merged

Conversation

kreneskyp
Copy link
Owner

@kreneskyp kreneskyp commented May 26, 2023

Description

Adds general support for Langchain memory classes + adds ArtifactMemory

Memory

All Langchain memory classes that extend BaseMemory should be supported unless they have custom loading requirements. (e. g. BaseChatMemory required a backend loader for persistence storage).

Memory loader will set session_id based on session config for the memory or backend class. Memory may be scoped to chat, agent, task, or user and allows grouping within those scopes. This provides a very flexible system for shared and localized memory.

Example use cases:

  • Collective memory within a chat.
  • Collective memory of an agent across multiple chats.
  • Subgroup of agents within a chat.
  • Individual agent memory.
  • "short term" task specific memory.

Artifact Memory

Artifact Memory class for loading {artifact} references into the context. The user or a bot may include a reference to a name/key and the memory class will provide it as an input for the chain & prompt template.

Ix_-_Google_Chrome_2023-05-24_20-49-45_V3
Demo of new ChatInput including artifact references

Changes

Chain memory

Chains now support Langchain memory

  • added load_memory and load_chat_memory_backend helpers
  • added get_memory_session helper for parsing session info out of runtime context
  • LLMChain, LLMReply, IXSequence, MapSubchain now support memory.
  • LLMChain now filters inputs keys provided by memory out of input_keys to support memory set directly on the chain when used inside a Sequence.

ArtifactMemory

  • Implements ArtifactMemory
  • Added ArtifactMemory to Coder v1
  • Implements Artifact.data for loading artifact content (e.g. from file)
  • Implements Artifact.as_memory_text() for rendering artifacts

Chat

  • ChatMutation now parses {artifact} references from input into artifact_keys

Misc

  • IxCallbackManager now has task_id, chat_id, agent_id, user_id properties
  • fake_chat now allows task to be passed by kwarg
  • mock_callback_manager now creates a chat if one does not exist

How Tested

  • new unit tests covering:
    • loading tools - covers all new memory related loaders
    • ArtifactMemory - full suite
    • IXSequence - full suite
    • MapSubchain - adds coverage for memory
  • manual testing with @pirate

TODOs

  • test for ChatMutation changes
  • need better test coverage for loading memory classes
  • need to decide how to handle secrets for loading memory classes
  • limit scope of artifact query
  • docs

@kreneskyp kreneskyp mentioned this pull request May 26, 2023
2 tasks
- IxSequence now checks if memory has a truthy value to avoid memory=None
- MapSubchain now passes memory to the IxSequence it creates
- added get_memory_options for consistently fetching memory class options
- memory and backend are split into load_memory and load_chat_memory_backend
- load_memory now supports both lists and single configs
- added parse_scope helper for parsing session config and returning a session_id
- adds tests for new loading helpers
- adds tests for IXSequence, MapSubchains
- MockMemory now has a session_id property for testing with memory
@kreneskyp kreneskyp marked this pull request as ready for review May 29, 2023 15:42
@kreneskyp kreneskyp merged commit 8cdf04e into master May 29, 2023
@kreneskyp kreneskyp deleted the artifact_memory branch May 29, 2023 18:03
@kreneskyp kreneskyp changed the title Artifact memory Langchain memory support + ArtifactMemory May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant