Skip to content

Traits > Memories for Moonbeam Queries#237

Merged
sfreeman422 merged 7 commits intomasterfrom
feature/traits
Apr 17, 2026
Merged

Traits > Memories for Moonbeam Queries#237
sfreeman422 merged 7 commits intomasterfrom
feature/traits

Conversation

@sfreeman422
Copy link
Copy Markdown
Collaborator

@sfreeman422 sfreeman422 commented Apr 17, 2026

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 /traits endpoint, trait extraction prompt, and trait context injection into AI conversations, along with comprehensive tests.

Trait extraction and context integration:

  • Added a new TRAIT_EXTRACTION_PROMPT constant to define how traits are synthesized from user memories, focusing on high-signal, enduring characteristics and outputting a JSON array of trait strings.
  • Updated the AI service to fetch and inject trait context for conversation participants into AI prompt instructions, ensuring the model has access to relevant user traits when generating responses. [1] [2]

API and controller changes:

  • Implemented a new /traits endpoint in ai.controller.ts that immediately responds to Slack, then asynchronously fetches and formats a user's traits for ephemeral display, including error handling and user feedback.
  • Registered and instantiated the TraitPersistenceService in the controller to support trait retrieval.

Testing and test utilities:

  • Added comprehensive tests for the /traits endpoint, covering successful trait retrieval, empty trait lists, and error scenarios.
  • Mocked trait persistence methods and ensured trait context is tested in AI service prompt generation. [1] [2] [3] [4] [5] [6]

Other changes:

  • Removed the MEMORY_SELECTION_PROMPT and example responses from ai.constants.ts, likely as part of deprecating or refactoring memory selection in favor of traits. [1] [2]
  • Refactored and extended internal AI service helpers and tests to support trait context alongside memory context.

These changes collectively enable the backend to extract, store, and use user traits for more personalized and context-aware AI interactions in Slack.

Copilot AI review requested due to automatic review settings April 17, 2026 14:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Trait TypeORM model and associates it with SlackUser.
  • Implements trait persistence (replace + retrieval) and switches AI context injection from “selected memories” to “traits”.
  • Adds /ai/traits endpoint plus tests, and adds a new TRAIT_EXTRACTION_PROMPT used 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.

Comment thread packages/backend/src/ai/ai.controller.ts Outdated
Comment thread packages/backend/src/ai/trait/trait.persistence.service.ts
Comment thread packages/backend/src/ai/trait/trait.persistence.service.ts Outdated
Comment thread packages/backend/src/ai/ai.service.ts Outdated
Comment thread packages/backend/src/ai/ai.constants.ts
Comment thread packages/backend/src/ai/ai.service.spec.ts
@sfreeman422 sfreeman422 merged commit 401f471 into master Apr 17, 2026
10 checks passed
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.

3 participants