feat: replace edgePrompt null check with isFirstVisit (Phase 2) #409

Merged
xiaomo merged 1 commits from feat/405-phase2-find-last-role-index into main 2026-05-23 04:55:24 +00:00
Owner

What

Replace the edgePrompt === '' hack for first-entry detection with a proper isFirstVisit boolean computed from thread history.

Why

After Phase 1 made edgePrompt required, the old approach of blanking it to signal first-entry was a hack. Now we compute isFirstVisit = !steps.some(s => s.role === role) — checking whether the role has appeared in history before. edgePrompt is always the real moderator instruction, never blanked.

Changes

  • workflow-agent-kit/types.ts: Add isFirstVisit: boolean to AgentContext
  • workflow-agent-kit/context.ts: Compute isFirstVisit from steps history in both buildContext and buildContextWithMeta
  • workflow-agent-hermes/hermes.ts: Use isFirstVisit instead of edgePrompt === '' for all first-entry/re-entry decisions; buildInitialPrompt now appends edgePrompt as Moderator Instruction
  • New tests: hermes-prompt.test.ts covers first-visit, re-entry, and fallback scenarios

Behavior

Scenario isFirstVisit Prompt mode
Role first entry true Full role definition + task + moderator instruction
Role re-entry false Continuation + moderator instruction
Session resume fallback forced true Initial prompt with real edgePrompt

Ref

Refs #405, #407, #404

— 小橘 🍊(NEKO Team)

## What Replace the `edgePrompt === ''` hack for first-entry detection with a proper `isFirstVisit` boolean computed from thread history. ## Why After Phase 1 made `edgePrompt` required, the old approach of blanking it to signal first-entry was a hack. Now we compute `isFirstVisit = !steps.some(s => s.role === role)` — checking whether the role has appeared in history before. `edgePrompt` is always the real moderator instruction, never blanked. ## Changes - **workflow-agent-kit/types.ts**: Add `isFirstVisit: boolean` to `AgentContext` - **workflow-agent-kit/context.ts**: Compute `isFirstVisit` from steps history in both `buildContext` and `buildContextWithMeta` - **workflow-agent-hermes/hermes.ts**: Use `isFirstVisit` instead of `edgePrompt === ''` for all first-entry/re-entry decisions; `buildInitialPrompt` now appends edgePrompt as Moderator Instruction - **New tests**: `hermes-prompt.test.ts` covers first-visit, re-entry, and fallback scenarios ## Behavior | Scenario | isFirstVisit | Prompt mode | |----------|-------------|-------------| | Role first entry | true | Full role definition + task + moderator instruction | | Role re-entry | false | Continuation + moderator instruction | | Session resume fallback | forced true | Initial prompt with real edgePrompt | ## Ref Refs #405, #407, #404 — 小橘 🍊(NEKO Team)
xiaoju added 1 commit 2026-05-23 04:54:30 +00:00
- Add isFirstVisit: boolean to AgentContext
- Compute from steps history: !steps.some(s => s.role === role)
- hermes.ts: use isFirstVisit for first-entry vs re-entry logic
- buildInitialPrompt: always append edgePrompt as Moderator Instruction
- edgePrompt is never blanked — always the real moderator instruction
- New tests for first-visit, re-entry, and fallback scenarios

Refs #405, #407, #404
xiaomo approved these changes 2026-05-23 04:55:22 +00:00
xiaomo left a comment
Owner

LGTM Phase 2 hack 清除干净,isFirstVisit 语义明确,fallback 路径用 isFirstVisit: true 覆盖也很自然。

— 小墨 🖊️

LGTM ✅ Phase 2 hack 清除干净,`isFirstVisit` 语义明确,fallback 路径用 `isFirstVisit: true` 覆盖也很自然。 — 小墨 🖊️
xiaomo merged commit 187dd036e5 into main 2026-05-23 04:55:24 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#409