File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -120,7 +120,7 @@ async def run_agent(
120
120
# Build the index once here, and then all tools won't need to rebuild it
121
121
# only build if the a search tool is requested
122
122
if PaperSearch .TOOL_FN_NAME in (settings .agent .tool_names or DEFAULT_TOOL_NAMES ):
123
- await get_directory_index (settings = settings )
123
+ await get_directory_index (settings = settings , build = settings . agent . rebuild_index )
124
124
125
125
if isinstance (agent_type , str ) and agent_type .lower () == FAKE_AGENT_TYPE :
126
126
session , agent_status = await run_fake_agent (
Original file line number Diff line number Diff line change @@ -523,6 +523,14 @@ class AgentSettings(BaseModel):
523
523
)
524
524
index : IndexSettings = Field (default_factory = IndexSettings )
525
525
526
+ rebuild_index : bool = Field (
527
+ default = True ,
528
+ description = (
529
+ "Flag to rebuild the index at the start of agent runners, default is True"
530
+ " for CLI users to ensure all source PDFs are pulled in."
531
+ ),
532
+ )
533
+
526
534
callbacks : Mapping [str , Sequence [Callable [[_EnvironmentState ], Any ]]] = Field (
527
535
default_factory = dict ,
528
536
description = """
Original file line number Diff line number Diff line change @@ -1080,6 +1080,20 @@ async def test_search_pagination(agent_test_settings: Settings) -> None:
1080
1080
), "Second page should match second slice of all results"
1081
1081
1082
1082
1083
+ @pytest .mark .asyncio
1084
+ async def test_empty_index_without_index_rebuild (agent_test_settings : Settings ):
1085
+ """Test that empty index and `rebuild_index=False` lead to a RuntimeError."""
1086
+ agent_test_settings .agent = AgentSettings (index = IndexSettings ()) # empty index
1087
+ agent_test_settings .agent .rebuild_index = False
1088
+ with pytest .raises (RuntimeError , match = r"Index .* was empty, please rebuild it." ):
1089
+ await agent_query (
1090
+ query = "Are COVID-19 vaccines effective?" ,
1091
+ settings = agent_test_settings ,
1092
+ agent_type = FAKE_AGENT_TYPE ,
1093
+ force_index_rebuild = False ,
1094
+ )
1095
+
1096
+
1083
1097
class TestClinicalTrialSearchTool :
1084
1098
@pytest .mark .asyncio
1085
1099
async def test_continuation (self ) -> None :
You can’t perform that action at this time.
0 commit comments