Skip to content

Commit b66838a

Browse files
committed
[chore][tests][anchor the rollback tests away from the shared file tail]
1 parent 1f40a43 commit b66838a

1 file changed

Lines changed: 86 additions & 86 deletions

File tree

tests/structs/test_agent.py

Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,92 +2468,6 @@ def test_unset_credentials_are_omitted_from_the_provider_call(
24682468
print("✓ Default path leaves both out")
24692469

24702470

2471-
# ============================================================================
2472-
# CONTEXT LENGTH
2473-
# ============================================================================
2474-
2475-
2476-
class TestContextLength:
2477-
"""context_length must survive __init__ and reach the Conversation."""
2478-
2479-
@staticmethod
2480-
def _agent(**kwargs):
2481-
with patch("swarms.structs.agent.LiteLLM"):
2482-
return Agent(
2483-
agent_name="ctx_agent",
2484-
max_loops=1,
2485-
print_on=False,
2486-
verbose=False,
2487-
persistent_memory=False,
2488-
**kwargs,
2489-
)
2490-
2491-
def test_explicit_value_is_honoured(self):
2492-
"""The constructor argument used to be overwritten with 16000."""
2493-
agent = self._agent(
2494-
model_name="gpt-4.1", context_length=200000
2495-
)
2496-
2497-
assert agent.context_length == 200000
2498-
assert agent.short_memory.context_length == 200000
2499-
2500-
def test_default_uses_the_model_input_window(self):
2501-
"""Omitting it should size to the model, not a flat 16000."""
2502-
agent = self._agent(model_name="gpt-4o")
2503-
2504-
# gpt-4o's input window is far above the old hardcoded default;
2505-
# asserting the relation rather than the literal keeps this from
2506-
# breaking when litellm refreshes its model table.
2507-
assert agent.context_length > 16000
2508-
2509-
def test_unknown_model_falls_back(self):
2510-
"""An unrecognised model must not raise out of __init__."""
2511-
agent = self._agent(model_name="totally-made-up-model-xyz")
2512-
2513-
assert agent.context_length == 16000
2514-
2515-
2516-
# ============================================================================
2517-
# TOOLS LIST ISOLATION
2518-
# ============================================================================
2519-
2520-
2521-
class TestToolsListIsolation:
2522-
"""tools_list_dictionary must not be shared between Agent instances."""
2523-
2524-
@staticmethod
2525-
def _agent(name, **kwargs):
2526-
with patch("swarms.structs.agent.LiteLLM"):
2527-
return Agent(
2528-
agent_name=name,
2529-
model_name="gpt-5.4",
2530-
max_loops=1,
2531-
print_on=False,
2532-
verbose=False,
2533-
persistent_memory=False,
2534-
**kwargs,
2535-
)
2536-
2537-
def test_default_is_per_instance(self):
2538-
"""One agent's tools must not reach another, or the next one."""
2539-
first = self._agent("First")
2540-
second = self._agent("Second")
2541-
first.tools_list_dictionary.append(
2542-
{"function": {"name": "x"}}
2543-
)
2544-
2545-
assert second.tools_list_dictionary == []
2546-
# a fresh agent too: the old pollution outlived agents on __defaults__
2547-
assert self._agent("Third").tools_list_dictionary == []
2548-
given = [{"function": {"name": "given"}}]
2549-
assert (
2550-
self._agent(
2551-
"Fourth", tools_list_dictionary=given
2552-
).tools_list_dictionary
2553-
== given
2554-
)
2555-
2556-
25572471
# ============================================================================
25582472
# RETRY MEMORY ROLLBACK
25592473
# ============================================================================
@@ -2642,6 +2556,92 @@ def test_rollback_also_rewinds_memory_md(self, tmp_path):
26422556
assert "keep me" in contents
26432557

26442558

2559+
# ============================================================================
2560+
# CONTEXT LENGTH
2561+
# ============================================================================
2562+
2563+
2564+
class TestContextLength:
2565+
"""context_length must survive __init__ and reach the Conversation."""
2566+
2567+
@staticmethod
2568+
def _agent(**kwargs):
2569+
with patch("swarms.structs.agent.LiteLLM"):
2570+
return Agent(
2571+
agent_name="ctx_agent",
2572+
max_loops=1,
2573+
print_on=False,
2574+
verbose=False,
2575+
persistent_memory=False,
2576+
**kwargs,
2577+
)
2578+
2579+
def test_explicit_value_is_honoured(self):
2580+
"""The constructor argument used to be overwritten with 16000."""
2581+
agent = self._agent(
2582+
model_name="gpt-4.1", context_length=200000
2583+
)
2584+
2585+
assert agent.context_length == 200000
2586+
assert agent.short_memory.context_length == 200000
2587+
2588+
def test_default_uses_the_model_input_window(self):
2589+
"""Omitting it should size to the model, not a flat 16000."""
2590+
agent = self._agent(model_name="gpt-4o")
2591+
2592+
# gpt-4o's input window is far above the old hardcoded default;
2593+
# asserting the relation rather than the literal keeps this from
2594+
# breaking when litellm refreshes its model table.
2595+
assert agent.context_length > 16000
2596+
2597+
def test_unknown_model_falls_back(self):
2598+
"""An unrecognised model must not raise out of __init__."""
2599+
agent = self._agent(model_name="totally-made-up-model-xyz")
2600+
2601+
assert agent.context_length == 16000
2602+
2603+
2604+
# ============================================================================
2605+
# TOOLS LIST ISOLATION
2606+
# ============================================================================
2607+
2608+
2609+
class TestToolsListIsolation:
2610+
"""tools_list_dictionary must not be shared between Agent instances."""
2611+
2612+
@staticmethod
2613+
def _agent(name, **kwargs):
2614+
with patch("swarms.structs.agent.LiteLLM"):
2615+
return Agent(
2616+
agent_name=name,
2617+
model_name="gpt-5.4",
2618+
max_loops=1,
2619+
print_on=False,
2620+
verbose=False,
2621+
persistent_memory=False,
2622+
**kwargs,
2623+
)
2624+
2625+
def test_default_is_per_instance(self):
2626+
"""One agent's tools must not reach another, or the next one."""
2627+
first = self._agent("First")
2628+
second = self._agent("Second")
2629+
first.tools_list_dictionary.append(
2630+
{"function": {"name": "x"}}
2631+
)
2632+
2633+
assert second.tools_list_dictionary == []
2634+
# a fresh agent too: the old pollution outlived agents on __defaults__
2635+
assert self._agent("Third").tools_list_dictionary == []
2636+
given = [{"function": {"name": "given"}}]
2637+
assert (
2638+
self._agent(
2639+
"Fourth", tools_list_dictionary=given
2640+
).tools_list_dictionary
2641+
== given
2642+
)
2643+
2644+
26452645
# ============================================================================
26462646
# MAIN TEST RUNNER
26472647
# ============================================================================

0 commit comments

Comments
 (0)