Skip to content

fix(agent): report the system prompt before a session's first message - #974

Merged
agegr merged 3 commits into
agegr:mainfrom
wyx20021207-create:fix/system-prompt-empty-state
Sep 30, 2026
Merged

agegr merged 3 commits into
agegr:mainfrom
wyx20021207-create:fix/system-prompt-empty-state

Conversation

@wyx20021207-create

Copy link
Copy Markdown
Contributor

What

get_state reported agent.state.systemPrompt, which Pi 0.86 turned into a getter that replays the transcript's system messages. A session that has not run anything yet has no message to replay, so the field came back as "" — and SystemPromptPanel renders prompt === "" as "System prompt is empty (tools are disabled)", a state meant for Chat-only sessions. Every brand-new session therefore claimed its tools were disabled until the first message was sent. Sessions that already have messages were unaffected, which is why this only shows up on a fresh session.

Fixes #973.

How

systemPrompt: this.exactSystemPrompt?.() ?? this.inner.systemPrompt ?? "",

AgentSession.systemPrompt renders the prompt from the current options and is populated while the session is built (_buildRuntime → _refreshToolRegistry → setActiveToolsByName → _rebuildSystemPrompt), so it is already correct before the first run. Its meaning did not change in 0.86 — it is what the old _baseSystemPrompt field held. The exact-prompt branch is untouched, so Chat-only sessions and replace-mode subagents keep reporting their projected prompt.

Verification

The empty string is the whole bug — one brand-new session, nothing sent, the same prompt read two ways:

read via value
agent.state.systemPrompt (what get_state read before) ""
AgentSession.systemPrompt (what it reads now) 7613 chars
  • End-to-end against the real SDK (0.87.1): calling startRpcSession() and reading get_state on a brand-new session with no message sent now returns the full rendered prompt — preamble, tool list, skills, cwd — instead of "". On that same session agent.state.systemPrompt is still "".
  • Confirmed in the browser: opening the System panel on a brand-new session in a build with this change shows the full prompt instead of the empty state. The same build without the change still shows the empty state.
  • Regression test: get_state reports the prompt of a session that has not run anything yet covers the empty-transcript case. It fails on main and passes with the change.
  • The existing test that drives this field moved from agent.state.systemPrompt to inner.systemPrompt — which is also what extensions rewrite when they are bound, so it still tests what its name says.
  • npm run lint and npx tsc --noEmit are clean.
  • npm test: identical results to main — the same pre-existing failures (FileViewer, terminal PTY, symlink and PATH tests; all Windows-only), no new ones.

wyx20021207-create and others added 3 commits September 26, 2026 20:08
`get_state` read `agent.state.systemPrompt`, which Pi 0.86 turned into a
getter that replays the transcript. A session that has not run anything
yet has no system message to replay, so the field came back as "" and the
System panel rendered its "prompt is empty (tools are disabled)" state for
every brand-new session.

Read the session-level getter instead. It renders the prompt from the
current options, which are populated while the session is built, so it is
already correct before the first run; its meaning did not change in 0.86,
and it is what the old `_baseSystemPrompt` field held.

Fixes agegr#973
The session getter renders the prompt from the base options, so after a run it
drops the sections a before_agent_start handler changed for that run. Report the
transcript replay when it has a prompt and fall back to the getter only while it
is still empty.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@agegr

agegr commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Thanks @wyx20021207-create! #973 is real: the SDK builds the agent with systemPrompt: "", so agent.state.systemPrompt has nothing to replay until the first run persists a system message, and the panel shows the Chat-only empty state.

I pushed one change on top of your commit:

  • Keep the replayed prompt once there is one. AgentSession.systemPrompt renders from the base options. During a run it uses _runSystemPromptOptions, but that is cleared when the run ends. So after the first message, reading only the getter would drop any section a before_agent_start handler changed for that run, while the transcript replay still holds exactly what the model saw. get_state now reports the replay when it's non-empty and falls back to the getter only while it's still empty. There's a new test for that case next to yours.
  • Merged main.

The getter exists unchanged in pi 0.99, so this carries over to the upgrade. tsc --noEmit, eslint, and the full unit suite pass (the one failure, worktree.test.mjs force removal, also fails on main in my macOS temp dir). LGTM 👍


Generated by Claude Code

@agegr
agegr merged commit 6f92983 into agegr:main Sep 30, 2026
2 checks passed
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
…gr#976 agegr#974 agegr#989 agegr#990 agegr#991)

这 8 个提交与我们的分叉没有文本冲突,直接并入:
- agegr#1011 回合答案出现后折叠过程详情
- agegr#1012 移动端打开模型选择器不弹键盘
- agegr#972/agegr#976 行内链接在 CJK 标点处停止、行内公式与货币格式
- agegr#974 首条消息前即报告 system prompt
- agegr#989/agegr#990/agegr#991 子代理:收集标记按 run 计、重启后的中断报告、续跑背景报告标注
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
…agegr#974)

* fix(agent): report the system prompt before a session's first message

`get_state` read `agent.state.systemPrompt`, which Pi 0.86 turned into a
getter that replays the transcript. A session that has not run anything
yet has no system message to replay, so the field came back as "" and the
System panel rendered its "prompt is empty (tools are disabled)" state for
every brand-new session.

Read the session-level getter instead. It renders the prompt from the
current options, which are populated while the session is built, so it is
already correct before the first run; its meaning did not change in 0.86,
and it is what the old `_baseSystemPrompt` field held.

Fixes agegr#973

* fix(agent): keep the replayed system prompt once a run has recorded one

The session getter renders the prompt from the base options, so after a run it
drops the sections a before_agent_start handler changed for that run. Report the
transcript replay when it has a prompt and fall back to the getter only while it
is still empty.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Alex Yang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
…agegr#974)

* fix(agent): report the system prompt before a session's first message

`get_state` read `agent.state.systemPrompt`, which Pi 0.86 turned into a
getter that replays the transcript. A session that has not run anything
yet has no system message to replay, so the field came back as "" and the
System panel rendered its "prompt is empty (tools are disabled)" state for
every brand-new session.

Read the session-level getter instead. It renders the prompt from the
current options, which are populated while the session is built, so it is
already correct before the first run; its meaning did not change in 0.86,
and it is what the old `_baseSystemPrompt` field held.

Fixes agegr#973

* fix(agent): keep the replayed system prompt once a run has recorded one

The session getter renders the prompt from the base options, so after a run it
drops the sections a before_agent_start handler changed for that run. Report the
transcript replay when it has a prompt and fall back to the getter only while it
is still empty.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Alex Yang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

Title: System panel shows "System prompt is empty (tools are disabled)" on a fresh session until the first message

2 participants