MCPcopy
hub / github.com/langroid/langroid / test_retrieval_tool

Function test_retrieval_tool

tests/main/test_doc_chat_agent.py:309–335  ·  view source on GitHub ↗
(
    test_settings: Settings, retrieval_agent, query: str, expected: str
)

Source from the content-addressed store, hash-verified

307 ],
308)
309def test_retrieval_tool(
310 test_settings: Settings, retrieval_agent, query: str, expected: str
311):
312 set_global(test_settings)
313 retrieval_agent.enable_message(RetrievalTool)
314 task = Task(
315 retrieval_agent,
316 restart=True,
317 interactive=False,
318 system_message=f"""
319 To answer user's query, use the `retrieval_tool` to retrieve relevant passages,
320 and ONLY then answer the query.
321 In case the query is simply a topic or search phrase,
322 guess what the user may want to know, and formulate it as a
323 question to be answered, and use this as the `query` field in the
324 `retrieval_tool`.
325
326 When you are ready to show your answer, say {DONE}, followed by the answer.
327 """,
328 )
329 # 3 turns:
330 # 1. LLM gen `retrieval_tool` request
331 # 2. Agent gen `retrieval_tool` response (i.e. returns relevant passages)
332 # 3. LLM gen answer based on passages
333 ans = task.run(query, turns=3).content
334 expected = [e.strip().lower() for e in expected.split(",")]
335 assert all([e in ans.lower() for e in expected])
336
337
338@pytest.fixture(scope="function")

Callers

nothing calls this directly

Calls 5

runMethod · 0.95
set_globalFunction · 0.90
TaskClass · 0.90
enable_messageMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…