TestParseAIMessage Class — langchain Architecture
Architecture documentation for the TestParseAIMessage class in test_openai_functions_multi.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 744eb6ed_e970_902c_3b2f_989585354200["TestParseAIMessage"] 21559aaf_24e1_3178_8193_1719e6ef11ba["AgentFinish"] 744eb6ed_e970_902c_3b2f_989585354200 -->|extends| 21559aaf_24e1_3178_8193_1719e6ef11ba 0dd75536_e009_da4d_0090_3d46069fce40["OutputParserException"] 744eb6ed_e970_902c_3b2f_989585354200 -->|extends| 0dd75536_e009_da4d_0090_3d46069fce40 0b380906_8607_9bd2_6c02_00d2a6dc939e["test_openai_functions_multi.py"] 744eb6ed_e970_902c_3b2f_989585354200 -->|defined in| 0b380906_8607_9bd2_6c02_00d2a6dc939e 29d02895_c890_960c_e718_7bbb3452b603["test_not_an_ai()"] 744eb6ed_e970_902c_3b2f_989585354200 -->|method| 29d02895_c890_960c_e718_7bbb3452b603 7f862751_3c88_9471_f358_c879faebfa25["test_model_response()"] 744eb6ed_e970_902c_3b2f_989585354200 -->|method| 7f862751_3c88_9471_f358_c879faebfa25 c69a3e4d_fa4a_7304_56d3_028afc0d8367["test_func_call()"] 744eb6ed_e970_902c_3b2f_989585354200 -->|method| c69a3e4d_fa4a_7304_56d3_028afc0d8367 4535f167_64ff_3f42_c538_6b1be3971d44["test_func_call_oldstyle()"] 744eb6ed_e970_902c_3b2f_989585354200 -->|method| 4535f167_64ff_3f42_c538_6b1be3971d44 7282a82f_e3ca_276a_0b12_02f0944b63b9["test_func_call_invalid()"] 744eb6ed_e970_902c_3b2f_989585354200 -->|method| 7282a82f_e3ca_276a_0b12_02f0944b63b9
Relationship Graph
Source Code
libs/langchain/tests/unit_tests/agents/test_openai_functions_multi.py lines 15–91
class TestParseAIMessage:
# Test: Pass Non-AIMessage.
def test_not_an_ai(self) -> None:
err = f"Expected an AI message got {SystemMessage!s}"
with pytest.raises(TypeError, match=err):
_parse_ai_message(SystemMessage(content="x"))
# Test: Model response (not a function call).
def test_model_response(self) -> None:
msg = AIMessage(content="Model response.")
result = _parse_ai_message(msg)
assert isinstance(result, AgentFinish)
assert result.return_values == {"output": "Model response."}
assert result.log == "Model response."
# Test: Model response with a function call.
def test_func_call(self) -> None:
act = json.dumps([{"action_name": "foo", "action": {"param": 42}}])
msg = AIMessage(
content="LLM thoughts.",
additional_kwargs={
"function_call": {"name": "foo", "arguments": f'{{"actions": {act}}}'},
},
)
result = _parse_ai_message(msg)
assert isinstance(result, list)
assert len(result) == 1
action = result[0]
assert isinstance(action, _FunctionsAgentAction)
assert action.tool == "foo"
assert action.tool_input == {"param": 42}
assert action.log == (
"\nInvoking: `foo` with `{'param': 42}`\nresponded: LLM thoughts.\n\n"
)
assert action.message_log == [msg]
# Test: Model response with a function call (old style tools).
def test_func_call_oldstyle(self) -> None:
act = json.dumps([{"action_name": "foo", "action": {"__arg1": "42"}}])
msg = AIMessage(
content="LLM thoughts.",
additional_kwargs={
"function_call": {"name": "foo", "arguments": f'{{"actions": {act}}}'},
},
)
result = _parse_ai_message(msg)
assert isinstance(result, list)
assert len(result) == 1
action = result[0]
assert isinstance(action, _FunctionsAgentAction)
assert action.tool == "foo"
assert action.tool_input == "42"
assert action.log == (
"\nInvoking: `foo` with `42`\nresponded: LLM thoughts.\n\n"
)
assert action.message_log == [msg]
# Test: Invalid function call args.
def test_func_call_invalid(self) -> None:
msg = AIMessage(
content="LLM thoughts.",
additional_kwargs={"function_call": {"name": "foo", "arguments": "{42]"}},
)
err = (
"Could not parse tool input: {'name': 'foo', 'arguments': '{42]'} "
"because the `arguments` is not valid JSON."
)
with pytest.raises(OutputParserException, match=err):
_parse_ai_message(msg)
Extends
Source
Frequently Asked Questions
What is the TestParseAIMessage class?
TestParseAIMessage is a class in the langchain codebase, defined in libs/langchain/tests/unit_tests/agents/test_openai_functions_multi.py.
Where is TestParseAIMessage defined?
TestParseAIMessage is defined in libs/langchain/tests/unit_tests/agents/test_openai_functions_multi.py at line 15.
What does TestParseAIMessage extend?
TestParseAIMessage extends AgentFinish, OutputParserException.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free