
    MKiQ                    V   S SK Jr  S SKrS SKrS SKrS SKJrJrJr  S SK	J
r
  S SKJrJrJrJrJrJrJr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJrJr  S SKJrJ r   S SK!J"r"  S SK#J$r$  S SK%J&r&J'r'  S SK(J)r)  S SK*J+r+J,r,J-r-J.r.J/r/J0r0  S SK1J2r2  S SK3J4r4J5r5  S SK6J7r7J8r8J9r9J:r:  S SK;J<r<  S SK=J>r>J?r?  Sr@ " S S\\+\-4   5      rA\ S"SSSS.           S#S jjj5       rB\S$S j5       rB\S%S j5       rB S"SSSS.           S&S jjjrB\" S5      rC\" S5      rD " S  S!\\<   5      rEg)'    )annotationsN)	AwaitableCallableSequence)	dataclass)AnyGenericTypeVarcastget_args
get_originoverload)	BaseCache)BaseCheckpointSaver)	BaseStore)Unpack)CACHE_NS_WRITESPREVIOUS)MISSINGDeprecatedKwargs)EphemeralValue)	LastValue)ENDSTART)Pregel)PSyncAsyncFutureTcallget_runnable_for_entrypoint
identifier)
PregelNode)ChannelWriteChannelWriteEntry)
_DC_KWARGSCachePolicyRetryPolicy
StreamMode)ContextT)LangGraphDeprecatedSinceV05LangGraphDeprecatedSinceV10)task
entrypointc                  X    \ rS rSrSSS.         S	S jjrS
S jrSS jrSS jrSrg)_TaskFunction.   N)cache_policynamec                   UbK  [        US5      (       a4  [        R                  " UR                  UR                  5      nXEl        UnOXAl        Xl        X l        X0l        [        R                  " X5        g )N__func__)
hasattr	functoolspartialr4   __self____name__funcretry_policyr1   update_wrapper)selfr:   r;   r1   r2   instance_methods         Y/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/langgraph/func/__init__.py__init___TaskFunction.__init__/   sd     tZ(( #,"3"3DMM4=="Q+/(& !%	((  ,    c                b    [        U R                  /UQ7U R                  U R                  S.UD6$ )N)r;   r1   )r   r:   r;   r1   )r=   argskwargss      r?   __call___TaskFunction.__call__G   sA    II
 	
****

 
 	
rB   c                    U R                   b5  UR                  [        [        U R                  5      =(       d    S445        ggzClear the cache for this task.N__dynamic__)r1   clearr   r!   r:   r=   caches     r?   clear_cache_TaskFunction.clear_cacheP   s5    (KK/:dii+@+QMRTU )rB   c                   #    U R                   b=  UR                  [        [        U R                  5      =(       d    S445      I Sh  vN   gg N7frI   )r1   aclearr   r!   r:   rL   s     r?   aclear_cache_TaskFunction.aclear_cacheU   sJ     (,,!:dii#8#IMJL   )s   AAAA)r1   r:   r;   )
r:   *Callable[P, Awaitable[T]] | Callable[P, T]r;   zSequence[RetryPolicy]r1   ,CachePolicy[Callable[P, str | bytes]] | Noner2   
str | NonereturnNone)rD   zP.argsrE   zP.kwargsrW   zSyncAsyncFuture[T])rM   r   rW   rX   )	r9   
__module____qualname____firstlineno__r@   rF   rN   rR   __static_attributes__ rB   r?   r/   r/   .   sR     FJ-8- ,	-
 C- - 
-0
V
rB   r/   )r2   r;   r1   c                   g Nr]   )__func_or_none__r2   r;   r1   rE   s        r?   r,   r,   ]   s     rB   c                    g r_   r]   r`   s    r?   r,   r,   k   s    NQrB   c                    g r_   r]   rb   s    r?   r,   r,   o   s    CFrB   c                  ^^^ UR                  S[        5      =n[        La  [        R                  " S[        SS9  Uc  UnUc  SO[        U[        5      (       a  U4OUm    SUUU4S jjnU b  U" U 5      $ U$ )a  Define a LangGraph task using the `task` decorator.

!!! important "Requires python 3.11 or higher for async functions"
    The `task` decorator supports both sync and async functions. To use async
    functions, ensure that you are using Python 3.11 or higher.

Tasks can only be called from within an [`entrypoint`][langgraph.func.entrypoint] or
from within a `StateGraph`. A task can be called like a regular function with the
following differences:

- When a checkpointer is enabled, the function inputs and outputs must be serializable.
- The decorated function can only be called from within an entrypoint or `StateGraph`.
- Calling the function produces a future. This makes it easy to parallelize tasks.

Args:
    name: An optional name for the task. If not provided, the function name will be used.
    retry_policy: An optional retry policy (or list of policies) to use for the task in case of a failure.
    cache_policy: An optional cache policy to use for the task. This allows caching of the task results.

Returns:
    A callable function when used as a decorator.

Example: Sync Task
    ```python
    from langgraph.func import entrypoint, task


    @task
    def add_one_task(a: int) -> int:
        return a + 1


    @entrypoint()
    def add_one(numbers: list[int]) -> list[int]:
        futures = [add_one_task(n) for n in numbers]
        results = [f.result() for f in futures]
        return results


    # Call the entrypoint
    add_one.invoke([1, 2, 3])  # Returns [2, 3, 4]
    ```

Example: Async Task
    ```python
    import asyncio
    from langgraph.func import entrypoint, task


    @task
    async def add_one_task(a: int) -> int:
        return a + 1


    @entrypoint()
    async def add_one(numbers: list[int]) -> list[int]:
        futures = [add_one_task(n) for n in numbers]
        return asyncio.gather(*futures)


    # Call the entrypoint
    await add_one.ainvoke([1, 2, 3])  # Returns [2, 3, 4]
    ```
retryM`retry` is deprecated and will be removed. Please use `retry_policy` instead.   category
stacklevelr]   c                   > [        U TTTS9$ )N)r;   r1   r2   )r/   )r:   r1   r2   retry_policiess    r?   	decoratortask.<locals>.decorator   s     ~Lt
 	
rB   )r:   rT   rW   zCallable[P, SyncAsyncFuture[T]])getr   warningswarnr*   
isinstancer'   )r`   r2   r;   r1   rE   re   rm   rl   s    ` `   @r?   r,   r,   s   s    V GW--g=[0	

  L  	 lK00 _ 
8
	(
 
 #)**rB   RSc                      \ rS rSrSr      S	               S
S jjr\" S0 \D6 " S S\\	\
4   5      5       rSS jrSrg)r-      a  Define a LangGraph workflow using the `entrypoint` decorator.

### Function signature

The decorated function must accept a **single parameter**, which serves as the input
to the function. This input parameter can be of any type. Use a dictionary
to pass **multiple parameters** to the function.

### Injectable parameters

The decorated function can request access to additional parameters
that will be injected automatically at run time. These parameters include:

| Parameter        | Description                                                                                          |
|------------------|------------------------------------------------------------------------------------------------------|
| **`config`**     | A configuration object (aka `RunnableConfig`) that holds run-time configuration values.              |
| **`previous`**   | The previous return value for the given thread (available only when a checkpointer is provided).     |
| **`runtime`**    | A `Runtime` object that contains information about the current run, including context, store, writer |

The entrypoint decorator can be applied to sync functions or async functions.

### State management

The **`previous`** parameter can be used to access the return value of the previous
invocation of the entrypoint on the same thread id. This value is only available
when a checkpointer is provided.

If you want **`previous`** to be different from the return value, you can use the
`entrypoint.final` object to return a value while saving a different value to the
checkpoint.

Args:
    checkpointer: Specify a checkpointer to create a workflow that can persist
        its state across runs.
    store: A generalized key-value store. Some implementations may support
        semantic search capabilities through an optional `index` configuration.
    cache: A cache to use for caching the results of the workflow.
    context_schema: Specifies the schema for the context object that will be
        passed to the workflow.
    cache_policy: A cache policy to use for caching the results of the workflow.
    retry_policy: A retry policy (or list of policies) to use for the workflow in case of a failure.

!!! warning "`config_schema` Deprecated"
    The `config_schema` parameter is deprecated in v0.6.0 and support will be removed in v2.0.0.
    Please use `context_schema` instead to specify the schema for run-scoped context.


Example: Using entrypoint and tasks
    ```python
    import time

    from langgraph.func import entrypoint, task
    from langgraph.types import interrupt, Command
    from langgraph.checkpoint.memory import InMemorySaver

    @task
    def compose_essay(topic: str) -> str:
        time.sleep(1.0)  # Simulate slow operation
        return f"An essay about {topic}"

    @entrypoint(checkpointer=InMemorySaver())
    def review_workflow(topic: str) -> dict:
        """Manages the workflow for generating and reviewing an essay.

        The workflow includes:
        1. Generating an essay about the given topic.
        2. Interrupting the workflow for human review of the generated essay.

        Upon resuming the workflow, compose_essay task will not be re-executed
        as its result is cached by the checkpointer.

        Args:
            topic: The subject of the essay.

        Returns:
            dict: A dictionary containing the generated essay and the human review.
        """
        essay_future = compose_essay(topic)
        essay = essay_future.result()
        human_review = interrupt({
            "question": "Please provide a review",
            "essay": essay
        })
        return {
            "essay": essay,
            "review": human_review,
        }

    # Example configuration for the workflow
    config = {
        "configurable": {
            "thread_id": "some_thread"
        }
    }

    # Topic for the essay
    topic = "cats"

    # Stream the workflow to generate the essay and await human review
    for result in review_workflow.stream(topic, config):
        print(result)

    # Example human review provided after the interrupt
    human_review = "This essay is great."

    # Resume the workflow with the provided human review
    for result in review_workflow.stream(Command(resume=human_review), config):
        print(result)
    ```

Example: Accessing the previous return value
    When a checkpointer is enabled the function can access the previous return value
    of the previous invocation on the same thread id.

    ```python
    from typing import Optional

    from langgraph.checkpoint.memory import MemorySaver

    from langgraph.func import entrypoint


    @entrypoint(checkpointer=InMemorySaver())
    def my_workflow(input_data: str, previous: Optional[str] = None) -> str:
        return "world"


    config = {"configurable": {"thread_id": "some_thread"}}
    my_workflow.invoke("hello", config)
    ```

Example: Using `entrypoint.final` to save a value
    The `entrypoint.final` object allows you to return a value while saving
    a different value to the checkpoint. This value will be accessible
    in the next invocation of the entrypoint via the `previous` parameter, as
    long as the same thread id is used.

    ```python
    from typing import Any

    from langgraph.checkpoint.memory import MemorySaver

    from langgraph.func import entrypoint


    @entrypoint(checkpointer=InMemorySaver())
    def my_workflow(
        number: int,
        *,
        previous: Any = None,
    ) -> entrypoint.final[int, int]:
        previous = previous or 0
        # This will return the previous value to the caller, saving
        # 2 * number to the checkpoint, which will be used in the next invocation
        # for the `previous` parameter.
        return entrypoint.final(value=previous, save=2 * number)


    config = {"configurable": {"thread_id": "some_thread"}}

    my_workflow.invoke(3, config)  # 0 (previous was None)
    my_workflow.invoke(1, config)  # 6 (previous was 3 * 2 from the previous invocation)
    ```
Nc                   UR                  S[        5      =n[        La4  [        R                  " S[        SS9  Uc  [        [        [           U5      nUR                  S[        5      =n	[        La)  [        R                  " S[        SS9  Uc  [        SU	5      nXl	        X l
        X0l        XPl        X`l        X@l        g)	z$Initialize the entrypoint decorator.config_schemazW`config_schema` is deprecated and will be removed. Please use `context_schema` instead.rg   rh   Nre   rf   z#RetryPolicy | Sequence[RetryPolicy])ro   r   rp   rq   r+   r   typer)   r*   checkpointerstorerM   r1   r;   context_schema)
r=   rz   r{   rM   r|   r1   r;   rE   rx   re   s
             r?   r@   entrypoint.__init__  s     $ZZAAM'QMMi4
 %!%d8nm!DZZ11E'AMM_4
 ##$I5Q(

((,rB   c                  0    \ rS rSr% SrS\S'    S\S'   Srg)	entrypoint.finali  a  A primitive that can be returned from an entrypoint.

This primitive allows to save a value to the checkpointer distinct from the
return value from the entrypoint.

Example: Decoupling the return value and the save value
    ```python
    from langgraph.checkpoint.memory import InMemorySaver
    from langgraph.func import entrypoint


    @entrypoint(checkpointer=InMemorySaver())
    def my_workflow(
        number: int,
        *,
        previous: Any = None,
    ) -> entrypoint.final[int, int]:
        previous = previous or 0
        # This will return the previous value to the caller, saving
        # 2 * number to the checkpoint, which will be used in the next invocation
        # for the `previous` parameter.
        return entrypoint.final(value=previous, save=2 * number)


    config = {"configurable": {"thread_id": "1"}}

    my_workflow.invoke(3, config)  # 0 (previous was None)
    my_workflow.invoke(1, config)  # 6 (previous was 3 * 2 from the previous invocation)
    ```
rs   valuert   saver]   N)r9   rY   rZ   r[   __doc____annotations__r\   r]   rB   r?   finalr     s    	> T	rB   r   c                h   [         R                  " U5      (       d  [         R                  " U5      (       a  [        S5      e[	        U5      nSn[         R
                  " U5      n[        [        UR                  R                  5       5      S5      nU(       d  [        S5      eUR                  U   R                  [         R                  R                  La  UR                  U   R                  O[        nSS jnSS jn[        [        pUR                  [         R                  R                  La  UR                  [         R"                  L a  [        =pO|[%        UR                  5      nU[         R"                  L aG  ['        UR                  5      n[)        U5      S:w  a  [+        S5      e['        UR                  5      u  pOUR                  =p[-        UR.                  [1        U[2        /[2        [5        [7        [8        US	9[7        [:        US	9/5      /S
90[2        [=        U5      [8        [?        U	[8        5      [:        [?        U
[:        5      0[2        [8        [8        USU R@                  U RB                  U RD                  U RF                  U RH                  =(       d    SU RJ                  S9$ )zConvert a function into a Pregel graph.

Args:
    func: The function to convert. Support both sync and async functions.

Returns:
    A Pregel graph.
z3Generators are not supported in the Functional API.updatesNz4Entrypoint function must have at least one parameterc                \    [        U [        R                  5      (       a  U R                  $ U $ )zEExtract the return_ value the entrypoint.final object or passthrough.)rr   r-   r   r   r   s    r?   _pluck_return_value0entrypoint.__call__.<locals>._pluck_return_value  s#    ",UJ4D4D"E"E5;;P5PrB   c                \    [        U [        R                  5      (       a  U R                  $ U $ )z?Get save value from the entrypoint.final object or passthrough.)rr   r-   r   r   r   s    r?   _pluck_save_value.entrypoint.__call__.<locals>._pluck_save_value  s#    !+E:3C3C!D!D5::O%OrB   rg   zPlease an annotation for both the return_ and the save values.For example, `-> entrypoint.final[int, str]` would assign a return_ a type of `int` and save the type `str`.)mapper)boundtriggerschannelswritersTr]   )nodesr   input_channelsoutput_channelsstream_channelsstream_modestream_eagerrz   r{   rM   r1   r;   r|   )r   r   rW   r   )&inspectisgeneratorfunctionisasyncgenfunctionNotImplementedErrorr    	signaturenextiter
parameterskeys
ValueError
annotation	Signatureemptyr   return_annotationr-   r   r   r   len	TypeErrorr   r9   r"   r   r#   r$   r   r   r   r   rz   r{   rM   r1   r;   r|   )r=   r:   r   r   sigfirst_parameter_name
input_typer   r   output_type	save_typeorigintype_annotationss                r?   rF   entrypoint.__call__  sV    &&t,,0J0J40P0P%E  ,D1"+ %#D)<)<)>$?F#STT ~~23>>$$**+ NN/0;; 	 		Q	P "%cY  (9(9(?(?? %%)9)99*--i#C$9$9:Z---'/0E0E'F$+,1'O  .6c6K6K-L*K.1.C.CCKz#W"$ 1#>Q R 1(CT U	   ~j1Y{C0)Ix8
 !#**********0b..? 
  	
rB   )rM   r1   rz   r|   r;   r{   )NNNNNN)rz   zBaseCheckpointSaver | Noner{   zBaseStore | NonerM   zBaseCache | Noner|   ztype[ContextT] | Noner1   zCachePolicy | Noner;   *RetryPolicy | Sequence[RetryPolicy] | NonerE   Unpack[DeprecatedKwargs]rW   rX   r]   )r:   zCallable[..., Any]rW   r   )r9   rY   rZ   r[   r   r@   r   r%   r	   rs   rt   r   rF   r\   r]   rB   r?   r-   r-      s    cN 48"&"&04+/CG"-0"-  "-  	"-
 ."- )"- A"- +"- 
"-H &1 & &P\
rB   r-   r_   )r`   rX   r2   rV   r;   r   r1   rU   rE   r   rW   zKCallable[[Callable[P, Awaitable[T]] | Callable[P, T]], _TaskFunction[P, T]])r`   zCallable[P, Awaitable[T]]rW   _TaskFunction[P, T])r`   zCallable[P, T]rW   r   )r`   z1Callable[P, Awaitable[T]] | Callable[P, T] | Noner2   rV   r;   r   r1   rU   rE   r   rW   zaCallable[[Callable[P, Awaitable[T]] | Callable[P, T]], _TaskFunction[P, T]] | _TaskFunction[P, T])F
__future__r   r6   r   rp   collections.abcr   r   r   dataclassesr   typingr   r	   r
   r   r   r   r   langgraph.cache.baser   langgraph.checkpoint.baser   langgraph.store.baser   typing_extensionsr   langgraph._internal._constantsr   r   langgraph._internal._typingr   r   "langgraph.channels.ephemeral_valuer   langgraph.channels.last_valuer   langgraph.constantsr   r   langgraph.pregelr   langgraph.pregel._callr   r   r   r   r    r!   langgraph.pregel._readr"   langgraph.pregel._writer#   r$   langgraph.typesr%   r&   r'   r(   langgraph.typingr)   langgraph.warningsr*   r+   __all__r/   r,   rs   rt   r-   r]   rB   r?   <module>r      s   "    9 9 !   + 9 * $ D A = 3 * #  . C L L % W
 ,GAqDM ,^ 
!
 ?CAE

 
 =	

 ?
 '

 

 
 Q 
 Q 
 F 
 F KOf ?CAEfGf f =	f
 ?f 'ffR CLCLO
" O
rB   