Home / Function/ test_calls_convert_agent_action_to_messages() — langchain Function Reference

test_calls_convert_agent_action_to_messages() — langchain Function Reference

Architecture documentation for the test_calls_convert_agent_action_to_messages() function in test_openai_tools.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  bab45635_a998_b43b_f933_63e6d57f97e6["test_calls_convert_agent_action_to_messages()"]
  e1f67a20_c53c_0c56_caf3_8aba6704bc4c["test_openai_tools.py"]
  bab45635_a998_b43b_f933_63e6d57f97e6 -->|defined in| e1f67a20_c53c_0c56_caf3_8aba6704bc4c
  style bab45635_a998_b43b_f933_63e6d57f97e6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/tests/unit_tests/agents/format_scratchpad/test_openai_tools.py lines 11–111

def test_calls_convert_agent_action_to_messages() -> None:
    additional_kwargs1 = {
        "tool_calls": [
            {
                "id": "call_abcd12345",
                "function": {"arguments": '{"a": 3, "b": 5}', "name": "add"},
                "type": "function",
            },
        ],
    }
    message1 = AIMessage(content="", additional_kwargs=additional_kwargs1)

    actions1 = parse_ai_message_to_openai_tool_action(message1)
    additional_kwargs2 = {
        "tool_calls": [
            {
                "id": "call_abcd54321",
                "function": {"arguments": '{"a": 3, "b": 5}', "name": "subtract"},
                "type": "function",
            },
        ],
    }
    message2 = AIMessage(content="", additional_kwargs=additional_kwargs2)
    actions2 = parse_ai_message_to_openai_tool_action(message2)

    additional_kwargs3 = {
        "tool_calls": [
            {
                "id": "call_abcd67890",
                "function": {"arguments": '{"a": 3, "b": 5}', "name": "multiply"},
                "type": "function",
            },
            {
                "id": "call_abcd09876",
                "function": {"arguments": '{"a": 3, "b": 5}', "name": "divide"},
                "type": "function",
            },
        ],
    }
    message3 = AIMessage(content="", additional_kwargs=additional_kwargs3)
    actions3 = parse_ai_message_to_openai_tool_action(message3)

    message4 = AIMessage(
        content="",
        tool_calls=[
            ToolCall(
                name="exponentiate",
                args={"a": 3, "b": 5},
                id="call_abc02468",
                type="tool_call",
            ),
        ],
    )
    actions4 = parse_ai_message_to_openai_tool_action(message4)

    # for mypy
    assert isinstance(actions1, list)
    assert isinstance(actions2, list)
    assert isinstance(actions3, list)
    assert isinstance(actions4, list)

    intermediate_steps = [
        (actions1[0], "observation1"),
        (actions2[0], "observation2"),
        (actions3[0], "observation3"),
        (actions3[1], "observation4"),
        (actions4[0], "observation4"),
    ]
    expected_messages = [
        message1,
        ToolMessage(
            tool_call_id="call_abcd12345",
            content="observation1",
            additional_kwargs={"name": "add"},
        ),
        message2,
        ToolMessage(
            tool_call_id="call_abcd54321",
            content="observation2",
            additional_kwargs={"name": "subtract"},
        ),

Domain

Subdomains

Frequently Asked Questions

What does test_calls_convert_agent_action_to_messages() do?
test_calls_convert_agent_action_to_messages() is a function in the langchain codebase, defined in libs/langchain/tests/unit_tests/agents/format_scratchpad/test_openai_tools.py.
Where is test_calls_convert_agent_action_to_messages() defined?
test_calls_convert_agent_action_to_messages() is defined in libs/langchain/tests/unit_tests/agents/format_scratchpad/test_openai_tools.py at line 11.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free