mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-17 21:27:23 +08:00
feat(agent): add module-level debug logging for canvas execution flow (#16200)
Summary Add module-level debug logging to track Agent canvas execution flow (Closes #9306), enabling developers to diagnose component invocation, input/output states, and variable resolution without modifying production code. Also fix related bugs in message.py: re.sub backreference issue and unawaited _save_to_memory coroutine causing silent memory save failures. Changes agent/canvas.py: log workflow start, component invocation, and component completion agent/component/agent_with_tools.py: log Agent parameter resolution and LLM invocation path; standardize json.dumps usage agent/component/base.py: log get_input() variable resolution branches agent/component/message.py: fix re.sub backreference issue; properly await _save_to_memory coroutine Design Uses module-level loggers (logging.getLogger(__name__)) to support selective debugging: LOG_LEVELS=agent=DEBUG Zero performance impact in production (INFO level by default) Works with existing PUT /system/config/log API for runtime level changes Closes #9306 Note: While adding debug logging, I discovered and fixed two related bugs in message.py: - re.sub replacement value was interpreted as regex backreference instead of literal string - _save_to_memory coroutine was not properly awaited, causing silent failures --------- Co-authored-by: wills <willsgao@163.com>
This commit is contained in:
@@ -31,6 +31,8 @@ from common.connection_utils import timeout
|
||||
|
||||
from common.misc_utils import thread_pool_exec
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
_FEEDED_DEPRECATED_PARAMS = "_feeded_deprecated_params"
|
||||
_DEPRECATED_PARAMS = "_deprecated_params"
|
||||
_USER_FEEDED_PARAMS = "_user_feeded_params"
|
||||
@@ -481,18 +483,28 @@ class ComponentBase(ABC):
|
||||
return self._param.inputs.get(key, {}).get("value")
|
||||
|
||||
res = {}
|
||||
for var, o in self.get_input_elements().items():
|
||||
input_elements = self.get_input_elements()
|
||||
_logger.debug(
|
||||
"[Base] Component '%s' (%s) resolving inputs. Input element keys: %s",
|
||||
self._id, self.component_name, list(input_elements.keys()),
|
||||
)
|
||||
for var, o in input_elements.items():
|
||||
v = self.get_param(var)
|
||||
if v is None:
|
||||
_logger.debug("[Base] var '%s': param is None, skipping", var)
|
||||
continue
|
||||
if isinstance(v, str) and self._canvas.is_reff(v):
|
||||
self.set_input_value(var, self._canvas.get_variable_value(v))
|
||||
resolved = self._canvas.get_variable_value(v)
|
||||
self.set_input_value(var, resolved)
|
||||
_logger.debug("[Base] var '%s': resolved ref '%s' -> %s", var, v, json.dumps(resolved, ensure_ascii=False, default=str)[:200])
|
||||
elif isinstance(v, str) and re.search(self.variable_ref_patt, v):
|
||||
elements = self.get_input_elements_from_text(v)
|
||||
kv = {k: e.get('value', '') for k, e in elements.items()}
|
||||
self.set_input_value(var, self.string_format(v, kv))
|
||||
_logger.debug("[Base] var '%s': resolved text refs '%s' -> %s", var, v, json.dumps(kv, ensure_ascii=False, default=str)[:200])
|
||||
else:
|
||||
self.set_input_value(var, v)
|
||||
_logger.debug("[Base] var '%s': literal value -> %s", var, json.dumps(v, ensure_ascii=False, default=str)[:200])
|
||||
res[var] = self.get_input_value(var)
|
||||
return res
|
||||
|
||||
|
||||
Reference in New Issue
Block a user