Test one-shot enabling of multiple tools.
(prompt, tool_name, expected)
| 596 | ) |
| 597 | @pytest.mark.asyncio |
| 598 | async 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") |
nothing calls this directly
no test coverage detected
searching dependent graphs…