Home / Function/ __run__() — anthropic-sdk-python Function Reference

__run__() — anthropic-sdk-python Function Reference

Architecture documentation for the __run__() function in _beta_runner.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  e767db6b_72ea_d60e_0f49_54ac2dd6c0a7["__run__()"]
  e1032e12_8173_7783_f9c6_c9b9260e5366["BaseAsyncToolRunner"]
  e767db6b_72ea_d60e_0f49_54ac2dd6c0a7 -->|defined in| e1032e12_8173_7783_f9c6_c9b9260e5366
  21042fa5_2057_e026_e344_8ecf6abf02cc["_should_stop()"]
  e767db6b_72ea_d60e_0f49_54ac2dd6c0a7 -->|calls| 21042fa5_2057_e026_e344_8ecf6abf02cc
  947ff695_bb6a_d258_a971_760cc41d22a6["_handle_request()"]
  e767db6b_72ea_d60e_0f49_54ac2dd6c0a7 -->|calls| 947ff695_bb6a_d258_a971_760cc41d22a6
  1fdee5f9_923d_e71a_5610_d1556341274b["_get_last_message()"]
  e767db6b_72ea_d60e_0f49_54ac2dd6c0a7 -->|calls| 1fdee5f9_923d_e71a_5610_d1556341274b
  dc62d390_be42_9d71_fa80_f161d7ae3cc8["_check_and_compact()"]
  e767db6b_72ea_d60e_0f49_54ac2dd6c0a7 -->|calls| dc62d390_be42_9d71_fa80_f161d7ae3cc8
  e6eb0ae3_dad5_13a8_e981_1b176438b0fe["generate_tool_call_response()"]
  e767db6b_72ea_d60e_0f49_54ac2dd6c0a7 -->|calls| e6eb0ae3_dad5_13a8_e981_1b176438b0fe
  4970c546_0fad_9c03_1498_9ae6f7952dcf["append_messages()"]
  e767db6b_72ea_d60e_0f49_54ac2dd6c0a7 -->|calls| 4970c546_0fad_9c03_1498_9ae6f7952dcf
  b2a98d76_24b2_7388_d54b_d0f7084fdb5f["_get_last_message()"]
  e767db6b_72ea_d60e_0f49_54ac2dd6c0a7 -->|calls| b2a98d76_24b2_7388_d54b_d0f7084fdb5f
  fc3214ad_dd7a_b1a4_994d_95d55d1f3a68["_check_and_compact()"]
  e767db6b_72ea_d60e_0f49_54ac2dd6c0a7 -->|calls| fc3214ad_dd7a_b1a4_994d_95d55d1f3a68
  style e767db6b_72ea_d60e_0f49_54ac2dd6c0a7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/lib/tools/_beta_runner.py lines 493–513

    async def __run__(self) -> AsyncIterator[RunnerItemT]:
        while not self._should_stop():
            async with self._handle_request() as item:
                yield item
                message = await self._get_last_message()
                assert message is not None

            self._iteration_count += 1

            # If the compaction was performed, skip tool call generation this iteration
            if not await self._check_and_compact():
                response = await self.generate_tool_call_response()
                if response is None:
                    log.debug("Tool call was not requested, exiting from tool runner loop.")
                    return

                if not self._messages_modified:
                    self.append_messages(message, response)

            self._messages_modified = False
            self._cached_tool_call_response = None

Subdomains

Frequently Asked Questions

What does __run__() do?
__run__() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/lib/tools/_beta_runner.py.
Where is __run__() defined?
__run__() is defined in src/anthropic/lib/tools/_beta_runner.py at line 493.
What does __run__() call?
__run__() calls 8 function(s): _check_and_compact, _check_and_compact, _get_last_message, _get_last_message, _handle_request, _should_stop, append_messages, generate_tool_call_response.

Analyze Your Own Codebase

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

Try Supermodel Free