Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
fix(workspace): honor an explicit max_live_stateful_mcps of 0 (#2741)
Grapette.L4ea302a54081
diff --git a/src/agentscope/workspace/_base.py b/src/agentscope/workspace/_base.pyindex 1d81d15ca..e1f27e141 100644--- a/src/agentscope/workspace/_base.py+++ b/src/agentscope/workspace/_base.py@@ -360,6 +360,7 @@ class WorkspaceBase:Cap on concurrently live *stateful* MCP instances.``None`` derives ``max(40, 2 * <stateful defaults>)``so one session can always start its own seeded set.+ Any explicit value, including ``0``, is used as given."""self.workspace_id = workspace_id or _generate_id()self.is_alive = False@@ -369,10 +370,12 @@ class WorkspaceBase:self.skill_paths = [_normalize_local_path(path) for path in skill_paths or []]- self.max_live_stateful_mcps = max_live_stateful_mcps or max(- _DEFAULT_MAX_LIVE_STATEFUL_MCPS,- 2 * len([m for m in self.default_mcps if m.is_stateful]),- )+ if max_live_stateful_mcps is None:+ max_live_stateful_mcps = max(+ _DEFAULT_MAX_LIVE_STATEFUL_MCPS,+ 2 * len([m for m in self.default_mcps if m.is_stateful]),+ )+ self.max_live_stateful_mcps = max_live_stateful_mcpsself._mcp_specs = {}self._mcp_instances = {}diff --git a/tests/workspace_local_test.py b/tests/workspace_local_test.pyindex 868cb5fa9..7b440e01a 100644--- a/tests/workspace_local_test.py+++ b/tests/workspace_local_test.py@@ -1776,6 +1776,7 @@ class TestLocalWorkspaceMCPScoping(IsolatedAsyncioTestCase):with an empty list- ``purge_session`` drops declarations, instances and offload files- the live-stateful cap never evicts the requesting scope+ - an explicit live-stateful cap of 0 is honored"""async def asyncSetUp(self) -> None:@@ -2090,6 +2091,42 @@ class TestLocalWorkspaceMCPScoping(IsolatedAsyncioTestCase):self.assertEqual([m.name for m in again], ["a", "b"])self.assertEqual(len(connected), 6)+ @staticmethod+ def _make_stateful_mcp(name: str) -> MCPClient:+ """Return a stateful spec whose transport is never opened."""+ return MCPClient(+ name=name,+ is_stateful=True,+ mcp_config={+ "type": "http_mcp",+ "url": f"http://127.0.0.1:1/{name}",+ },+ )++ async def test_zero_stateful_cap_is_not_treated_as_unset(+ self,+ ) -> None:+ """``max_live_stateful_mcps=0`` is kept, not replaced."""+ defaults = [+ self._make_stateful_mcp("a"),+ self._make_stateful_mcp("b"),+ ]++ effective = {}+ for cap in (0, 1, None):+ ws = await self._workspace(+ default_mcps=defaults,+ max_live_stateful_mcps=cap,+ )+ effective[f"cap={cap}"] = ws.max_live_stateful_mcps++ # Only ``None`` derives the ``max(40, 2 * n)`` default; every+ # explicit value, 0 included, is used as given.+ self.assertEqual(+ effective,+ {"cap=0": 0, "cap=1": 1, "cap=None": 40},+ )+class TestLocalWorkspaceSkillPartitions(IsolatedAsyncioTestCase):"""Per-agent skill partitions under ``skills/``.