Docs: clarify ChatObject suspend usage and callback/iterator modes#55
Merged
JohnRichard4096 merged 2 commits intomainfrom Apr 22, 2026
Merged
Docs: clarify ChatObject suspend usage and callback/iterator modes#55JohnRichard4096 merged 2 commits intomainfrom
JohnRichard4096 merged 2 commits intomainfrom
Conversation
Contributor
Reviewer's GuideRefines the English and Chinese suspend/resume concept docs to clarify lifecycle usage, explicitly document callback vs iterator exclusivity, and update code examples and wording to match the current ChatObject task management API and recommended patterns. Sequence diagram for iterator mode with outer suspend controlsequenceDiagram
actor UserController
participant ControllerTask
participant ChatObject
participant InternalTask
participant LLM
UserController->>ChatObject: configure_agent()
UserController->>ChatObject: begin()
activate ChatObject
ChatObject->>InternalTask: create_and_start()
activate InternalTask
par Control_flow
UserController->>ControllerTask: asyncio.create_task(controller)
activate ControllerTask
ControllerTask->>ChatObject: wait_to_suspend(tag, timeout)
and Business_flow
loop lifecycle
InternalTask->>InternalTask: call_suspend_decorated_method()
InternalTask->>ChatObject: check_suspend_signal()
alt suspend_requested_for_tag
InternalTask-->>ChatObject: set_suspended_state
InternalTask-->>InternalTask: pause_at_wait_for_continue
else no_suspend
InternalTask->>LLM: request_completion()
LLM-->>InternalTask: stream_chunks()
InternalTask-->>ChatObject: queue_chunks_for_iterator
end
end
end
ControllerTask-->>ChatObject: detects_suspended
ControllerTask-->>ControllerTask: custom_logic_inspect_modify_state
ControllerTask->>ChatObject: resume()
ChatObject-->>InternalTask: wake_up_from_wait_for_continue
UserController->>ChatObject: async with chat
loop streaming
ChatObject->>UserController: async for chunk in get_response_generator()
end
InternalTask-->>ChatObject: finished
deactivate InternalTask
ChatObject-->>UserController: __aexit__()
deactivate ChatObject
Class diagram for ChatObject suspend and lifecycle APIsclassDiagram
class SuspendObjectStream {
<<abstract>>
+suspend(func) async
+suspend_with_tag(tag, func) async
+wait_to_suspend(tag, timeout) async
+resume() void
+_wait_for_continue(tag) async
}
class ChatObject {
+begin() void
+set_callback_func(callback) void
+get_response_generator() async
+full_response() async
+__await__() async
+__aenter__() async
+__aexit__(exc_type, exc, tb) async
-_entry() async
-_run() async
-_run_strategy() async
}
SuspendObjectStream <|-- ChatObject
SuspendObjectStream ..> ChatObject : manages_suspend_points
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Member
Author
|
@sourcery-ai title |
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In the iterator‑mode controller examples you still use the blocking
input()call directly inside async functions (e.g.,input("Press Enter to continue...")); for consistency with other snippets and to avoid confusing users about blocking the event loop, consider wrapping these inawait asyncio.to_thread(input, ...)as you did in the callback‑mode examples.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the iterator‑mode controller examples you still use the blocking `input()` call directly inside async functions (e.g., `input("Press Enter to continue...")`); for consistency with other snippets and to avoid confusing users about blocking the event loop, consider wrapping these in `await asyncio.to_thread(input, ...)` as you did in the callback‑mode examples.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Deploying amritacore with
|
| Latest commit: |
ece04f9
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://179e8c4f.amritacore.pages.dev |
| Branch Preview URL: | https://johnrichard4096-patch-1.amritacore.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Clarify and update documentation for the ChatObject suspend/resume mechanism and usage patterns in both English and Chinese guides.
Documentation: