Skip to content

Personal AI, On Personal Devices

Python

fix: normalize TOML arrays for property setters, not just dataclass fields

Jon Saad-Falcon3b4eeded0e1e
diff --git a/src/openjarvis/cli/serve.py b/src/openjarvis/cli/serve.py
index bfd819a6..69c1d938 100644
--- a/src/openjarvis/cli/serve.py
+++ b/src/openjarvis/cli/serve.py
@@ -181,10 +181,16 @@ def serve(
_DEFAULT_TOOLS = {"think", "calculator", "web_search"}
configured = config.agent.tools
if configured:
- allowed = {
- t.strip() for t in configured.split(",")
- if t.strip()
- }
+ if isinstance(configured, list):
+ allowed = {
+ t.strip() for t in configured
+ if isinstance(t, str) and t.strip()
+ }
+ else:
+ allowed = {
+ t.strip() for t in configured.split(",")
+ if t.strip()
+ }
else:
allowed = _DEFAULT_TOOLS
diff --git a/src/openjarvis/core/config.py b/src/openjarvis/core/config.py
index d717575b..bce70fa3 100644
--- a/src/openjarvis/core/config.py
+++ b/src/openjarvis/core/config.py
@@ -1240,8 +1240,9 @@ def _apply_toml_section(target: Any, section: Dict[str, Any]) -> None:
"""Overlay TOML key/value pairs onto a dataclass instance.
Recursively handles nested dicts when the target attribute is itself
- a dataclass. Normalises TOML arrays to comma-separated strings when
- the target field is annotated as ``str``.
+ a dataclass. Normalises TOML arrays to comma-separated strings — both
+ for dataclass fields annotated as ``str`` and for backward-compat
+ property setters that expect string input.
"""
for key, value in section.items():
if hasattr(target, key):
@@ -1252,10 +1253,19 @@ def _apply_toml_section(target: Any, section: Dict[str, Any]) -> None:
else:
setattr(target, key, value)
else:
- # Normalise TOML arrays → comma-separated string when field is str
- if isinstance(value, list) and hasattr(target, "__dataclass_fields__"):
- field_obj = target.__dataclass_fields__.get(key)
- if field_obj is not None and field_obj.type in ("str", str):
+ # Normalise TOML arrays → comma-separated string.
+ # Covers both real dataclass fields and backward-compat
+ # property setters (e.g. reward_weights, default_tools).
+ if isinstance(value, list):
+ is_str_field = False
+ if hasattr(target, "__dataclass_fields__"):
+ field_obj = target.__dataclass_fields__.get(key)
+ if field_obj is not None and field_obj.type in ("str", str):
+ is_str_field = True
+ elif field_obj is None:
+ # Property, not a real field — normalise to string
+ is_str_field = True
+ if is_str_field:
value = ",".join(str(v) for v in value)
setattr(target, key, value)
diff --git a/tests/core/test_config.py b/tests/core/test_config.py
index f4adb5ec..bf4ec66f 100644
--- a/tests/core/test_config.py
+++ b/tests/core/test_config.py
@@ -458,6 +458,29 @@ class TestApplyTomlSectionListNormalization:
assert isinstance(target.enabled, str)
assert target.enabled == "code_interpreter,web_search,file_read"
+ def test_apply_toml_section_list_to_property_setter(self) -> None:
+ """TOML arrays passed to backward-compat property setters should be
+ normalized to comma-separated strings, not passed as raw lists."""
+ from openjarvis.core.config import _apply_toml_section
+
+ target = LearningConfig()
+ _apply_toml_section(target, {
+ "reward_weights": ["accuracy=0.8", "latency=0.2"],
+ })
+ assert target.metrics.accuracy_weight == 0.8
+ assert target.metrics.latency_weight == 0.2
+
+ def test_apply_toml_section_agent_tools_list(self) -> None:
+ """Agent tools should work as a TOML array."""
+ from openjarvis.core.config import _apply_toml_section
+
+ target = AgentConfig()
+ _apply_toml_section(target, {
+ "tools": ["web_search", "http_request", "file_read"],
+ })
+ assert isinstance(target.tools, str)
+ assert target.tools == "web_search,http_request,file_read"
+
class TestWhatsAppBaileysChannelConfig:
def test_defaults(self) -> None: