Files
dify/dify-agent/src/dify_agent/runtime/user_prompt_validation.py
T
盐粒 Yanliandautofix-ci[bot] 0f06aa2fdd feat(dify-agent): sync agent progress (#36633)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-05-26 03:14:10 +00:00

30 lines
983 B
Python

"""Validation for effective user prompts produced by Agenton runs.
Validation happens after safe compositor construction and run entry so runtime
execution uses the same transformed prompts as the actual pydantic-ai input.
Blank string fragments do not count as meaningful input; non-string
``UserContent`` is treated as intentional content because rich media/message
parts do not have a universal whitespace representation.
"""
from collections.abc import Sequence
from pydantic_ai.messages import UserContent
EMPTY_USER_PROMPTS_ERROR = "run.user_prompts must not be empty"
def has_non_blank_user_prompt(user_prompts: Sequence[UserContent]) -> bool:
"""Return whether composed user prompts contain meaningful input."""
for prompt in user_prompts:
if isinstance(prompt, str):
if prompt.strip():
return True
else:
return True
return False
__all__ = ["EMPTY_USER_PROMPTS_ERROR", "has_non_blank_user_prompt"]