4646# --- agents sub-modules (short absolute imports in factory code)
4747mock_agent_template_cls = Mock ()
4848mock_mcp_config_cls = Mock ()
49+ mock_knowledge_base_config_cls = Mock ()
4950
5051sys .modules .setdefault ("agents" , Mock ()) # parent package stub
5152_mock_agent_template_mod = Mock ()
5758_mock_mcp_config_mod = Mock ()
5859_mock_mcp_config_mod .MCPConfig = mock_mcp_config_cls
5960_mock_mcp_config_mod .VectorStoreConfig = mock_vector_store_config_cls
61+ _mock_mcp_config_mod .KnowledgeBaseConfig = mock_knowledge_base_config_cls
6062sys .modules ["config.mcp_config" ] = _mock_mcp_config_mod
6163
6264# Now import the module under test (full backend.* path as per project convention)
@@ -76,6 +78,8 @@ def _agent_obj(**overrides) -> SimpleNamespace:
7678 coding_tools = False ,
7779 use_toolbox = False ,
7880 use_file_search = False ,
81+ use_knowledge_base = False ,
82+ knowledge_base_name = None ,
7983 user_responses = False ,
8084 vector_store_name = None ,
8185 )
@@ -113,6 +117,7 @@ def setup_method(self):
113117 self .memory_store = Mock ()
114118 mock_agent_template_cls .reset_mock ()
115119 mock_mcp_config_cls .reset_mock ()
120+ mock_knowledge_base_config_cls .reset_mock ()
116121 mock_vector_store_config_cls .reset_mock ()
117122
118123 @pytest .mark .asyncio
@@ -164,6 +169,31 @@ async def test_user_responses_false_no_mcp_config(self):
164169
165170 mock_mcp_config_cls .from_env .assert_not_called ()
166171
172+ @pytest .mark .asyncio
173+ async def test_knowledge_base_agent_appends_no_citations_prompt (self ):
174+ """KB-backed agents receive citation cleanup instructions."""
175+ kb_instance = Mock ()
176+ mock_knowledge_base_config_cls .from_env .return_value = kb_instance
177+ agent_instance = Mock ()
178+ agent_instance .open = AsyncMock ()
179+ mock_agent_template_cls .return_value = agent_instance
180+
181+ await self .factory .create_agent_from_config (
182+ "user123" ,
183+ _agent_obj (
184+ use_knowledge_base = True ,
185+ knowledge_base_name = "test-kb" ,
186+ system_message = "Use retrieved facts." ,
187+ ),
188+ self .team_config ,
189+ self .memory_store ,
190+ )
191+
192+ mock_knowledge_base_config_cls .from_env .assert_called_once_with ("test-kb" )
193+ instructions = mock_agent_template_cls .call_args [1 ]["agent_instructions" ]
194+ assert "RESPONSE CITATION POLICY" in instructions
195+ assert "Do not include any citation markers" in instructions
196+
167197 @pytest .mark .asyncio
168198 async def test_use_toolbox_takes_priority_over_user_responses (self ):
169199 """use_toolbox=True takes priority; MCPConfig uses the toolbox_filter, not 'user_responses'."""
0 commit comments