[PR #5414] [CLOSED] fix: persist API agent chats in thread history #5438

Closed
opened 2026-06-05 15:21:21 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/5414
Author: @officialasishkumar
Created: 4/12/2026
Status: Closed

Base: masterHead: 5060-api-agent-thread-history


📝 Commits (1)

  • 96ba3ef fix: persist api agent chats in thread history

📊 Changes

2 files changed (+145 additions, -3 deletions)

View changed files

server/__tests__/utils/chats/apiChatHandler.test.js (+137 -0)
📝 server/utils/chats/apiChatHandler.js (+8 -3)

📄 Description

Pull Request Type

  • feat (New feature)
  • 🐛 fix (Bug fix)
  • ♻️ refactor (Code refactoring without changing behavior)
  • 💄 style (UI style changes)
  • 🔨 chore (Build, CI, maintenance)
  • 📝 docs (Documentation updates)

Relevant Issues

resolves #5060

Description

Persist API @agent chat results with the same thread/user/session metadata as normal API chats so thread-scoped agent interactions are returned by thread history endpoints and visible in the UI.

This updates the synchronous API agent path to save visible chat history rows with threadId, user, and apiSessionId, and aligns the streaming API agent save path with the same metadata. Both API agent paths now return the saved chatId when persistence succeeds.

Visuals (if applicable)

N/A

Additional Information

No public API contract changes beyond including the saved chatId in API agent responses, matching normal chat behavior.

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated (if applicable)
  • I have tested my code functionality
  • Docker build succeeds locally

Focused validations run:

  • corepack yarn test server/__tests__/utils/chats/apiChatHandler.test.js --runInBand
  • cd server && corepack yarn eslint utils/chats/apiChatHandler.js
  • cd server && corepack yarn prettier --check utils/chats/apiChatHandler.js __tests__/utils/chats/apiChatHandler.test.js

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Mintplex-Labs/anything-llm/pull/5414 **Author:** [@officialasishkumar](https://github.com/officialasishkumar) **Created:** 4/12/2026 **Status:** ❌ Closed **Base:** `master` ← **Head:** `5060-api-agent-thread-history` --- ### 📝 Commits (1) - [`96ba3ef`](https://github.com/Mintplex-Labs/anything-llm/commit/96ba3efd3e90e1a5facabefdc2d076a6bbdfaaf3) fix: persist api agent chats in thread history ### 📊 Changes **2 files changed** (+145 additions, -3 deletions) <details> <summary>View changed files</summary> ➕ `server/__tests__/utils/chats/apiChatHandler.test.js` (+137 -0) 📝 `server/utils/chats/apiChatHandler.js` (+8 -3) </details> ### 📄 Description ### Pull Request Type <!-- For change type, change [ ] to [x]. --> - [ ] ✨ feat (New feature) - [x] 🐛 fix (Bug fix) - [ ] ♻️ refactor (Code refactoring without changing behavior) - [ ] 💄 style (UI style changes) - [ ] 🔨 chore (Build, CI, maintenance) - [ ] 📝 docs (Documentation updates) ### Relevant Issues <!-- Use "resolves #xxx" to auto resolve on merge. Otherwise, please use "connect #xxx" --> resolves #5060 ### Description Persist API `@agent` chat results with the same thread/user/session metadata as normal API chats so thread-scoped agent interactions are returned by thread history endpoints and visible in the UI. This updates the synchronous API agent path to save visible chat history rows with `threadId`, `user`, and `apiSessionId`, and aligns the streaming API agent save path with the same metadata. Both API agent paths now return the saved `chatId` when persistence succeeds. ### Visuals (if applicable) N/A ### Additional Information No public API contract changes beyond including the saved `chatId` in API agent responses, matching normal chat behavior. ### Developer Validations <!-- All of the applicable items should be checked. --> - [ ] I ran `yarn lint` from the root of the repo & committed changes - [x] Relevant documentation has been updated (if applicable) - [x] I have tested my code functionality - [ ] Docker build succeeds locally Focused validations run: - `corepack yarn test server/__tests__/utils/chats/apiChatHandler.test.js --runInBand` - `cd server && corepack yarn eslint utils/chats/apiChatHandler.js` - `cd server && corepack yarn prettier --check utils/chats/apiChatHandler.js __tests__/utils/chats/apiChatHandler.test.js` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 15:21:21 -04:00
yindo closed this issue 2026-06-05 15:21:21 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#5438