Traits > Memories for Moonbeam Queries#237
Merged
sfreeman422 merged 7 commits intomasterfrom Apr 17, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new “traits” layer (derived from stored memories) to provide smaller, more stable per-user context to Moonbeam, and adds a slash-command endpoint to retrieve a user’s traits.
Changes:
- Adds a new
TraitTypeORM model and associates it withSlackUser. - Implements trait persistence (replace + retrieval) and switches AI context injection from “selected memories” to “traits”.
- Adds
/ai/traitsendpoint plus tests, and adds a newTRAIT_EXTRACTION_PROMPTused to synthesize traits from memories.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/backend/src/shared/db/models/Trait.ts | New Trait entity + JOIN result type. |
| packages/backend/src/shared/db/models/SlackUser.ts | Adds traits relationship to SlackUser. |
| packages/backend/src/ai/trait/trait.persistence.service.ts | New persistence service for replacing and fetching traits. |
| packages/backend/src/ai/trait/trait.persistence.service.spec.ts | Unit tests for trait persistence behavior. |
| packages/backend/src/ai/ai.service.ts | Injects trait context into prompts; regenerates traits after memory extraction. |
| packages/backend/src/ai/ai.service.spec.ts | Updates/moves tests to validate trait context injection + regeneration. |
| packages/backend/src/ai/ai.controller.ts | Adds /traits route (slash-command) for retrieving traits. |
| packages/backend/src/ai/ai.controller.spec.ts | Adds controller tests for /traits. |
| packages/backend/src/ai/ai.constants.ts | Removes memory-selection prompt; adds trait-extraction prompt. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
This pull request introduces support for user "traits" in the backend AI service, allowing the system to extract, persist, and expose stable user characteristics (like preferences or beliefs) for use in AI prompts and Slack interactions. The main changes add a new
/traitsendpoint, trait extraction prompt, and trait context injection into AI conversations, along with comprehensive tests.Trait extraction and context integration:
TRAIT_EXTRACTION_PROMPTconstant to define how traits are synthesized from user memories, focusing on high-signal, enduring characteristics and outputting a JSON array of trait strings.API and controller changes:
/traitsendpoint inai.controller.tsthat immediately responds to Slack, then asynchronously fetches and formats a user's traits for ephemeral display, including error handling and user feedback.TraitPersistenceServicein the controller to support trait retrieval.Testing and test utilities:
/traitsendpoint, covering successful trait retrieval, empty trait lists, and error scenarios.Other changes:
MEMORY_SELECTION_PROMPTand example responses fromai.constants.ts, likely as part of deprecating or refactoring memory selection in favor of traits. [1] [2]These changes collectively enable the backend to extract, store, and use user traits for more personalized and context-aware AI interactions in Slack.