diff --git a/packages/app/src/app/agent/[serverId]/[agentId].tsx b/packages/app/src/app/agent/[serverId]/[agentId].tsx index ef597b93a..54af17062 100644 --- a/packages/app/src/app/agent/[serverId]/[agentId].tsx +++ b/packages/app/src/app/agent/[serverId]/[agentId].tsx @@ -1,4 +1,5 @@ import { useEffect, useMemo, useRef, useCallback, useState } from "react"; +import { useShallow } from "zustand/shallow"; import { View, Text, @@ -154,18 +155,21 @@ function AgentScreenContent({ serverId, agentId, onBack }: AgentScreenContentPro ); // Select child agents (agents where parentAgentId === current agentId) - const childAgents = useSessionStore((state) => { - if (!resolvedAgentId) return []; - const agents = state.sessions[serverId]?.agents; - if (!agents) return []; - const children: Array<{ id: string; title: string | null }> = []; - for (const [id, a] of agents) { - if (a.parentAgentId === resolvedAgentId) { - children.push({ id, title: a.title }); + // Use useShallow to avoid creating new array references on every render + const childAgents = useSessionStore( + useShallow((state) => { + if (!resolvedAgentId) return []; + const agents = state.sessions[serverId]?.agents; + if (!agents) return []; + const children: Array<{ id: string; title: string | null }> = []; + for (const [id, a] of agents) { + if (a.parentAgentId === resolvedAgentId) { + children.push({ id, title: a.title }); + } } - } - return children; - }); + return children; + }) + ); // Select only the specific stream state - use stable empty array to avoid infinite loop const streamItemsRaw = useSessionStore((state) => diff --git a/plan.md b/plan.md index 5d1da8309..c38a29bb7 100644 --- a/plan.md +++ b/plan.md @@ -334,7 +334,7 @@ Files requiring modification: - Run typecheck after changes. - **Done (2025-12-21 22:00)**: Added Sub-Agents section to agent info menu in `[agentId].tsx`. Added `childAgents` selector to query agents with matching `parentAgentId`. Added `handleNavigateToChildAgent` callback for navigation. UI shows "No sub-agents" when empty, or clickable list of child agents with chevron icons. Typecheck passes. -- [ ] **Test**: Verify parent/child hierarchy end-to-end. +- [x] **Test**: Verify parent/child hierarchy end-to-end. - Create a root agent via the UI - Use MCP to spawn a child agent from within the root agent @@ -343,6 +343,24 @@ Files requiring modification: - Click child agent in menu, verify navigation works - Verify back button returns to parent agent screen - If issues found: add fix tasks + re-test task. + - **Done (2025-12-21 22:30)**: PARTIAL PASS with issues found. Fixed infinite loop bug (added `useShallow` to `childAgents` selector). Agent screen loads correctly. Sub-Agents menu section shows "No sub-agents". Parent agent successfully created child via MCP `create_agent`. However, child appears on homepage because `parentAgentId` not set - MCP server doesn't auto-inject calling agent's ID. Fix task added. + +- [ ] **Fix**: Auto-inject parentAgentId in MCP create_agent tool. + + - The MCP server needs to know which agent is calling it + - Explore passing agent ID context when MCP transport is created + - Or: Have each agent's MCP session be scoped to that agent + - Update `create_agent` handler to automatically set `parentAgentId` + - Run typecheck after changes. + +- [ ] **Test**: Re-verify parent/child hierarchy after MCP fix. + + - Create a root agent via the UI + - Use MCP to spawn a child agent from within the root agent + - Verify child agent has `parentAgentId` set automatically + - Verify homepage only shows the root agent (not the child) + - Verify root agent's menu shows the child in "Sub-Agents" section + - Click child agent in menu, verify navigation works - [ ] **Plan**: Re-audit agent hierarchy after initial implementation.