Coverage for core/langgraph/_tool_markup.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-09-25 03:05 +0000

1"""Isolated detector for tool calls expressed as assistant-content markup. 

2 

3This detector implements ADR-0041 D3: native function calling is a hard 

4provider requirement, so a tool call expressed as content markup while the 

5native `message.tool_calls` is absent is a hard failure. 

6 

7The raised failure reuses the existing `TOOL_FAILURE` code rather than adding 

8a new one: `TOOL_FAILURE` is already a member of the closed 19-code 

9`ENGINE_ERROR_CODES` set and already listed in `HARD_ERROR_CODES`, so reusing 

10it keeps the producer-owned closed error-code set and its canonical test 

11unchanged. 

12""" 

13from __future__ import annotations 

14 

15TOOL_CALL_MARKUP_SIGNATURES = ( 

16 "<tool_call>", 

17 "</tool_call>", 

18 "<tool_calls>", 

19 "</tool_calls>", 

20 "<function_call>", 

21 "</function_call>", 

22 "<function_calls>", 

23 "</function_calls>", 

24 "<invoke>", 

25 "</invoke>", 

26 "<tool_use>", 

27 "</tool_use>", 

28 "<|tool_call|>", 

29 "<|python_tag|>", 

30 "antml:invoke", 

31 "antml:tool_use", 

32 "antml:function_calls", 

33 "[TOOL_CALLS]", 

34) 

35 

36 

37def contains_tool_call_markup(text: str | None) -> bool: 

38 if text is None: 

39 return False 

40 return any(signature in text for signature in TOOL_CALL_MARKUP_SIGNATURES)