ó
    ýÞ j  ã            
       óÆ   • S r SSKrSSKJrJr  SSKJr  SSKJr  S\S\	4   S\S\
\\	\4      4   4S	 jrS
\S\\	   4   S\S\\
\\	\4         4   4S jrS\S\S\4S jrg)z.Custom tool decorator for OpenAI custom tools.é    N)Ú	AwaitableÚCallable)ÚAny)ÚtoolÚfunc.Úreturnc                 óX   ^ • S[         S[        [        [         [        4      4U 4S jjnU$ )NÚxr   c                 ó   >• ST" U 5      S./$ ©NÚcustom_tool_call_output)ÚtypeÚoutput© )r
   r   s    €Ú\/var/www/html/gaurav/venv/lib/python3.13/site-packages/langchain_openai/tools/custom_tool.pyÚwrappedÚ#_make_wrapped_func.<locals>.wrapped   s   ø€ Ø2¹dÀ1»gÑFÐGÐGó    )ÚstrÚlistÚdictr   )r   r   s   ` r   Ú_make_wrapped_funcr   
   s-   ø€ ðH”3ð Hœ4¤¤S¬# X¡Ñ/÷ Hð €Nr   Ú	coroutinec           	      ód   ^ • S[         S[         S[        [        [        [         4      4U 4S jjnU$ )NÚargsÚkwargsr   c               Ÿ   ó<   >#   • T" U 0 UD6I S h  v•N nSUS./$  N
7fr   r   )r   r   Úresultr   s      €r   r   Ú(_make_wrapped_coroutine.<locals>.wrapped   s+   øé € Ù  $Ð1¨&Ñ1×1ˆØ2¸fÑEÐFÐFñ 2ùs   ƒ��)r   r   r   r   )r   r   s   ` r   Ú_make_wrapped_coroutiner       s5   ø€ ðGœSð G¬Cð G´D¼¼cÄ3¸h¹Ñ4H÷ Gð €Nr   r   r   c                  óš   ^• S[         S[        4   S[        4U4S jjnU (       a%  [        U S   5      (       a  T(       d  U" U S   5      $ U$ )a   Decorator to create an OpenAI custom tool.

Custom tools allow for tools with (potentially long) freeform string inputs.

See below for an example using LangGraph:

```python
@custom_tool
def execute_code(code: str) -> str:
    """Execute python code."""
    return "27"


model = ChatOpenAI(model="gpt-5", output_version="responses/v1")

agent = create_react_agent(model, [execute_code])

input_message = {"role": "user", "content": "Use the tool to calculate 3^3."}
for step in agent.stream(
    {"messages": [input_message]},
    stream_mode="values",
):
    step["messages"][-1].pretty_print()
```

You can also specify a format for a corresponding context-free grammar using the
`format` kwarg:

```python
from langchain_openai import ChatOpenAI, custom_tool
from langgraph.prebuilt import create_react_agent

grammar = """
start: expr
expr: term (SP ADD SP term)* -> add
| term
term: factor (SP MUL SP factor)* -> mul
| factor
factor: INT
SP: " "
ADD: "+"
MUL: "*"
%import common.INT
"""

format = {"type": "grammar", "syntax": "lark", "definition": grammar}

# highlight-next-line
@custom_tool(format=format)
def do_math(input_string: str) -> str:
    """Do a mathematical operation."""
    return "27"


model = ChatOpenAI(model="gpt-5", output_version="responses/v1")

agent = create_react_agent(model, [do_math])

input_message = {"role": "user", "content": "Use the tool to calculate 3^3."}
for step in agent.stream(
    {"messages": [input_message]},
    stream_mode="values",
):
    step["messages"][-1].pretty_print()
```
r   .r   c                 ó  >• SS0nST;   a  TR                  S5      US'   [        SSS0TD6" U 5      nXl        U R                  Ul        [
        R                  " U 5      (       a  [        U 5      Ul        U$ [        U 5      Ul
        U$ )Nr   Úcustom_toolÚformatÚinfer_schemaFr   )Úpopr   ÚmetadataÚ__doc__ÚdescriptionÚinspectÚiscoroutinefunctionr    r   r   r   )r   r'   Útool_objr   s      €r   Ú	decoratorÚcustom_tool.<locals>.decorator_   s‰   ø€ Ø˜MÐ*ˆØ�vÓØ!'§¡¨HÓ!5ˆH�XÑÜÑ5 UÐ5¨fÒ5°dÓ;ˆØ$ÔØ#Ÿ|™|ˆÔÜ×&Ò& t×,Ñ,Ü!8¸Ó!>ˆHÔð ˆô /¨tÓ4ˆHŒMØˆr   r   )r   r   Úcallable)r   r   r-   s    ` r   r#   r#      sJ   ø€ ðHœ ¤c Ñ*ð ¬s÷ ö ”˜˜a™×!Ñ!®&Ù˜˜a™Ó!Ð!àÐr   )r(   r*   Úcollections.abcr   r   Útypingr   Úlangchain_core.toolsr   r   r   r   r   r    r#   r   r   r   Ú<module>r3      s¥   ðÙ 4ã ß /Ý å %ð˜X c¨3 hÑ/ð °H¸SÀ$ÀtÈCÐQTÈHÁ~ÑBVÐ=VÑ4Wô ðØ˜˜Y s™^Ð+Ñ,ðàˆc�9˜T $ s¨C x¡.Ñ1Ñ2Ð2Ñ3ôðT�sð T cð T¨cõ Tr   