JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
test(agentserver): avoid cold tokenizer startup
guozirui19102e8c0428a
diff --git a/tests/unit_tests/agentserver/test_chat_steering_core_integration.py b/tests/unit_tests/agentserver/test_chat_steering_core_integration.pyindex 18c8a5262b..682e9fc025 100644--- a/tests/unit_tests/agentserver/test_chat_steering_core_integration.py+++ b/tests/unit_tests/agentserver/test_chat_steering_core_integration.py@@ -8,7 +8,6 @@ normal single-agent streaming, steering dispatch, binding and Core are real.from __future__ import annotationsimport asyncio-import inspectfrom importlib.util import find_specimport uuidfrom types import SimpleNamespace@@ -23,6 +22,7 @@ from openjiuwen.core.foundation.llm import ()from openjiuwen.core.foundation.llm.schema.message_chunk import AssistantMessageChunkfrom openjiuwen.core.foundation.tool import Tool, ToolCard+from openjiuwen.core.context_engine.token.base import TokenCounterfrom openjiuwen.core.runner import Runnerfrom openjiuwen.core.session.agent import Sessionfrom openjiuwen.harness import create_deep_agent@@ -43,6 +43,19 @@ from jiuwenswarm.server.runtime.agent_adapter.interface_deep import (_CORE_HAS_STEERING = find_spec("openjiuwen.core.single_agent.schema.steering") is not None+class _FastTokenCounter(TokenCounter):+ """Deterministic counter for a test that does not exercise tokenization."""++ def count(self, text, *, model="", **kwargs):+ return len(text)++ def count_messages(self, messages, *, model="", **kwargs):+ return sum(self.count(str(message.content)) for message in messages)++ def count_tools(self, tools, *, model="", **kwargs):+ return len(tools)++class _BlockingTool(Tool):def __init__(self):super().__init__(ToolCard(name="blocked_tool", description="Wait for test"))@@ -176,22 +189,16 @@ async def test_chat_pipeline_steers_real_core_during_tool_without_replacing_origtool_entered_task = Nonetry:await core.start(session=Session(session_id=sid))- # This test exercises the real Core loop and steering path, not context- # callback delivery. Earlier tests in the full suite may leave process-- # global CONTEXT_RETRIEVED callbacks registered; invoking those callbacks- # can block context creation for 30 seconds and make the 10-second tool- # entry assertion fail before the tool is scheduled. Bypass only the- # event decorator while retaining the real ContextEngine implementation.- context_engine = core._react_agent.context_engine- raw_create_context = inspect.unwrap(type(context_engine).create_context)-- async def create_context_without_global_callbacks(*args, **kwargs):- return await raw_create_context(context_engine, *args, **kwargs)+ # This test exercises steering, not tiktoken initialization. A cold+ # tiktoken cache can spend more than 30 seconds loading its encoding in+ # the full parallel suite, exhausting the tool-entry deadline before the+ # real Core loop reaches the fake tool.+ from openjiuwen.core.context_engine.token import tiktoken_countermonkeypatch.setattr(- context_engine,- "create_context",- create_context_without_global_callbacks,+ tiktoken_counter,+ "TiktokenCounter",+ _FastTokenCounter,)adapter = JiuWenSwarmDeepAdapter()adapter.mark_as_session_scoped(sid)