Skip to content

feat(chat): start a session directly as an agent profile - #1069

Open
SoulKyu wants to merge 1 commit into
agegr:mainfrom
SoulKyu:feat/session-agent-profile
Open

SoulKyu wants to merge 1 commit into
agegr:mainfrom
SoulKyu:feat/session-agent-profile

Conversation

@SoulKyu

@SoulKyu SoulKyu commented Oct 5, 2026

Copy link
Copy Markdown

Summary

Agent profiles could only run as subagents, dispatched by the default agent through the Agent tool. There was no way to talk to a specialized agent directly: every conversation started as the default agent. This adds an Agent selector to the new-session composer. Picking a profile starts a top-level session that runs as that profile from its first message.

It reuses what subagent sessions already do rather than adding a second mechanism. startRpcSession already restores a persisted subagent's isolated resources (exact or appended prompt, fixed tools, skill/extension switches) from its resource snapshot; a profile session pins the same snapshot, without a parent.

Server

  • POST /api/agent/new accepts agentProfile. The profile is resolved with resolveSubagentProfile() (enabled profiles only, same precedence as Agent); an unknown or disabled name is refused.
  • The new session gets the profile's prompt plan (buildSubagentPromptPlan()), tools, model and thinking level. The snapshot is written to a new pi-web:agent-profile custom entry once the profile's extension tools are resolved.
  • readSubagentSessionResources() also reads that entry, so reopening the session restores the profile, set_tools is refused ("fixed by its profile"), and navigate_tree keeps the restored loadout, exactly as for subagents. readSubagentRun() ignores it, so the session is never filed under a parent.
  • Completion notifications stay on: unlike a subagent, this session has no parent to report to.
  • GET /api/sessions/[id] returns agentProfile.
  • The extension-tool selection for a profile is extracted into resolveProfileActiveTools(), shared with the subagent runtime (no behavior change there).

Client

  • components/AgentProfileSelector.tsx: a searchable dropdown (profile lists can be long), filtering on name, display name and description. It is editable only before the first message; afterwards it shows the session's profile read-only.
  • The tool preset control is hidden for a profile session, since the profile fixes its tools.
  • The composer may already have started an empty runtime (ensure_session) to load commands. Changing the profile drops it; it was never persisted or listed. The next ensureNewSession then starts one with the chosen profile.
  • New i18n keys in en, zh-CN, zh-TW.

Test plan

  • tsc --noEmit, npm run lint, npm run build
  • npm test: 2285/2285 pass, including new lib/subagents.test.mjs cases. They check that an agent-profile entry restores its resources and is not read as a subagent run, and that a malformed entry is ignored.
  • Against a running build on a loopback port:
    • ensure_session with agentProfile → get_state.systemPrompt carries the profile's prompt;
    • set_tools is refused, and an unknown profile is rejected;
    • a prompt is answered in the profile's persona, the session file holds the pi-web:agent-profile entry, and GET /api/sessions/[id] returns agentProfile;
    • after a server restart, reopening the session restores the profile's prompt.
  • Used manually in the browser: pick a profile, chat with it, reopen the session.

Add an agent selector to the new-session composer. Picking a profile starts
a top-level session with the profile's prompt, tools, model and thinking,
reusing the isolated resources subagents already run with.

- persist the profile in a pi-web:agent-profile custom entry so reopening
  the session restores it, and expose it on GET /api/sessions/[id]
- POST /api/agent/new accepts agentProfile; a profile fixes the tools, so
  set_tools is refused and the tool preset control is hidden
- extract resolveProfileActiveTools() shared with the subagent runtime
- completion notifications stay on for these sessions (they have no parent)

This branch has not been deployed

No deployments
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.

1 participant