Test whether LLM is able to GENERATE message (tool) in required format, and the agent handles the message correctly. Args: test_settings: test settings from conftest.py use_functions_api: whether to use LLM's functions api or not (i.e. use the langroid ToolMe
(
test_settings: Settings,
use_functions_api: bool,
use_tools_api: bool,
message_class: ToolMessage,
prompt: str,
result: str,
)
| 174 | ], |
| 175 | ) |
| 176 | async def test_llm_tool_message( |
| 177 | test_settings: Settings, |
| 178 | use_functions_api: bool, |
| 179 | use_tools_api: bool, |
| 180 | message_class: ToolMessage, |
| 181 | prompt: str, |
| 182 | result: str, |
| 183 | ): |
| 184 | """ |
| 185 | Test whether LLM is able to GENERATE message (tool) in required format, and the |
| 186 | agent handles the message correctly. |
| 187 | Args: |
| 188 | test_settings: test settings from conftest.py |
| 189 | use_functions_api: whether to use LLM's functions api or not |
| 190 | (i.e. use the langroid ToolMessage tools instead). |
| 191 | message_class: the message class (i.e. tool/function) to test |
| 192 | prompt: the prompt to use to induce the LLM to use the tool |
| 193 | result: the expected result from agent handling the tool-message |
| 194 | """ |
| 195 | set_global(test_settings) |
| 196 | agent = MessageHandlingAgent(cfg) |
| 197 | agent.config.use_functions_api = use_functions_api |
| 198 | agent.config.use_tools = use_tools_api |
| 199 | agent.config.use_tools = not use_functions_api |
| 200 | agent.enable_message(FileExistsMessage) |
| 201 | agent.enable_message(PythonVersionMessage) |
| 202 | agent.enable_message(CountryCapitalMessage) |
| 203 | |
| 204 | llm_msg = await agent.llm_response_forget_async(prompt) |
| 205 | assert isinstance(agent.get_tool_messages(llm_msg)[0], message_class) |
| 206 | |
| 207 | agent_result = (await agent.handle_message_async(llm_msg)).content |
| 208 | assert result.lower() in agent_result.lower() |
| 209 | |
| 210 | |
| 211 | @pytest.mark.asyncio |
nothing calls this directly
no test coverage detected
searching dependent graphs…