Skip to content

Commit a07b1b9

Browse files
authored
Exposing environment on-reset hook for Docs preparation (#1003)
1 parent 75c3a25 commit a07b1b9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

paperqa/agents/env.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,13 @@ def make_tools(self) -> list[Tool]:
235235
embedding_model=self._embedding_model,
236236
)
237237

238-
def make_initial_state(self) -> EnvironmentState:
238+
async def _reset_docs(self) -> None:
239+
"""Hook to reset the docs when creating the initial state."""
240+
self._docs.clear_docs()
241+
242+
async def make_initial_state(self) -> EnvironmentState:
243+
await self._reset_docs()
244+
239245
status_fn = None
240246

241247
if ClinicalTrialsSearch.TOOL_FN_NAME in (
@@ -264,8 +270,7 @@ async def reset(self) -> tuple[list[Message], list[Tool]]:
264270
# NOTE: don't build the index here, as sometimes we asyncio.gather over this
265271
# method, and our current design (as of v5.0.10) could hit race conditions
266272
# because index building does not use file locks
267-
self._docs.clear_docs()
268-
self.state, self.tools = self.make_initial_state(), self.make_tools()
273+
self.state, self.tools = (await self.make_initial_state()), self.make_tools()
269274
return (
270275
[
271276
Message(

0 commit comments

Comments
 (0)