Workflow Custom Code Writing Specification
Background: For security reasons, the code writing for 【python custom skill code】&&【advanced orchestration - code node】is standardized.
Supported Python Packages
1. Built-in Functions and Types
dictsortedfiltermapenumerate
2. Standard Library Modules
Data Processing
jsondecimaluuidbase64hashlib
String Processing
re(regular expressions)stringtextwrapdifflib(difference comparison)
Data Structures and Algorithms
copybisect(binary search)heapq(heap queue)statistics(statistical calculations)
Mathematical Computation
mathoperator(operator functions)
Date and Time
datetimetimecalendar
Other Utilities
random(random number generation)requests(HTTP requests)
3. Type Annotations (typing module)
typing(the module itself)AnyUnionOptionalLiteralFinalClassVarTypeVarGenericProtocolruntime_checkableoverloadcastTYPE_CHECKINGNoReturnListDictSetTupleFrozenSetDequeCounterChainMapOrderedDictDefaultDictMutableMappingMutableSequenceMutableSetMappingSequenceAbstractSetCollectionContainerIterableIteratorReversibleSizedHashableCallableAwaitableCoroutineAsyncIterableAsyncIteratorAsyncGeneratorGeneratorContextManagerAsyncContextManager
Syntax Specification
Due to the use of secure environment isolation and other restrictions, code writers need to follow relevant specifications when writing code. Premise: only built-in syntax and built-in libraries, as well as a limited set of standard libraries, are supported.
- Using the math module
import math
def calculate(a, b):
result = math.fsum([a, b])
return result
Incorrect usage:
from math import fsum
def calculate(a, b):
result = fsum([a, b])
return result
Explanation: The current code block import restrictions only allow importing the parent package when importing packages, and do not support the syntax from a import b.
- Using datetime
Correct usage:
import typing
from datetime import datetime
def get_weather(location: str, date: typing.Optional[str] = None) -> dict:
# Handle default date
if date is None:
formatted_date = datetime.datetime.now().strftime("%Y-%m-%d")
else:
try:
# Try parsing common date formats
if len(date) == 8 and date.isdigit():
# Handle YYYYMMDD format
date_obj = datetime.datetime.strptime(date, "%Y%m%d")
else:
# Try standard format YYYY-MM-DD
date_obj = datetime.datetime.strptime(date, "%Y-%m-%d")
formatted_date = date_obj.strftime("%Y-%m-%d")
except ValueError:
# If format does not match, use the original input (may cause API call failure)
formatted_date = date
# This is simulated data; in actual applications, a weather API might be called
weather_data = {
"location": location,
"date": formatted_date,
"forecast": "sunny",
"temperature": "25°C",
"wind": "light breeze"
}
return weather_data
Incorrect usage:
from typing import Optional, List, Dict, Any, Union, Callable
from datetime import datetime
...omitted...