MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / _run_sync_tool_use

Function _run_sync_tool_use

tests/lib/tools/test_runners.py:1018–1039  ·  view source on GitHub ↗

Drive a tool runner over `messages` and collect the tool_result messages it generated.

(
    client: Anthropic,
    *,
    tools: List[Any],
    messages: List[BetaMessageParam],
)

Source from the content-addressed store, hash-verified

1016
1017
1018def _run_sync_tool_use(
1019 client: Anthropic,
1020 *,
1021 tools: List[Any],
1022 messages: List[BetaMessageParam],
1023) -> List[BetaMessageParam]:
1024 """Drive a tool runner over `messages` and collect the tool_result
1025 messages it generated."""
1026 runner = client.beta.messages.tool_runner(
1027 max_tokens=1024,
1028 model="claude-haiku-4-5",
1029 tools=tools,
1030 messages=messages,
1031 # The tests assert on whole request bodies; on a message thread a request carries only the new messages.
1032 thread=False,
1033 )
1034 responses: List[BetaMessageParam] = []
1035 for _ in runner:
1036 response = runner.generate_tool_call_response()
1037 if response is not None:
1038 responses.append(response)
1039 return responses
1040
1041
1042@pytest.mark.skipif(PYDANTIC_V1, reason="tool runner not supported with pydantic v1")

Calls 3

tool_runnerMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected