test_custom_message_handling() — anthropic-sdk-python Function Reference
Architecture documentation for the test_custom_message_handling() function in test_runners.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD d58be04b_df6f_a0c1_5a21_2cb82fab496e["test_custom_message_handling()"] 6847e1ae_03a4_3e19_19ff_ea808e74d94c["TestSyncRunTools"] d58be04b_df6f_a0c1_5a21_2cb82fab496e -->|defined in| 6847e1ae_03a4_3e19_19ff_ea808e74d94c be8a7f3a_5951_1f73_7331_3ad05c999ecf["_get_weather()"] d58be04b_df6f_a0c1_5a21_2cb82fab496e -->|calls| be8a7f3a_5951_1f73_7331_3ad05c999ecf style d58be04b_df6f_a0c1_5a21_2cb82fab496e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/lib/tools/test_runners.py lines 173–222
def test_custom_message_handling(
self, client: Anthropic, respx_mock: MockRouter, monkeypatch: pytest.MonkeyPatch
) -> None:
@beta_tool
def get_weather(location: str, units: Literal["c", "f"]) -> BetaFunctionToolResultType:
"""Lookup the weather for a given city in either celsius or fahrenheit
Args:
location: The city and state, e.g. San Francisco, CA
units: Unit for the output, either 'c' for celsius or 'f' for fahrenheit
Returns:
A dictionary containing the location, temperature, and weather condition.
"""
return json.dumps(_get_weather(location, units))
def custom_message_handling(client: Anthropic) -> BetaMessage:
runner = client.beta.messages.tool_runner(
model="claude-haiku-4-5",
messages=[{"role": "user", "content": "What's the weather in SF in Celsius?"}],
tools=[get_weather],
max_tokens=1024,
)
for message in runner:
# handle only where there is a tool call
if message.content[0].type == "tool_use":
runner.append_messages(
BetaMessageParam(
role="assistant",
content=[
BetaToolResultBlockParam(
tool_use_id=message.content[0].id,
content="The weather in San Francisco, CA is currently sunny with a temperature of 20°C.",
type="tool_result",
)
],
),
)
return runner.until_done()
message = make_snapshot_request(
custom_message_handling,
content_snapshot=snapshots["custom"]["responses"],
path="/v1/messages",
mock_client=client,
respx_mock=respx_mock,
)
assert print_obj(message, monkeypatch) == snapshots["custom"]["result"]
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does test_custom_message_handling() do?
test_custom_message_handling() is a function in the anthropic-sdk-python codebase, defined in tests/lib/tools/test_runners.py.
Where is test_custom_message_handling() defined?
test_custom_message_handling() is defined in tests/lib/tools/test_runners.py at line 173.
What does test_custom_message_handling() call?
test_custom_message_handling() calls 1 function(s): _get_weather.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free