refactor: address code review feedback on AgentLoop.from_config()

- Accept optional `provider` kwarg in from_config() to avoid double
  instantiation in _run_gateway (which already builds provider_snapshot)
- Restore try/except ValueError wrappers in serve() and agent() for
  clean error messages on provider creation failure
- Update test: _FakeAgentLoop captures provider from kwargs, restore
  strong assertion (seen["provider"] is provider)
This commit is contained in:
chengyongru
2026-05-09 15:30:48 +08:00
committed by Xubin Ren
parent 3202f58c41
commit 733b34d685
3 changed files with 30 additions and 16 deletions
+7 -2
View File
@@ -348,13 +348,18 @@ class AgentLoop:
bus: MessageBus | None = None,
**extra: Any,
) -> AgentLoop:
"""Create an AgentLoop from config with the common parameter set."""
"""Create an AgentLoop from config with the common parameter set.
Extra keyword arguments are forwarded to ``AgentLoop.__init__``,
allowing callers to override or extend the standard config-derived
parameters (e.g. ``cron_service``, ``session_manager``).
"""
from nanobot.providers.factory import make_provider
if bus is None:
bus = MessageBus()
defaults = config.agents.defaults
provider = make_provider(config)
provider = extra.pop("provider", None) or make_provider(config)
return cls(
bus=bus,
provider=provider,