Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

docs(brain): note why chat turns always end with a reply (#16617)

Hazem Adel3403e22b32df
diff --git a/brain/knowledge/ai-intelligence/ai-agents.md b/brain/knowledge/ai-intelligence/ai-agents.md
index d7b393fff16..51d9b3ba9f3 100644
--- a/brain/knowledge/ai-intelligence/ai-agents.md
+++ b/brain/knowledge/ai-intelligence/ai-agents.md
@@ -86,6 +86,7 @@ Three things follow. `run_agent` has two modes: pointed at a saved agent (`agent
- **A platform tier turn falls back per step, not per turn.** When a step fails on a provider error (`isFallbackWorthy`) before sending content, the turn continues on the next candidate from the steps already done, the way `continue_truncation` does. Tool results stay in the messages, so nothing runs twice. A fast step that sent nothing is dropped on **any** error, not only fallback-worthy ones: the Fast tier can sit on a smaller context window than the main tier (Haiku 200K under a Gemini 1M tier), and once the history outgrows it the fast model answers 400 "prompt is too long", which must not sink a turn the main model can still take. For the same reason compaction sizes its budget over the tier's candidates **and** the Fast tier, not the main tier alone. After any switch the turn stays on that candidate and has no fast model. A step that already sent text never falls back, and is not retried on the same model either (`shouldRetryStream` also reads the drain). Piece tools follow the model **running the current step** (`onStepModel` from `prepareStep`), so a fast step's tool calls use the fast key. The worker sends `answeredBy` on save, and billing labels the turn with it. `answeredBy` is the model of the turn's **last** step, so a turn that ends on the fast step is billed under the fast tier's key, not the main one. Search and image stay on the pair they were resolved with, and knowledge-base search stays on the chat key, because the chunks were embedded with it.
- **"Did the failing step send anything" is read off the UI stream, and `producedVisibleOutput` cannot answer it.** `uiParts` only grows in `onStepEnd`, after chunks have already reached the client. The UI stream sends `start`/`start-step` before any content. When the model call itself throws, there is no `start-step` at all, only `error`. A stream error arrives **before** `finish-step` (`text-delta, error, finish-step`). `trackStepContent` therefore resets on `start-step`/`finish-step` and freezes its answer at the first `error` chunk. Drive it through the real `toUIMessageStream` in tests, because a mocked drain hides the ordering.
- **`AgentConfigResponse.tier` is always the console credits tier.** A platform tier run fills `platformTier`, `candidates` and `fastCandidate`. The single `credentials`/`modelId` fields equal `candidates[0]`. On a tier run the worker sends no `modelName` to `saveAgentMessages`, and the RPC ignores one on a tier row, because a model name clears the tier (the last write wins).
+- **A thinking-only final step triggers a reply nudge.** `decideLoopAction` (`run-agent-turn.ts`) decides the `continue_empty` nudge from the final step only (`stepEndsWithReply`), up to `MAX_EMPTY_CONTINUATIONS` nudges per turn. Counting every part the attempt produced, as it used to, let earlier tool chips and reasoning hide a last step that was only thinking, so the user saw "Thought for N seconds" and no reply. `shouldRetryStream` still uses the raw part count, since a stream retry is about the attempt, not its last step.
### Key files
diff --git a/bun.lock b/bun.lock
index 47178ea7827..9801f96d016 100644
--- a/bun.lock
+++ b/bun.lock
@@ -167,7 +167,7 @@
},
"packages/core/shared": {
"name": "@activepieces/shared",
- "version": "0.202.0",
+ "version": "0.202.1",
"dependencies": {
"@activepieces/core-execution": "workspace:*",
"@activepieces/core-formula": "workspace:*",