Skip to content

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.

feat: Introduce global flow configuration for human-in-the-loop feedback (#4193)

João Moura0ccc15545750
diff --git a/lib/crewai/src/crewai/flow/__init__.py b/lib/crewai/src/crewai/flow/__init__.py
index 8a27685da..2e31d9220 100644
--- a/lib/crewai/src/crewai/flow/__init__.py
+++ b/lib/crewai/src/crewai/flow/__init__.py
@@ -5,6 +5,7 @@ from crewai.flow.async_feedback import (
PendingFeedbackContext,
)
from crewai.flow.flow import Flow, and_, listen, or_, router, start
+from crewai.flow.flow_config import flow_config
from crewai.flow.human_feedback import HumanFeedbackResult, human_feedback
from crewai.flow.persistence import persist
from crewai.flow.visualization import (
@@ -24,6 +25,7 @@ __all__ = [
"PendingFeedbackContext",
"and_",
"build_flow_structure",
+ "flow_config",
"human_feedback",
"listen",
"or_",
diff --git a/lib/crewai/src/crewai/flow/flow_config.py b/lib/crewai/src/crewai/flow/flow_config.py
new file mode 100644
index 000000000..308210dc9
--- /dev/null
+++ b/lib/crewai/src/crewai/flow/flow_config.py
@@ -0,0 +1,39 @@
+"""Global Flow configuration.
+
+This module provides a singleton configuration object that can be used to
+customize Flow behavior at runtime.
+"""
+
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, Any
+
+if TYPE_CHECKING:
+ from crewai.flow.async_feedback.types import HumanFeedbackProvider
+
+
+class FlowConfig:
+ """Global configuration for Flow execution.
+
+ Attributes:
+ hitl_provider: The human-in-the-loop feedback provider.
+ Defaults to None (uses console input).
+ Can be overridden by deployments at startup.
+ """
+
+ def __init__(self) -> None:
+ self._hitl_provider: HumanFeedbackProvider | None = None
+
+ @property
+ def hitl_provider(self) -> Any:
+ """Get the configured HITL provider."""
+ return self._hitl_provider
+
+ @hitl_provider.setter
+ def hitl_provider(self, provider: Any) -> None:
+ """Set the HITL provider."""
+ self._hitl_provider = provider
+
+
+# Singleton instance
+flow_config = FlowConfig()
diff --git a/lib/crewai/src/crewai/flow/human_feedback.py b/lib/crewai/src/crewai/flow/human_feedback.py
index df433b5db..568aaf060 100644
--- a/lib/crewai/src/crewai/flow/human_feedback.py
+++ b/lib/crewai/src/crewai/flow/human_feedback.py
@@ -283,11 +283,18 @@ def human_feedback(
llm=llm if isinstance(llm, str) else None,
)
- if provider is not None:
- # Use custom provider (may raise HumanFeedbackPending)
- return provider.request_feedback(context, flow_instance)
+ # Determine effective provider:
+ effective_provider = provider
+ if effective_provider is None:
+ from crewai.flow.flow_config import flow_config
+
+ effective_provider = flow_config.hitl_provider
+
+ if effective_provider is not None:
+ # Use provider (may raise HumanFeedbackPending for async providers)
+ return effective_provider.request_feedback(context, flow_instance)
else:
- # Use default console input
+ # Use default console input (local development)
return flow_instance._request_human_feedback(
message=message,
output=method_output,