Skip to content

Utils Guide

LangCrew includes utility functions for common development tasks. These are primarily internal functions, but can be useful for advanced use cases.

Check if files are binary or text:

from langcrew.utils import is_binary_file, is_text_file
with open('document.pdf', 'rb') as f:
data = f.read()
if is_binary_file(data):
print("Binary file")
elif is_text_file(data):
print("Text file")

Simple Chinese/English detection:

from langcrew.utils import detect_language, detect_chinese
# Detect language
lang = detect_language("你好世界") # "zh"
lang = detect_language("Hello") # "en"
# Check for Chinese
is_chinese = detect_chinese("你好世界") # True

Generate unique message IDs:

from langcrew.utils import generate_message_id
msg_id = generate_message_id() # "1748438204041_a7k9"

Most users won’t need these utilities directly. They’re primarily used internally by LangCrew components. Focus on the main Agent, Task, and Crew concepts instead.

For complete API details, see the source code documentation in the langcrew.utils module.