You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add documentation for chat processing modes and typing indicators
This change documents the new chat processing features added in PR #685:
- Chat processing modes (sequential vs batch)
- Typing-aware batching with configurable timeouts
- New onInputChange handler for typing indicators
- Configuration properties: chatProcessingMode, chatIdleTimeout, chatTypingTimeout
Includes:
- API reference updates for AIChatAgent class
- Detailed examples for each processing mode
- Client-side React integration examples
- Guidance on when to use each mode
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: src/content/docs/agents/api-reference/agents-api.mdx
+145Lines changed: 145 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -801,6 +801,17 @@ class AIChatAgent<Env = unknown, State = unknown> extends Agent<Env, State> {
801
801
// Array of chat messages for the current conversation
802
802
messages:Message[];
803
803
804
+
// Chat processing mode: "sequential" (default) or "batch"
805
+
chatProcessingMode:"sequential"|"batch";
806
+
807
+
// Idle timeout in milliseconds for batch mode (default: 5000ms)
808
+
// How long to wait after a message is sent before processing
809
+
chatIdleTimeout:number;
810
+
811
+
// Typing timeout in milliseconds for batch mode (default: 1500ms)
812
+
// How long to wait after user stops typing before processing
813
+
chatTypingTimeout:number;
814
+
804
815
// Handle incoming chat messages and generate a response
805
816
// onFinish is called when the response is complete
806
817
async onChatMessage(
@@ -865,6 +876,138 @@ class CustomerSupportAgent extends AIChatAgent<Env> {
865
876
866
877
</TypeScriptExample>
867
878
879
+
#### Chat Processing Modes
880
+
881
+
`AIChatAgent` supports two different modes for handling multiple incoming messages:
882
+
883
+
-**`"sequential"`** (default): Process each message one-by-one. Each message gets its own response. Messages are queued and processed in order, waiting for each response to fully complete before the next.
884
+
-**`"batch"`**: Combine multiple rapid messages into one response. Uses debounce timing and optional typing indicators to batch messages together, which is better for conversational UX where users send multiple short messages in quick succession.
885
+
886
+
##### Sequential Mode
887
+
888
+
Sequential mode is the default behavior. Each message is processed independently and receives its own response:
- Use **sequential mode** when each message should be treated independently, such as commands, queries, or when you want to provide feedback for every message
1008
+
- Use **batch mode** when users tend to send multiple related messages quickly, such as in conversational chat, brainstorming sessions, or when users are providing multi-part information
1009
+
- Use **typing-aware batching** for the most natural conversational experience, where the agent waits for the user to finish their complete thought before responding
1010
+
868
1011
### Chat Agent React API
869
1012
870
1013
#### useAgentChat
@@ -905,6 +1048,8 @@ function useAgentChat(options: UseAgentChatOptions): {
0 commit comments