Home / Function/ test_response_format_in_agent() — langchain Function Reference

test_response_format_in_agent() — langchain Function Reference

Architecture documentation for the test_response_format_in_agent() function in test_chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  b50d2ceb_f542_cf7b_cc20_b4477364c9ed["test_response_format_in_agent()"]
  f27640dd_3870_5548_d153_f9504ae1021f["test_chat_models.py"]
  b50d2ceb_f542_cf7b_cc20_b4477364c9ed -->|defined in| f27640dd_3870_5548_d153_f9504ae1021f
  style b50d2ceb_f542_cf7b_cc20_b4477364c9ed fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/tests/integration_tests/test_chat_models.py lines 744–774

def test_response_format_in_agent() -> None:
    class Weather(BaseModel):
        temperature: float
        units: str

    # no tools
    agent = create_agent(
        "anthropic:claude-sonnet-4-5", response_format=ProviderStrategy(Weather)
    )
    result = agent.invoke({"messages": [{"role": "user", "content": "75 degrees F."}]})
    assert len(result["messages"]) == 2
    parsed = json.loads(result["messages"][-1].text)
    assert Weather(**parsed) == result["structured_response"]

    # with tools
    def get_weather(location: str) -> str:
        """Get the weather at a location."""
        return "75 degrees Fahrenheit."

    agent = create_agent(
        "anthropic:claude-sonnet-4-5",
        tools=[get_weather],
        response_format=ProviderStrategy(Weather),
    )
    result = agent.invoke(
        {"messages": [{"role": "user", "content": "What's the weather in SF?"}]},
    )
    assert len(result["messages"]) == 4
    assert result["messages"][1].tool_calls
    parsed = json.loads(result["messages"][-1].text)
    assert Weather(**parsed) == result["structured_response"]

Domain

Subdomains

Frequently Asked Questions

What does test_response_format_in_agent() do?
test_response_format_in_agent() is a function in the langchain codebase, defined in libs/partners/anthropic/tests/integration_tests/test_chat_models.py.
Where is test_response_format_in_agent() defined?
test_response_format_in_agent() is defined in libs/partners/anthropic/tests/integration_tests/test_chat_models.py at line 744.

Analyze Your Own Codebase

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

Try Supermodel Free