fix: scope agent memory files to selected agent in admin UI#1049
Merged
fix: scope agent memory files to selected agent in admin UI#1049
Conversation
The agent files API (agentFiles.js) was using raw @wordpress/api-fetch instead of the shared client, bypassing the agent ID interceptor entirely. Memory content never changed when switching agents in the dropdown. Three fixes: - Replace raw apiFetch with shared client in agentFiles.js so GET requests receive agent_id via the interceptor, and mutations pass it explicitly - Include selectedAgentId in all TanStack Query cache keys so each agent's files are cached independently - Forward agent_id from REST request to DailyMemoryAbilities in all four daily memory PHP handlers (list, get, put, delete)
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.
Summary
When switching agents in the dropdown on the Agents admin page, the MEMORY.md content (and all memory files) never changed — it always showed the same agent's data.
Root Cause
agentFiles.jsused raw@wordpress/api-fetchinstead of the sharedclientfrom@shared/utils/api, completely bypassing the agent ID interceptor. Theagent_idparam was never sent to the REST API, so the backend always fell back to the default agent.Fixes
api/agentFiles.js— Replaced rawapiFetchwith the sharedclient. GET requests now receiveagent_idvia the interceptor automatically. PUT/DELETE mutations passagent_idexplicitly from the Zustand store since the interceptor only covers GET.queries/agentFiles.js— AddedselectedAgentIdto all TanStack Query cache keys (KEYS,DAILY_KEYS,CONTEXT_KEYS) so each agent's files are cached independently and refetch automatically on agent switch.Api/AgentFiles.php— The 4 daily memory REST handlers (list_daily_files,get_daily_file,put_daily_file,delete_daily_file) now extractagent_idfrom the request and forward it toDailyMemoryAbilities, matching the pattern already used by the core agent file handlers above them.