WeKnora/internal
lyingbug 383d26535a
feat(agent): persist human-in-the-loop prompts with a shared broker (#4250)
* feat(agent): persist human-in-the-loop prompts with a shared broker

Tool approvals and MCP OAuth prompts are now rows in agent_prompts,
awaited through hitl.Broker (lease, DB polling, Redis wake-up, per-kind
answer validation). Resolve is bound to session and kind. This is P1 of
the suspend/resume design; runs still block as before.

* feat(agent): suspend runs whose prompt outlives a short in-memory wait

Behind agent.prompt_suspend_enabled (off by default). A run raised from the
HTTP stream saves its state when a tool approval is raised; after the hot
wait the prompt moves to suspended and the assistant message is saved as
awaiting_input instead of blocking. A reaper takes over prompts whose
waiting replica stopped renewing its lease. Resume comes in a later change.

* feat(agent): resume suspended runs once their prompt is answered

The replica that records the answer resumes the run in process under the
prompt's lease. Superseded, expired and abandoned runs are closed with a
result for every tool call, and approved tools are never replayed.

* feat(agent): let users answer suspended tool approvals and follow the resumed run

* feat(agent): ask_user tool and generic prompt answer endpoint

- ask_user built-in tool: options, short forms or free text; validated
  answers, decline, suspend/resume like tool approval; non-interactive
  callers (IM, API keys) are told to ask in the reply instead
- POST /agent/prompts/{prompt_id} (and embed variant) answers ask_user
  and tool_approval prompts, returns resumed; SDK ResolveAgentPrompt
- agent_prompt_required/resolved events; AskUserCard sharing the
  countdown with ToolApprovalCard; answered questions rebuilt as cards
  from history
- awaiting-input messages keep their steps expanded so the pending card
  stays visible; prompt cards keyed by their own id
- i18n for all locales; design doc updated

* fix(agent): keep prompt answers that race a suspending or vanished owner

- Resolve suspends a pending prompt whose owner's lease lapsed, as the
  reaper would, so the answer resumes the run instead of waking nobody.
- Resuming waits for the suspending run to persist its message and clear
  its live-run marker; a marker left by a vanished owner is cleared.
- A resumed run that suspends again on a new prompt no longer has its
  message closed from the old state.
- tool_approval answers are decoded strictly and require "approved";
  fix the SDK doc that showed {"decision": "approve"}.
- API-key runs block instead of suspending, since they cannot answer.
- A run state that cannot be saved falls back to an in-memory wait, and
  NUL escapes are stripped from snapshots for jsonb.

* style(chat): align the ask_user card with the other interaction cards

Question and answer use the timeline's step text styles instead of
primary-colored and monospace text; options and form controls use the
compact step size, the number input spans the row, and the free-text
character counter is hidden.

* feat(chat): dock pending agent prompts above the composer

Tool approvals, ask_user questions and MCP OAuth prompts were answered
inline in the agent timeline, where a long answer or scrolling back
pushes them out of view. Open prompts of a streaming or suspended run
now gather in a dock above the composer (main chat and embed), one at a
time with a pager, lettered options and Enter to submit. The timeline
keeps a one-line record with a link back to the dock and the outcome
once answered. Views without a dock still answer inline.

* fix(agent): fence prompt ownership and preserve resumed turn context

* fix(agent): keep runs through consume errors and file prompts under the caller

Consume reported a store error as a lost claim, so an answer consumed
during a database hiccup detached its run: the message was never
persisted, the live-run marker stayed, and the reaper skipped the row
because the waiter had already dropped the snapshot. Consume now retries,
then decides from the row, and gives a run up only when the prompt is
known to have moved on.

Tool approvals and OAuth prompts of a shared agent were filed under the
agent's workspace, so the user's answer failed the tenant check and the
prompt timed out. Like ask_user, they now use the caller's workspace;
policy and token lookups stay in the agent's.

Enter on a picked option submits it instead of toggling it off, and
resume errors no longer report a nil cause.

* fix(agent): validate prompt choices and require durable approval claims

Reject malformed serialized option lists so the model can retry with valid arguments. Distinguish prompt consumption failures from lost ownership without authorizing side effects, and preserve native Enter selection for unselected choices.

* fix(agent): resolve prompt workflow lint errors
2026-10-14 20:37:28 +08:00
..
agent feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
application feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
assets feat(assets): add ASR test audio file and embed it in the application 2026-04-02 21:27:27 +08:00
browserskill fix(browser): refine connection and preview UI with extension version 2026-09-23 10:57:59 +08:00
common fix(markdown): sanitize invalid UTF-8 and NUL bytes 2026-08-31 12:24:35 +08:00
config feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
container feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
database feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
datasource fix(datasource/gitlab): emptied files no longer leave their old body searchable (#4008) 2026-10-12 13:06:19 +08:00
embedpolicy fix(embed): enforce host origin allowlists on framed pages 2026-09-14 18:03:57 +08:00
errors feat(knowledge): flag documents that stop making progress (#3557) 2026-09-22 21:34:08 +08:00
event feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
filetransport refactor(resource-access): unify scoped authorization and transfer recovery (#3097) 2026-09-08 15:36:33 +08:00
handler feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
im feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
infrastructure feat(agent): read chat attachments on demand (#4203) 2026-10-13 14:37:17 +08:00
ipclass fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
localsandbox feat(lite): install and run skills on the host (#3661) 2026-09-24 21:30:34 +08:00
logger fix(logger): keep LLM debug records inside their directory 2026-09-25 18:22:14 +08:00
mcp fix(mcp): keep OAuth token expiry independent of the process time zone (#4207) 2026-10-13 16:56:51 +08:00
mcpserver fix(mcp): stop advertising read-only endpoint tools as destructive 2026-10-10 20:19:13 +08:00
middleware feat(mcp): let callers without a browser obtain MCP OAuth tokens (#4229) 2026-10-13 16:37:24 +08:00
modelcontext feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
models feat(models): add WeMM embedding presets and Transformers serving (#4238) 2026-10-13 17:22:24 +08:00
ratelimit feat(embed): add backend embed channels with auth and rate limiting (#1657) 2026-06-12 23:10:39 +08:00
reranking perf(reranking): accelerate MMR selection with sparse postings 2026-10-10 20:06:30 +08:00
router feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
runtime fix(server): run ResourceCleaner on signal shutdown instead of racing Fatalf exit (#3804) 2026-09-28 23:37:36 +08:00
sandbox feat(sandbox): Docker 后端支持交互式终端 (#4023) 2026-10-10 21:38:03 +08:00
searchutil feat: judge image hits by their image in rerank and show them to vision models (#4013) 2026-10-09 13:01:48 +08:00
sourceloc fix(citations): 修复原文定位、高亮范围与 DocReader 启动失败 (#3794) 2026-09-27 20:32:26 +08:00
storageallowlist fix(storage): align default provider fallback with STORAGE_ALLOW_LIST 2026-07-15 11:05:00 +08:00
storageurl feat: judge image hits by their image in rerank and show them to vision models (#4013) 2026-10-09 13:01:48 +08:00
stream feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
textconv fix: remove GPL converter and bundle third-party license sources 2026-09-08 15:19:10 +08:00
tracing/langfuse fix(models): align configuration and multimodal embedding workflows (#4080) 2026-10-10 11:06:00 +08:00
types feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
utils fix(agent): scope database queries to authorized shared knowledge bases (#4136) 2026-10-12 11:26:34 +08:00