mirror of
https://github.com/OpenBMB/ChatDev.git
synced 2026-04-25 11:18:06 +00:00
3.8 KiB
Executable File
3.8 KiB
Executable File
FIELD_SPECS Authoring Guide
This guide explains how to write FIELD_SPECS for new configs so the Web UI forms and python -m tools.export_design_template stay in sync. It applies to any BaseConfig subclass (nodes, Memory, Thinking, Tooling, etc.).
1. Why FIELD_SPECS matter
- UI forms rely on
FIELD_SPECSto render inputs, defaults, and helper text. - The design template exporter reads
FIELD_SPECSto populateyaml_template/design*.yamland the mirrored files underfrontend/public/. - Fields missing from
FIELD_SPECSwill not appear in the UI or generated templates.
2. Basic structure
FIELD_SPECS is a dict mapping field name → ConfigFieldSpec, usually declared inside the config class:
FIELD_SPECS = {
"interpreter": ConfigFieldSpec(
name="interpreter",
display_name="Interpreter",
type_hint="str",
required=False,
default="python3",
description="Path to the Python executable",
),
...
}
Key attributes:
name: same as the YAML field.display_name: optional human label shown in the UI; falls back tonamewhen omitted.type_hint: string describing the shape (str,list[str],dict[str, Any], etc.).required: whether the UI treats the field as mandatory; usuallyFalseif a default exists.default: scalar or JSON-serializable default value.description: helper text/tooltips in forms and docs.enum: array of allowed values (strings).enumOptions: richer metadata per enum entry (label, description). Use it alongsideenumfor user-friendly dropdowns.child: reference to anotherBaseConfigsubclass for nested structures.
3. Authoring flow
- Validate in
from_dict– ensure YAML parsing enforces types and emits clearConfigErrors (seeentity/configs/python_runner.py). - Define
FIELD_SPECS– cover all public fields with type, description, default, etc. - Handle dynamic fields – when options depend on registries or filesystem scans, override
field_specs()and usereplace()to inject real-timeenum/description(e.g.,FunctionToolEntryConfig.field_specs()lists functions on disk). - Export templates – after edits run:
The command uses the latestpython -m tools.export_design_template --output yaml_template/design.yaml --mirror frontend/public/design.yamlFIELD_SPECSto regenerate YAML templates and the frontend mirror—no manual edits needed.
4. Common patterns
- Scalar fields: see
entity/configs/python_runner.pyfortimeout_seconds(integer default + validation). - Nested lists:
entity/configs/memory.pyuseschild=FileSourceConfigforfile_sources, enabling repeatable subforms. - Dynamic enums:
Node.field_specs()(aroundentity/configs/node.py:304) pulls node types from the registry and suppliesenumOptions;FunctionToolEntryConfig.field_specs()builds enumerations from the function catalog. - Registry-driven descriptions: when calling
register_node_type/register_memory_store/register_thinking_mode/register_tooling_type, always providesummary/description. Those strings populateenumOptionsand keep dropdowns self-explanatory. - Optional blocks: combine
required=Falsewith sensibledefaultvalues and make surefrom_dicthonors the same defaults.
5. Best practices
- Keep descriptions user-friendly and clarify units (e.g., “Timeout (seconds)”).
- Align defaults with parsing logic so UI expectations match backend behavior.
- For nested configs, provide concise examples or cross-links so UI users understand the structure.
- After changing
FIELD_SPECS, re-run the export command and commit the updated templates/mirror files.
For more examples inspect entity/configs/model.py, entity/configs/tooling.py, or other existing node/Memory/Thinking configs.