Implement user input handling in Flows#4490
Merged
joaomdmoura merged 8 commits intomainfrom Feb 16, 2026
Merged
Conversation
- Introduced `FlowInputRequestedEvent` and `FlowInputReceivedEvent` to manage user input requests and responses during flow execution. - Added `InputProvider` protocol and `InputResponse` dataclass for customizable input handling. - Enhanced `Flow` class with `ask()` method to request user input, including timeout handling and state checkpointing. - Updated `FlowConfig` to support custom input providers. - Created `input_provider.py` for default input provider implementations, including a console-based provider. - Added comprehensive tests for `ask()` functionality, covering basic usage, timeout behavior, and integration with flow machinery.
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
- Removed unnecessary variable assignments for the result of `flow.kickoff()` in two test cases, improving code clarity. - Updated assertions to ensure the expected execution log entries are present after the flow kickoff, enhancing test reliability.
- Introduced a new context variable, `current_flow_method_name`, to store the name of the currently executing flow method, defaulting to "unknown". - Updated the Flow class to set and reset this context variable during method execution, enhancing the ability to track method calls without stack inspection. - Removed the obsolete `_resolve_calling_method_name` method, streamlining the code and improving clarity.
- Introduced a new `InputHistoryEntry` TypedDict to structure user input history for the `ask()` method, capturing details such as the question, user response, method name, timestamp, and associated metadata. - Updated the `_input_history` attribute in the Flow class to utilize the new `InputHistoryEntry` type, improving type safety and clarity in input history management.
- Updated the `ask()` method to improve timeout management by manually managing the `ThreadPoolExecutor`, preventing potential deadlocks when the provider call exceeds the timeout duration. - Added clarifications in the documentation regarding the behavior of the timeout and the underlying request handling, ensuring better understanding for users.
9223c32 to
c6e7d70
Compare
- Introduced flow memory reset capabilities in the `reset_memories_command`, allowing for both crew and flow memory resets. - Added a new utility function `_reset_flow_memory` to handle memory resets for individual flow instances, improving modularity and clarity. - Updated the `get_flows` utility to discover flow instances from project files, enhancing the CLI's ability to manage flow states. - Expanded test coverage to validate the new flow memory reset features, ensuring robust functionality and error handling.
greysonlalonde
approved these changes
Feb 16, 2026
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.
Add
self.ask()for conversational flowsFlows can now request user input mid-execution via
self.ask(). This enables conversational patterns like gathering requirements, interactive troubleshooting, multi-turn dialogs, without breaking the flow lifecycle and requiring HITL.What it does
self.ask(message, timeout=None, metadata=None)-- pauses the method, prompts the user, returns their response as a string. Works in both sync and async flow methods.Nonewhen expired, enablingwhile (msg := self.ask("You:", timeout=300)) is not None:loop patterns that always terminate.metadata={"user_id": "u123"}), receive context back from the provider viaInputResponse(text="answer", metadata={"responded_by": "u456"}). Thread-safe by design (no shared mutable state).self.statebefore eachask()call when persistence is configured, so previously gathered data survives crashes.asyncio.to_thread), soask()never blocks the event loop. Parallel listeners execute concurrently even when one is waiting for input.How it differs from
@human_feedbackself.ask()@human_feedbackThey coexist -- same flow can use both.