@@ -86,6 +86,15 @@ class _TestCoreAgent:
8686 "openai.types.chat.chat_completion_message_param" : MagicMock (),
8787 # Mock exa_py to avoid importing the real package when sdk.nexent.core.tools imports it
8888 "exa_py" : MagicMock (Exa = MagicMock ()),
89+ # Mock paramiko and cryptography to avoid PyO3 import issues in tests
90+ "paramiko" : MagicMock (),
91+ "cryptography" : MagicMock (),
92+ "cryptography.hazmat" : MagicMock (),
93+ "cryptography.hazmat.primitives" : MagicMock (),
94+ "cryptography.hazmat.primitives.ciphers" : MagicMock (),
95+ "cryptography.hazmat.primitives.ciphers.base" : MagicMock (),
96+ "cryptography.hazmat.bindings" : MagicMock (),
97+ "cryptography.hazmat.bindings._rust" : MagicMock (),
8998 # Mock the OpenAIModel import
9099 "sdk.nexent.core.models.openai_llm" : MagicMock (OpenAIModel = mock_openai_model_class ),
91100 # Mock CoreAgent import
@@ -100,6 +109,7 @@ class _TestCoreAgent:
100109# ---------------------------------------------------------------------------
101110with patch .dict ("sys.modules" , module_mocks ):
102111 from sdk .nexent .core .utils .observer import MessageObserver , ProcessType
112+ from sdk .nexent .core .agents import nexent_agent
103113 from sdk .nexent .core .agents .nexent_agent import NexentAgent , ActionStep , TaskStep
104114 from sdk .nexent .core .agents .agent_model import ToolConfig , ModelConfig , AgentConfig
105115
@@ -465,18 +475,17 @@ def test_create_local_tool_success(nexent_agent_instance):
465475 )
466476
467477 # Patch the module's globals to include our mock tool class
468- import sdk .nexent .core .agents .nexent_agent as nexent_agent_module
469- original_value = nexent_agent_module .__dict__ .get ("DummyTool" )
470- nexent_agent_module .__dict__ ["DummyTool" ] = mock_tool_class
478+ original_value = nexent_agent .__dict__ .get ("DummyTool" )
479+ nexent_agent .__dict__ ["DummyTool" ] = mock_tool_class
471480
472481 try :
473482 result = nexent_agent_instance .create_local_tool (tool_config )
474483 finally :
475484 # Restore original value
476485 if original_value is not None :
477- nexent_agent_module .__dict__ ["DummyTool" ] = original_value
478- elif "DummyTool" in nexent_agent_module .__dict__ :
479- del nexent_agent_module .__dict__ ["DummyTool" ]
486+ nexent_agent .__dict__ ["DummyTool" ] = original_value
487+ elif "DummyTool" in nexent_agent .__dict__ :
488+ del nexent_agent .__dict__ ["DummyTool" ]
480489
481490 mock_tool_class .assert_called_once_with (param1 = "value1" , param2 = 42 )
482491 assert result == mock_tool_instance
@@ -523,18 +532,17 @@ def test_create_local_tool_knowledge_base_search_tool_success(nexent_agent_insta
523532 },
524533 )
525534
526- import sdk .nexent .core .agents .nexent_agent as nexent_agent_module
527- original_value = nexent_agent_module .__dict__ .get ("KnowledgeBaseSearchTool" )
528- nexent_agent_module .__dict__ ["KnowledgeBaseSearchTool" ] = mock_kb_tool_class
535+ original_value = nexent_agent .__dict__ .get ("KnowledgeBaseSearchTool" )
536+ nexent_agent .__dict__ ["KnowledgeBaseSearchTool" ] = mock_kb_tool_class
529537
530538 try :
531539 result = nexent_agent_instance .create_local_tool (tool_config )
532540 finally :
533541 # Restore original value
534542 if original_value is not None :
535- nexent_agent_module .__dict__ ["KnowledgeBaseSearchTool" ] = original_value
536- elif "KnowledgeBaseSearchTool" in nexent_agent_module .__dict__ :
537- del nexent_agent_module .__dict__ ["KnowledgeBaseSearchTool" ]
543+ nexent_agent .__dict__ ["KnowledgeBaseSearchTool" ] = original_value
544+ elif "KnowledgeBaseSearchTool" in nexent_agent .__dict__ :
545+ del nexent_agent .__dict__ ["KnowledgeBaseSearchTool" ]
538546
539547 # Verify only non-excluded params are passed to __init__
540548 mock_kb_tool_class .assert_called_once_with (
@@ -578,18 +586,17 @@ def test_create_local_tool_knowledge_base_search_tool_with_conflicting_params(ne
578586 },
579587 )
580588
581- import sdk .nexent .core .agents .nexent_agent as nexent_agent_module
582- original_value = nexent_agent_module .__dict__ .get ("KnowledgeBaseSearchTool" )
583- nexent_agent_module .__dict__ ["KnowledgeBaseSearchTool" ] = mock_kb_tool_class
589+ original_value = nexent_agent .__dict__ .get ("KnowledgeBaseSearchTool" )
590+ nexent_agent .__dict__ ["KnowledgeBaseSearchTool" ] = mock_kb_tool_class
584591
585592 try :
586593 result = nexent_agent_instance .create_local_tool (tool_config )
587594 finally :
588595 # Restore original value
589596 if original_value is not None :
590- nexent_agent_module .__dict__ ["KnowledgeBaseSearchTool" ] = original_value
591- elif "KnowledgeBaseSearchTool" in nexent_agent_module .__dict__ :
592- del nexent_agent_module .__dict__ ["KnowledgeBaseSearchTool" ]
597+ nexent_agent .__dict__ ["KnowledgeBaseSearchTool" ] = original_value
598+ elif "KnowledgeBaseSearchTool" in nexent_agent .__dict__ :
599+ del nexent_agent .__dict__ ["KnowledgeBaseSearchTool" ]
593600
594601 # Verify conflicting params were filtered out from __init__ call
595602 # Only non-excluded params should be passed to __init__ due to smolagents wrapper restrictions
@@ -621,18 +628,17 @@ def test_create_local_tool_knowledge_base_search_tool_with_none_defaults(nexent_
621628 metadata = {}, # No metadata provided
622629 )
623630
624- import sdk .nexent .core .agents .nexent_agent as nexent_agent_module
625- original_value = nexent_agent_module .__dict__ .get ("KnowledgeBaseSearchTool" )
626- nexent_agent_module .__dict__ ["KnowledgeBaseSearchTool" ] = mock_kb_tool_class
631+ original_value = nexent_agent .__dict__ .get ("KnowledgeBaseSearchTool" )
632+ nexent_agent .__dict__ ["KnowledgeBaseSearchTool" ] = mock_kb_tool_class
627633
628634 try :
629635 result = nexent_agent_instance .create_local_tool (tool_config )
630636 finally :
631637 # Restore original value
632638 if original_value is not None :
633- nexent_agent_module .__dict__ ["KnowledgeBaseSearchTool" ] = original_value
634- elif "KnowledgeBaseSearchTool" in nexent_agent_module .__dict__ :
635- del nexent_agent_module .__dict__ ["KnowledgeBaseSearchTool" ]
639+ nexent_agent .__dict__ ["KnowledgeBaseSearchTool" ] = original_value
640+ elif "KnowledgeBaseSearchTool" in nexent_agent .__dict__ :
641+ del nexent_agent .__dict__ ["KnowledgeBaseSearchTool" ]
636642
637643 # Verify only non-excluded params are passed to __init__
638644 mock_kb_tool_class .assert_called_once_with (
@@ -665,18 +671,17 @@ def test_create_local_tool_with_observer_attribute(nexent_agent_instance):
665671 metadata = {},
666672 )
667673
668- import sdk .nexent .core .agents .nexent_agent as nexent_agent_module
669- original_value = nexent_agent_module .__dict__ .get ("ToolWithObserver" )
670- nexent_agent_module .__dict__ ["ToolWithObserver" ] = mock_tool_class
674+ original_value = nexent_agent .__dict__ .get ("ToolWithObserver" )
675+ nexent_agent .__dict__ ["ToolWithObserver" ] = mock_tool_class
671676
672677 try :
673678 result = nexent_agent_instance .create_local_tool (tool_config )
674679 finally :
675680 # Restore original value
676681 if original_value is not None :
677- nexent_agent_module .__dict__ ["ToolWithObserver" ] = original_value
678- elif "ToolWithObserver" in nexent_agent_module .__dict__ :
679- del nexent_agent_module .__dict__ ["ToolWithObserver" ]
682+ nexent_agent .__dict__ ["ToolWithObserver" ] = original_value
683+ elif "ToolWithObserver" in nexent_agent .__dict__ :
684+ del nexent_agent .__dict__ ["ToolWithObserver" ]
680685
681686 # Verify observer was set on the tool instance
682687 assert result .observer == nexent_agent_instance .observer
0 commit comments