-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
docs(ai-chat): correct chat.agent reference drift #3892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,17 +131,17 @@ To persist errors for debugging or undo, use `onTurnComplete` (which fires even | |
|
|
||
| ### Using `onTurnComplete` | ||
|
|
||
| `onTurnComplete` fires after every turn — successful **or** errored. The `responseMessage` will be undefined or partial on errors. Use this to mark the turn as failed: | ||
| `onTurnComplete` fires after every turn — successful **or** errored. On an errored turn `responseMessage` is undefined or partial and `error` carries the thrown value (with `finishReason` set to `"error"`). Use this to mark the turn as failed: | ||
|
|
||
| ```ts | ||
| onTurnComplete: async ({ chatId, uiMessages, responseMessage, stopped }) => { | ||
| onTurnComplete: async ({ chatId, uiMessages, responseMessage, stopped, error }) => { | ||
| // Persist the messages regardless of error state | ||
| await db.chat.update({ | ||
| where: { id: chatId }, | ||
| data: { | ||
| messages: uiMessages, | ||
| // Mark the chat as errored if no response message | ||
| lastTurnStatus: responseMessage ? "ok" : stopped ? "stopped" : "errored", | ||
| // `error` is set when the turn threw | ||
| lastTurnStatus: error ? "errored" : stopped ? "stopped" : "ok", | ||
|
Comment on lines
+134
to
+144
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 Documentation may be pre-documenting a planned The Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| }, | ||
| }); | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -286,6 +286,8 @@ Passed to the `onTurnComplete` callback. | |
| | `continuation` | `boolean` | Whether this run is continuing an existing chat | | ||
| | `usage` | `LanguageModelUsage \| undefined` | Token usage for this turn | | ||
| | `totalUsage` | `LanguageModelUsage` | Cumulative token usage across all turns | | ||
| | `finishReason` | `FinishReason \| undefined` | Why the LLM stopped (`"stop"`, `"tool-calls"`, `"error"`, …) | | ||
| | `error` | `unknown` | Set when the turn threw; `responseMessage` is then undefined or partial | | ||
|
ericallam marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Documentation references non-existent The reference docs add Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| ## BeforeTurnCompleteEvent | ||
|
|
||
|
|
@@ -761,10 +763,10 @@ See [Actions](/ai-chat/actions) for backend setup and [Sending actions](/ai-chat | |
| Eagerly trigger a run before the first message. | ||
|
|
||
| ```ts | ||
| transport.preload(chatId, { idleTimeoutInSeconds?: number }): Promise<void> | ||
| transport.preload(chatId): Promise<void> | ||
| ``` | ||
|
|
||
| No-op if a session already exists for this chatId. See [Preload](/ai-chat/fast-starts#preload) for full details. | ||
| No-op if a session already exists for this chatId. The preload idle window is set by `preloadIdleTimeoutInSeconds` on the agent, not by this call. See [Preload](/ai-chat/fast-starts#preload) for full details. | ||
|
|
||
| ## useTriggerChatTransport | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Error-handling doc example destructures non-existent
errorfield fromonTurnCompleteeventThe updated code example destructures
errorfrom theonTurnCompletecallback and uses it to determinelastTurnStatus. However,TurnCompleteEvent(defined atpackages/trigger-sdk/src/v3/ai.ts:4175-4243) has noerrorfield — the destructured value will always beundefined, solastTurnStatuswill never be"errored". The previous code (responseMessage ? "ok" : stopped ? "stopped" : "errored") was at least a heuristic that worked; the new code is strictly broken for detecting errors. The accompanying prose at line 134 ("errorcarries the thrown value") is also incorrect per the current codebase —onTurnCompleteis not called on errored turns at all (packages/trigger-sdk/src/v3/ai.ts:7527-7597).Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.