MCPcopy
hub / github.com/langroid/langroid / test_multiple_tools

Function test_multiple_tools

tests/main/test_mcp_tools.py:598–629  ·  view source on GitHub ↗

Test one-shot enabling of multiple tools.

(prompt, tool_name, expected)

Source from the content-addressed store, hash-verified

596)
597@pytest.mark.asyncio
598async def test_multiple_tools(prompt, tool_name, expected) -> None:
599 """
600 Test one-shot enabling of multiple tools.
601 """
602 agent = lr.ChatAgent(
603 lr.ChatAgentConfig(
604 llm=lm.OpenAIGPTConfig(
605 max_output_tokens=1000,
606 async_stream_quiet=False,
607 ),
608 )
609 )
610 all_tools = await get_tools_async(mcp_server())
611
612 tool = next(
613 (t for t in all_tools if t.name() == tool_name),
614 None,
615 )
616 agent.enable_message(all_tools)
617
618 # test that agent (LLM) can pick right tool based on prompt
619 prompt = "use one of your TOOLs to answer this: " + prompt
620 response: lr.ChatDocument = await agent.llm_response_async(prompt)
621 tools = agent.get_tool_messages(response)
622 assert len(tools) == 1
623 assert isinstance(tools[0], lr.ToolMessage)
624 assert isinstance(tools[0], tool)
625
626 # test in a task
627 task = lr.Task(agent, interactive=False)
628 result: lr.ChatDocument = await task.run_async(prompt, turns=3)
629 assert expected in result.content
630
631
632@pytest.mark.skipif(not shutil.which("npx"), reason="npx not available")

Callers

nothing calls this directly

Calls 7

enable_messageMethod · 0.95
llm_response_asyncMethod · 0.95
get_tool_messagesMethod · 0.95
run_asyncMethod · 0.95
get_tools_asyncFunction · 0.90
mcp_serverFunction · 0.85
nameMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…