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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user