MCPcopy
hub / github.com/langroid/langroid / test_llm_structured_output_nested

Function test_llm_structured_output_nested

tests/main/test_structured_output.py:139–160  ·  view source on GitHub ↗

Test whether LLM is able to GENERATE nested structured output.

(
    test_settings: Settings,
    use_functions_api: bool,
)

Source from the content-addressed store, hash-verified

137
138@pytest.mark.parametrize("use_functions_api", [False, True])
139def test_llm_structured_output_nested(
140 test_settings: Settings,
141 use_functions_api: bool,
142):
143 """
144 Test whether LLM is able to GENERATE nested structured output.
145 """
146 set_global(test_settings)
147 agent = ChatAgent(strict_cfg)
148 agent.config.use_functions_api = use_functions_api
149 agent.config.use_tools = not use_functions_api
150 agent.config.use_tools_api = True
151 agent.enable_message(PresidentTool)
152 country = "France"
153 prompt = f"""
154 Show me an example of a President of {country}.
155 Make sure you use the `{PresidentTool.name()}`
156 correctly with ALL the required fields!
157 """
158 llm_msg = agent.llm_response_forget(prompt)
159 assert isinstance(agent.get_tool_messages(llm_msg)[0], PresidentTool)
160 assert country == agent.agent_response(llm_msg).content
161
162
163@pytest.mark.parametrize("instructions", [False, True])

Callers

nothing calls this directly

Calls 7

enable_messageMethod · 0.95
llm_response_forgetMethod · 0.95
get_tool_messagesMethod · 0.95
set_globalFunction · 0.90
ChatAgentClass · 0.90
nameMethod · 0.80
agent_responseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…