lionagi 0.18.0__py3-none-any.whl → 0.18.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lionagi/_errors.py +0 -5
 - lionagi/fields.py +83 -0
 - lionagi/ln/__init__.py +3 -1
 - lionagi/ln/concurrency/primitives.py +4 -4
 - lionagi/ln/concurrency/task.py +1 -0
 - lionagi/models/field_model.py +12 -4
 - lionagi/models/hashable_model.py +2 -3
 - lionagi/operations/ReAct/ReAct.py +1 -1
 - lionagi/operations/act/act.py +3 -3
 - lionagi/operations/builder.py +5 -7
 - lionagi/operations/fields.py +380 -0
 - lionagi/operations/flow.py +4 -6
 - lionagi/operations/node.py +4 -4
 - lionagi/operations/operate/operate.py +9 -7
 - lionagi/{protocols/operatives → operations/operate}/operative.py +4 -5
 - lionagi/{protocols/operatives → operations/operate}/step.py +34 -39
 - lionagi/operations/select/select.py +1 -1
 - lionagi/operations/select/utils.py +7 -1
 - lionagi/operations/types.py +1 -1
 - lionagi/protocols/action/manager.py +5 -6
 - lionagi/protocols/contracts.py +2 -2
 - lionagi/protocols/generic/__init__.py +22 -0
 - lionagi/protocols/generic/element.py +36 -127
 - lionagi/protocols/generic/pile.py +9 -10
 - lionagi/protocols/generic/progression.py +23 -22
 - lionagi/protocols/graph/edge.py +6 -5
 - lionagi/protocols/ids.py +6 -49
 - lionagi/protocols/messages/__init__.py +3 -1
 - lionagi/protocols/messages/base.py +7 -6
 - lionagi/protocols/messages/instruction.py +0 -1
 - lionagi/protocols/types.py +1 -11
 - lionagi/service/connections/__init__.py +3 -0
 - lionagi/service/connections/providers/claude_code_cli.py +3 -2
 - lionagi/service/hooks/_types.py +1 -1
 - lionagi/service/hooks/_utils.py +1 -1
 - lionagi/service/hooks/hook_event.py +3 -8
 - lionagi/service/hooks/hook_registry.py +5 -5
 - lionagi/service/hooks/hooked_event.py +61 -1
 - lionagi/service/imodel.py +24 -20
 - lionagi/service/third_party/claude_code.py +1 -2
 - lionagi/service/third_party/openai_models.py +24 -22
 - lionagi/service/token_calculator.py +1 -94
 - lionagi/session/branch.py +26 -228
 - lionagi/session/session.py +5 -90
 - lionagi/version.py +1 -1
 - {lionagi-0.18.0.dist-info → lionagi-0.18.1.dist-info}/METADATA +6 -5
 - {lionagi-0.18.0.dist-info → lionagi-0.18.1.dist-info}/RECORD +49 -76
 - lionagi/fields/__init__.py +0 -47
 - lionagi/fields/action.py +0 -188
 - lionagi/fields/base.py +0 -153
 - lionagi/fields/code.py +0 -239
 - lionagi/fields/file.py +0 -234
 - lionagi/fields/instruct.py +0 -135
 - lionagi/fields/reason.py +0 -55
 - lionagi/fields/research.py +0 -52
 - lionagi/operations/brainstorm/__init__.py +0 -2
 - lionagi/operations/brainstorm/brainstorm.py +0 -498
 - lionagi/operations/brainstorm/prompt.py +0 -11
 - lionagi/operations/instruct/__init__.py +0 -2
 - lionagi/operations/instruct/instruct.py +0 -28
 - lionagi/operations/plan/__init__.py +0 -6
 - lionagi/operations/plan/plan.py +0 -386
 - lionagi/operations/plan/prompt.py +0 -25
 - lionagi/operations/utils.py +0 -45
 - lionagi/protocols/forms/__init__.py +0 -2
 - lionagi/protocols/forms/base.py +0 -85
 - lionagi/protocols/forms/flow.py +0 -79
 - lionagi/protocols/forms/form.py +0 -86
 - lionagi/protocols/forms/report.py +0 -48
 - lionagi/protocols/mail/__init__.py +0 -2
 - lionagi/protocols/mail/exchange.py +0 -220
 - lionagi/protocols/mail/mail.py +0 -51
 - lionagi/protocols/mail/mailbox.py +0 -103
 - lionagi/protocols/mail/manager.py +0 -218
 - lionagi/protocols/mail/package.py +0 -101
 - lionagi/protocols/operatives/__init__.py +0 -2
 - {lionagi-0.18.0.dist-info → lionagi-0.18.1.dist-info}/WHEEL +0 -0
 - {lionagi-0.18.0.dist-info → lionagi-0.18.1.dist-info}/licenses/LICENSE +0 -0
 
| 
         @@ -16,6 +16,7 @@ from collections.abc import ( 
     | 
|
| 
       16 
16 
     | 
    
         
             
            from functools import wraps
         
     | 
| 
       17 
17 
     | 
    
         
             
            from pathlib import Path
         
     | 
| 
       18 
18 
     | 
    
         
             
            from typing import TYPE_CHECKING, Any, ClassVar, Generic, Literal, TypeVar
         
     | 
| 
      
 19 
     | 
    
         
            +
            from uuid import UUID
         
     | 
| 
       19 
20 
     | 
    
         | 
| 
       20 
21 
     | 
    
         
             
            from pydantic import Field, field_serializer
         
     | 
| 
       21 
22 
     | 
    
         
             
            from pydapter import Adaptable, AsyncAdaptable
         
     | 
| 
         @@ -32,7 +33,7 @@ from lionagi.utils import ( 
     | 
|
| 
       32 
33 
     | 
    
         
             
            )
         
     | 
| 
       33 
34 
     | 
    
         | 
| 
       34 
35 
     | 
    
         
             
            from .._concepts import Observable
         
     | 
| 
       35 
     | 
    
         
            -
            from .element import ID, Collective, E, Element,  
     | 
| 
      
 36 
     | 
    
         
            +
            from .element import ID, Collective, E, Element, validate_order
         
     | 
| 
       36 
37 
     | 
    
         
             
            from .progression import Progression
         
     | 
| 
       37 
38 
     | 
    
         | 
| 
       38 
39 
     | 
    
         
             
            if TYPE_CHECKING:
         
     | 
| 
         @@ -112,7 +113,7 @@ def _validate_item_type(value, /) -> set[type[T]] | None: 
     | 
|
| 
       112 
113 
     | 
    
         | 
| 
       113 
114 
     | 
    
         | 
| 
       114 
115 
     | 
    
         
             
            def _validate_progression(
         
     | 
| 
       115 
     | 
    
         
            -
                value: Any, collections: dict[ 
     | 
| 
      
 116 
     | 
    
         
            +
                value: Any, collections: dict[UUID, T], /
         
     | 
| 
       116 
117 
     | 
    
         
             
            ) -> Progression:
         
     | 
| 
       117 
118 
     | 
    
         
             
                if not value:
         
     | 
| 
       118 
119 
     | 
    
         
             
                    return Progression(order=list(collections.keys()))
         
     | 
| 
         @@ -198,7 +199,7 @@ class Pile(Element, Collective[T], Generic[T], Adaptable, AsyncAdaptable): 
     | 
|
| 
       198 
199 
     | 
    
         
             
                    strict_type (bool): Whether to enforce strict type checking
         
     | 
| 
       199 
200 
     | 
    
         
             
                """
         
     | 
| 
       200 
201 
     | 
    
         | 
| 
       201 
     | 
    
         
            -
                collections: dict[ 
     | 
| 
      
 202 
     | 
    
         
            +
                collections: dict[UUID, T] = Field(default_factory=dict)
         
     | 
| 
       202 
203 
     | 
    
         
             
                item_type: set | None = Field(
         
     | 
| 
       203 
204 
     | 
    
         
             
                    default=None,
         
     | 
| 
       204 
205 
     | 
    
         
             
                    description="Set of allowed types for items in the pile.",
         
     | 
| 
         @@ -282,9 +283,7 @@ class Pile(Element, Collective[T], Generic[T], Adaptable, AsyncAdaptable): 
     | 
|
| 
       282 
283 
     | 
    
         
             
                    super().__init__(**data)
         
     | 
| 
       283 
284 
     | 
    
         | 
| 
       284 
285 
     | 
    
         
             
                @field_serializer("collections")
         
     | 
| 
       285 
     | 
    
         
            -
                def _serialize_collections(
         
     | 
| 
       286 
     | 
    
         
            -
                    self, v: dict[IDType, T]
         
     | 
| 
       287 
     | 
    
         
            -
                ) -> list[dict[str, Any]]:
         
     | 
| 
      
 286 
     | 
    
         
            +
                def _serialize_collections(self, v: dict[UUID, T]) -> list[dict[str, Any]]:
         
     | 
| 
       288 
287 
     | 
    
         
             
                    return [i.to_dict() for i in v.values()]
         
     | 
| 
       289 
288 
     | 
    
         | 
| 
       290 
289 
     | 
    
         
             
                @field_serializer("progression")
         
     | 
| 
         @@ -492,7 +491,7 @@ class Pile(Element, Collective[T], Generic[T], Adaptable, AsyncAdaptable): 
     | 
|
| 
       492 
491 
     | 
    
         
             
                    """Get all items in order."""
         
     | 
| 
       493 
492 
     | 
    
         
             
                    return [self.collections[key] for key in self.progression]
         
     | 
| 
       494 
493 
     | 
    
         | 
| 
       495 
     | 
    
         
            -
                def items(self) -> Sequence[tuple[ 
     | 
| 
      
 494 
     | 
    
         
            +
                def items(self) -> Sequence[tuple[UUID, T]]:
         
     | 
| 
       496 
495 
     | 
    
         
             
                    """Get all (ID, item) pairs in order."""
         
     | 
| 
       497 
496 
     | 
    
         
             
                    return [(key, self.collections[key]) for key in self.progression]
         
     | 
| 
       498 
497 
     | 
    
         | 
| 
         @@ -797,7 +796,7 @@ class Pile(Element, Collective[T], Generic[T], Adaptable, AsyncAdaptable): 
     | 
|
| 
       797 
796 
     | 
    
         
             
                        except Exception as e:
         
     | 
| 
       798 
797 
     | 
    
         
             
                            raise ItemNotFoundError(f"index {key}. Error: {e}")
         
     | 
| 
       799 
798 
     | 
    
         | 
| 
       800 
     | 
    
         
            -
                    elif isinstance(key,  
     | 
| 
      
 799 
     | 
    
         
            +
                    elif isinstance(key, UUID):
         
     | 
| 
       801 
800 
     | 
    
         
             
                        try:
         
     | 
| 
       802 
801 
     | 
    
         
             
                            return self.collections[key]
         
     | 
| 
       803 
802 
     | 
    
         
             
                        except Exception as e:
         
     | 
| 
         @@ -904,7 +903,7 @@ class Pile(Element, Collective[T], Generic[T], Adaptable, AsyncAdaptable): 
     | 
|
| 
       904 
903 
     | 
    
         
             
                    if isinstance(key, int | slice):
         
     | 
| 
       905 
904 
     | 
    
         
             
                        try:
         
     | 
| 
       906 
905 
     | 
    
         
             
                            pops = self.progression[key]
         
     | 
| 
       907 
     | 
    
         
            -
                            pops = [pops] if isinstance(pops,  
     | 
| 
      
 906 
     | 
    
         
            +
                            pops = [pops] if isinstance(pops, UUID) else pops
         
     | 
| 
       908 
907 
     | 
    
         
             
                            result = []
         
     | 
| 
       909 
908 
     | 
    
         
             
                            for i in pops:
         
     | 
| 
       910 
909 
     | 
    
         
             
                                self.progression.remove(i)
         
     | 
| 
         @@ -1196,7 +1195,7 @@ def to_list_type(value: Any, /) -> list[Any]: 
     | 
|
| 
       1196 
1195 
     | 
    
         
             
                """Convert input to a list format"""
         
     | 
| 
       1197 
1196 
     | 
    
         
             
                if value is None:
         
     | 
| 
       1198 
1197 
     | 
    
         
             
                    return []
         
     | 
| 
       1199 
     | 
    
         
            -
                if isinstance(value,  
     | 
| 
      
 1198 
     | 
    
         
            +
                if isinstance(value, UUID):
         
     | 
| 
       1200 
1199 
     | 
    
         
             
                    return [value]
         
     | 
| 
       1201 
1200 
     | 
    
         
             
                if isinstance(value, str):
         
     | 
| 
       1202 
1201 
     | 
    
         
             
                    return ID.get_id(value) if ID.is_id(value) else []
         
     | 
| 
         @@ -4,6 +4,7 @@ 
     | 
|
| 
       4 
4 
     | 
    
         
             
            from __future__ import annotations
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            from typing import Any, Generic, TypeVar
         
     | 
| 
      
 7 
     | 
    
         
            +
            from uuid import UUID
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
       8 
9 
     | 
    
         
             
            from pydantic import Field, field_serializer, field_validator
         
     | 
| 
       9 
10 
     | 
    
         
             
            from typing_extensions import Self
         
     | 
| 
         @@ -11,7 +12,7 @@ from typing_extensions import Self 
     | 
|
| 
       11 
12 
     | 
    
         
             
            from lionagi._errors import ItemNotFoundError
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
       13 
14 
     | 
    
         
             
            from .._concepts import Ordering
         
     | 
| 
       14 
     | 
    
         
            -
            from .element import ID, Element,  
     | 
| 
      
 15 
     | 
    
         
            +
            from .element import ID, Element, validate_order
         
     | 
| 
       15 
16 
     | 
    
         | 
| 
       16 
17 
     | 
    
         
             
            T = TypeVar("T", bound=Element)
         
     | 
| 
       17 
18 
     | 
    
         | 
| 
         @@ -26,7 +27,7 @@ class Progression(Element, Ordering[T], Generic[T]): 
     | 
|
| 
       26 
27 
     | 
    
         
             
                """Tracks an ordered sequence of item IDs, with optional naming.
         
     | 
| 
       27 
28 
     | 
    
         | 
| 
       28 
29 
     | 
    
         
             
                This class extends `Element` and implements `Ordering`, providing
         
     | 
| 
       29 
     | 
    
         
            -
                list-like operations for managing item IDs (based on ` 
     | 
| 
      
 30 
     | 
    
         
            +
                list-like operations for managing item IDs (based on `UUID`). It
         
     | 
| 
       30 
31 
     | 
    
         
             
                supports insertion, removal, slicing, and more. Items are stored in
         
     | 
| 
       31 
32 
     | 
    
         
             
                `order`, which is a simple list of IDs, and an optional `name`
         
     | 
| 
       32 
33 
     | 
    
         
             
                attribute can be assigned for identification.
         
     | 
| 
         @@ -50,23 +51,23 @@ class Progression(Element, Ordering[T], Generic[T]): 
     | 
|
| 
       50 
51 
     | 
    
         
             
                )
         
     | 
| 
       51 
52 
     | 
    
         | 
| 
       52 
53 
     | 
    
         
             
                @field_validator("order", mode="before")
         
     | 
| 
       53 
     | 
    
         
            -
                def _validate_ordering(cls, value: Any) -> list[ 
     | 
| 
       54 
     | 
    
         
            -
                    """Ensures `order` is a valid list of  
     | 
| 
      
 54 
     | 
    
         
            +
                def _validate_ordering(cls, value: Any) -> list[UUID]:
         
     | 
| 
      
 55 
     | 
    
         
            +
                    """Ensures `order` is a valid list of UUIDs.
         
     | 
| 
       55 
56 
     | 
    
         | 
| 
       56 
57 
     | 
    
         
             
                    Args:
         
     | 
| 
       57 
58 
     | 
    
         
             
                        value (Any): Input sequence (could be elements, IDs, etc.).
         
     | 
| 
       58 
59 
     | 
    
         | 
| 
       59 
60 
     | 
    
         
             
                    Returns:
         
     | 
| 
       60 
     | 
    
         
            -
                        list[ 
     | 
| 
      
 61 
     | 
    
         
            +
                        list[UUID]: The list of validated UUID objects.
         
     | 
| 
       61 
62 
     | 
    
         
             
                    """
         
     | 
| 
       62 
63 
     | 
    
         
             
                    return validate_order(value)
         
     | 
| 
       63 
64 
     | 
    
         | 
| 
       64 
65 
     | 
    
         
             
                @field_serializer("order")
         
     | 
| 
       65 
     | 
    
         
            -
                def _serialize_order(self, value: list[ 
     | 
| 
      
 66 
     | 
    
         
            +
                def _serialize_order(self, value: list[UUID]) -> list[str]:
         
     | 
| 
       66 
67 
     | 
    
         
             
                    """Serializes IDs in `order` to string form.
         
     | 
| 
       67 
68 
     | 
    
         | 
| 
       68 
69 
     | 
    
         
             
                    Args:
         
     | 
| 
       69 
     | 
    
         
            -
                        value (list[ 
     | 
| 
      
 70 
     | 
    
         
            +
                        value (list[UUID]): The order list of ID objects.
         
     | 
| 
       70 
71 
     | 
    
         | 
| 
       71 
72 
     | 
    
         
             
                    Returns:
         
     | 
| 
       72 
73 
     | 
    
         
             
                        list[str]: A list of stringified IDs.
         
     | 
| 
         @@ -85,7 +86,7 @@ class Progression(Element, Ordering[T], Generic[T]): 
     | 
|
| 
       85 
86 
     | 
    
         
             
                    """Checks if one or more IDs exist in the progression.
         
     | 
| 
       86 
87 
     | 
    
         | 
| 
       87 
88 
     | 
    
         
             
                    Args:
         
     | 
| 
       88 
     | 
    
         
            -
                        item (Any): Could be an `Element`, ` 
     | 
| 
      
 89 
     | 
    
         
            +
                        item (Any): Could be an `Element`, `UUID`, `UUID`, string,
         
     | 
| 
       89 
90 
     | 
    
         
             
                            or a sequence of these.
         
     | 
| 
       90 
91 
     | 
    
         | 
| 
       91 
92 
     | 
    
         
             
                    Returns:
         
     | 
| 
         @@ -98,14 +99,14 @@ class Progression(Element, Ordering[T], Generic[T]): 
     | 
|
| 
       98 
99 
     | 
    
         
             
                    except Exception:
         
     | 
| 
       99 
100 
     | 
    
         
             
                        return False
         
     | 
| 
       100 
101 
     | 
    
         | 
| 
       101 
     | 
    
         
            -
                def __getitem__(self, key: int | slice) ->  
     | 
| 
      
 102 
     | 
    
         
            +
                def __getitem__(self, key: int | slice) -> UUID | list[UUID]:
         
     | 
| 
       102 
103 
     | 
    
         
             
                    """Gets one or more items by index or slice.
         
     | 
| 
       103 
104 
     | 
    
         | 
| 
       104 
105 
     | 
    
         
             
                    Args:
         
     | 
| 
       105 
106 
     | 
    
         
             
                        key (int | slice): The index or slice.
         
     | 
| 
       106 
107 
     | 
    
         | 
| 
       107 
108 
     | 
    
         
             
                    Returns:
         
     | 
| 
       108 
     | 
    
         
            -
                         
     | 
| 
      
 109 
     | 
    
         
            +
                        UUID | list[UUID]:
         
     | 
| 
       109 
110 
     | 
    
         
             
                            A single ID if `key` is an int; a new `Progression`
         
     | 
| 
       110 
111 
     | 
    
         
             
                            if `key` is a slice.
         
     | 
| 
       111 
112 
     | 
    
         | 
| 
         @@ -164,15 +165,15 @@ class Progression(Element, Ordering[T], Generic[T]): 
     | 
|
| 
       164 
165 
     | 
    
         
             
                    """Iterates over the IDs in this progression.
         
     | 
| 
       165 
166 
     | 
    
         | 
| 
       166 
167 
     | 
    
         
             
                    Returns:
         
     | 
| 
       167 
     | 
    
         
            -
                        Iterator[ 
     | 
| 
      
 168 
     | 
    
         
            +
                        Iterator[UUID]: An iterator over the ID elements.
         
     | 
| 
       168 
169 
     | 
    
         
             
                    """
         
     | 
| 
       169 
170 
     | 
    
         
             
                    return iter(self.order)
         
     | 
| 
       170 
171 
     | 
    
         | 
| 
       171 
     | 
    
         
            -
                def __next__(self) ->  
     | 
| 
      
 172 
     | 
    
         
            +
                def __next__(self) -> UUID:
         
     | 
| 
       172 
173 
     | 
    
         
             
                    """Returns the next item if used as an iterator.
         
     | 
| 
       173 
174 
     | 
    
         | 
| 
       174 
175 
     | 
    
         
             
                    Returns:
         
     | 
| 
       175 
     | 
    
         
            -
                         
     | 
| 
      
 176 
     | 
    
         
            +
                        UUID: The next item in the iteration.
         
     | 
| 
       176 
177 
     | 
    
         | 
| 
       177 
178 
     | 
    
         
             
                    Raises:
         
     | 
| 
       178 
179 
     | 
    
         
             
                        StopIteration: If there are no more items.
         
     | 
| 
         @@ -182,11 +183,11 @@ class Progression(Element, Ordering[T], Generic[T]): 
     | 
|
| 
       182 
183 
     | 
    
         
             
                    except StopIteration:
         
     | 
| 
       183 
184 
     | 
    
         
             
                        raise StopIteration("No more items in the progression")
         
     | 
| 
       184 
185 
     | 
    
         | 
| 
       185 
     | 
    
         
            -
                def __list__(self) -> list[ 
     | 
| 
      
 186 
     | 
    
         
            +
                def __list__(self) -> list[UUID]:
         
     | 
| 
       186 
187 
     | 
    
         
             
                    """Returns a copy of all IDs in the progression.
         
     | 
| 
       187 
188 
     | 
    
         | 
| 
       188 
189 
     | 
    
         
             
                    Returns:
         
     | 
| 
       189 
     | 
    
         
            -
                        list[ 
     | 
| 
      
 190 
     | 
    
         
            +
                        list[UUID]: A shallow copy of the ID list.
         
     | 
| 
       190 
191 
     | 
    
         
             
                    """
         
     | 
| 
       191 
192 
     | 
    
         
             
                    return self.order[:]
         
     | 
| 
       192 
193 
     | 
    
         | 
| 
         @@ -256,7 +257,7 @@ class Progression(Element, Ordering[T], Generic[T]): 
     | 
|
| 
       256 
257 
     | 
    
         
             
                    refs = validate_order(item)
         
     | 
| 
       257 
258 
     | 
    
         
             
                    self.order.extend(refs)
         
     | 
| 
       258 
259 
     | 
    
         | 
| 
       259 
     | 
    
         
            -
                def pop(self, index: int = -1) ->  
     | 
| 
      
 260 
     | 
    
         
            +
                def pop(self, index: int = -1) -> UUID:
         
     | 
| 
       260 
261 
     | 
    
         
             
                    """Removes and returns one ID by index.
         
     | 
| 
       261 
262 
     | 
    
         | 
| 
       262 
263 
     | 
    
         
             
                    Args:
         
     | 
| 
         @@ -264,7 +265,7 @@ class Progression(Element, Ordering[T], Generic[T]): 
     | 
|
| 
       264 
265 
     | 
    
         
             
                            Position of the item to pop (default is the last item).
         
     | 
| 
       265 
266 
     | 
    
         | 
| 
       266 
267 
     | 
    
         
             
                    Returns:
         
     | 
| 
       267 
     | 
    
         
            -
                         
     | 
| 
      
 268 
     | 
    
         
            +
                        UUID: The removed ID.
         
     | 
| 
       268 
269 
     | 
    
         | 
| 
       269 
270 
     | 
    
         
             
                    Raises:
         
     | 
| 
       270 
271 
     | 
    
         
             
                        ItemNotFoundError: If the index is invalid or out of range.
         
     | 
| 
         @@ -274,11 +275,11 @@ class Progression(Element, Ordering[T], Generic[T]): 
     | 
|
| 
       274 
275 
     | 
    
         
             
                    except Exception as e:
         
     | 
| 
       275 
276 
     | 
    
         
             
                        raise ItemNotFoundError(str(e)) from e
         
     | 
| 
       276 
277 
     | 
    
         | 
| 
       277 
     | 
    
         
            -
                def popleft(self) ->  
     | 
| 
      
 278 
     | 
    
         
            +
                def popleft(self) -> UUID:
         
     | 
| 
       278 
279 
     | 
    
         
             
                    """Removes and returns the first ID.
         
     | 
| 
       279 
280 
     | 
    
         | 
| 
       280 
281 
     | 
    
         
             
                    Returns:
         
     | 
| 
       281 
     | 
    
         
            -
                         
     | 
| 
      
 282 
     | 
    
         
            +
                        UUID: The ID at the front of the progression.
         
     | 
| 
       282 
283 
     | 
    
         | 
| 
       283 
284 
     | 
    
         
             
                    Raises:
         
     | 
| 
       284 
285 
     | 
    
         
             
                        ItemNotFoundError: If the progression is empty.
         
     | 
| 
         @@ -300,9 +301,9 @@ class Progression(Element, Ordering[T], Generic[T]): 
     | 
|
| 
       300 
301 
     | 
    
         
             
                    """
         
     | 
| 
       301 
302 
     | 
    
         
             
                    try:
         
     | 
| 
       302 
303 
     | 
    
         
             
                        refs = validate_order(item)
         
     | 
| 
       303 
     | 
    
         
            -
                    except  
     | 
| 
       304 
     | 
    
         
            -
                         
     | 
| 
       305 
     | 
    
         
            -
             
     | 
| 
      
 304 
     | 
    
         
            +
                    except ValueError as e:
         
     | 
| 
      
 305 
     | 
    
         
            +
                        # Invalid UUID strings are treated as not found
         
     | 
| 
      
 306 
     | 
    
         
            +
                        raise ItemNotFoundError(str(item)) from e
         
     | 
| 
       306 
307 
     | 
    
         
             
                    if not refs:
         
     | 
| 
       307 
308 
     | 
    
         
             
                        return
         
     | 
| 
       308 
309 
     | 
    
         
             
                    missing = [r for r in refs if r not in self.order]
         
     | 
    
        lionagi/protocols/graph/edge.py
    CHANGED
    
    | 
         @@ -2,6 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            # SPDX-License-Identifier: Apache-2.0
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            from typing import Any
         
     | 
| 
      
 5 
     | 
    
         
            +
            from uuid import UUID
         
     | 
| 
       5 
6 
     | 
    
         | 
| 
       6 
7 
     | 
    
         
             
            from pydantic import (
         
     | 
| 
       7 
8 
     | 
    
         
             
                BaseModel,
         
     | 
| 
         @@ -14,7 +15,7 @@ from pydantic import ( 
     | 
|
| 
       14 
15 
     | 
    
         
             
            from lionagi.utils import is_same_dtype
         
     | 
| 
       15 
16 
     | 
    
         | 
| 
       16 
17 
     | 
    
         
             
            from .._concepts import Condition, Relational
         
     | 
| 
       17 
     | 
    
         
            -
            from ..generic.element import ID, Element 
     | 
| 
      
 18 
     | 
    
         
            +
            from ..generic.element import ID, Element
         
     | 
| 
       18 
19 
     | 
    
         | 
| 
       19 
20 
     | 
    
         
             
            __all__ = (
         
     | 
| 
       20 
21 
     | 
    
         
             
                "EdgeCondition",
         
     | 
| 
         @@ -51,8 +52,8 @@ class Edge(Element): 
     | 
|
| 
       51 
52 
     | 
    
         
             
                metadata, etc., may be stored in `properties`.
         
     | 
| 
       52 
53 
     | 
    
         
             
                """
         
     | 
| 
       53 
54 
     | 
    
         | 
| 
       54 
     | 
    
         
            -
                head:  
     | 
| 
       55 
     | 
    
         
            -
                tail:  
     | 
| 
      
 55 
     | 
    
         
            +
                head: UUID
         
     | 
| 
      
 56 
     | 
    
         
            +
                tail: UUID
         
     | 
| 
       56 
57 
     | 
    
         
             
                properties: dict[str, Any] = Field(
         
     | 
| 
       57 
58 
     | 
    
         
             
                    default_factory=dict,
         
     | 
| 
       58 
59 
     | 
    
         
             
                    title="Properties",
         
     | 
| 
         @@ -106,11 +107,11 @@ class Edge(Element): 
     | 
|
| 
       106 
107 
     | 
    
         
             
                    super().__init__(head=head, tail=tail, properties=kwargs)
         
     | 
| 
       107 
108 
     | 
    
         | 
| 
       108 
109 
     | 
    
         
             
                @field_serializer("head", "tail")
         
     | 
| 
       109 
     | 
    
         
            -
                def _serialize_id(self, value:  
     | 
| 
      
 110 
     | 
    
         
            +
                def _serialize_id(self, value: UUID) -> str:
         
     | 
| 
       110 
111 
     | 
    
         
             
                    return str(value)
         
     | 
| 
       111 
112 
     | 
    
         | 
| 
       112 
113 
     | 
    
         
             
                @field_validator("head", "tail", mode="before")
         
     | 
| 
       113 
     | 
    
         
            -
                def _validate_id(cls, value: str) ->  
     | 
| 
      
 114 
     | 
    
         
            +
                def _validate_id(cls, value: str) -> UUID:
         
     | 
| 
       114 
115 
     | 
    
         
             
                    return ID.get_id(value)
         
     | 
| 
       115 
116 
     | 
    
         | 
| 
       116 
117 
     | 
    
         
             
                @property
         
     | 
    
        lionagi/protocols/ids.py
    CHANGED
    
    | 
         @@ -3,7 +3,7 @@ 
     | 
|
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            """ID bridge utilities for V0/V1 compatibility.
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
            This module provides utilities to convert between V0's  
     | 
| 
      
 6 
     | 
    
         
            +
            This module provides utilities to convert between V0's UUID and V1's
         
     | 
| 
       7 
7 
     | 
    
         
             
            canonical UUID representation, enabling seamless interoperability during
         
     | 
| 
       8 
8 
     | 
    
         
             
            the gradual evolution process.
         
     | 
| 
       9 
9 
     | 
    
         
             
            """
         
     | 
| 
         @@ -13,7 +13,7 @@ from __future__ import annotations 
     | 
|
| 
       13 
13 
     | 
    
         
             
            from typing import Any
         
     | 
| 
       14 
14 
     | 
    
         
             
            from uuid import UUID
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
            from .generic.element import  
     | 
| 
      
 16 
     | 
    
         
            +
            from .generic.element import ID, Element
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
            __all__ = (
         
     | 
| 
       19 
19 
     | 
    
         
             
                "to_uuid",
         
     | 
| 
         @@ -22,60 +22,17 @@ __all__ = ( 
     | 
|
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
            def to_uuid(value: Any) -> UUID:
         
     | 
| 
       25 
     | 
    
         
            -
                """Convert ID-like values ( 
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                Optimized version that avoids string conversion when possible by directly
         
     | 
| 
       28 
     | 
    
         
            -
                accessing IDType's internal UUID. Falls back to V0's IDType.validate()
         
     | 
| 
       29 
     | 
    
         
            -
                for validation semantics only when necessary.
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                Args:
         
     | 
| 
       32 
     | 
    
         
            -
                    value: An ID-like value to convert (IDType, UUID, str, or Element)
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                Returns:
         
     | 
| 
       35 
     | 
    
         
            -
                    UUID: A validated UUIDv4
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                Raises:
         
     | 
| 
       38 
     | 
    
         
            -
                    IDError: If the value cannot be converted to a valid UUIDv4
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                Examples:
         
     | 
| 
       41 
     | 
    
         
            -
                    >>> element = Element()
         
     | 
| 
       42 
     | 
    
         
            -
                    >>> uuid_val = to_uuid(element)
         
     | 
| 
       43 
     | 
    
         
            -
                    >>> isinstance(uuid_val, UUID)
         
     | 
| 
       44 
     | 
    
         
            -
                    True
         
     | 
| 
       45 
     | 
    
         
            -
                    >>> to_uuid("550e8400-e29b-41d4-a716-446655440000")
         
     | 
| 
       46 
     | 
    
         
            -
                    UUID('550e8400-e29b-41d4-a716-446655440000')
         
     | 
| 
       47 
     | 
    
         
            -
                """
         
     | 
| 
      
 25 
     | 
    
         
            +
                """Convert ID-like values (UUID | str | Element) to UUID (v4)."""
         
     | 
| 
       48 
26 
     | 
    
         
             
                if isinstance(value, Element):
         
     | 
| 
       49 
     | 
    
         
            -
                    return value.id 
     | 
| 
      
 27 
     | 
    
         
            +
                    return value.id
         
     | 
| 
       50 
28 
     | 
    
         
             
                if isinstance(value, UUID):
         
     | 
| 
       51 
29 
     | 
    
         
             
                    return value
         
     | 
| 
       52 
30 
     | 
    
         
             
                if hasattr(value, "_id") and isinstance(value._id, UUID):
         
     | 
| 
       53 
31 
     | 
    
         
             
                    return value._id
         
     | 
| 
       54 
     | 
    
         
            -
                 
     | 
| 
       55 
     | 
    
         
            -
                validated_id = IDType.validate(value)
         
     | 
| 
       56 
     | 
    
         
            -
                return validated_id._id
         
     | 
| 
      
 32 
     | 
    
         
            +
                return ID.get_id(value)
         
     | 
| 
       57 
33 
     | 
    
         | 
| 
       58 
34 
     | 
    
         | 
| 
       59 
35 
     | 
    
         
             
            def canonical_id(obj: Any) -> UUID:
         
     | 
| 
       60 
     | 
    
         
            -
                """Accept an Observable-like object or raw ID and return canonical UUID.
         
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
                Safe to use across V0/V1 without changing class definitions. Prefers
         
     | 
| 
       63 
     | 
    
         
            -
                attribute access (.id) but falls back to treating the object as a raw ID.
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
                Args:
         
     | 
| 
       66 
     | 
    
         
            -
                    obj: An Observable object with .id attribute, or a raw ID value
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                Returns:
         
     | 
| 
       69 
     | 
    
         
            -
                    UUID: The canonical UUID representation
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
                Examples:
         
     | 
| 
       72 
     | 
    
         
            -
                    >>> element = Element()
         
     | 
| 
       73 
     | 
    
         
            -
                    >>> uuid_val = canonical_id(element)
         
     | 
| 
       74 
     | 
    
         
            -
                    >>> isinstance(uuid_val, UUID)
         
     | 
| 
       75 
     | 
    
         
            -
                    True
         
     | 
| 
       76 
     | 
    
         
            -
                    >>> canonical_id("550e8400-e29b-41d4-a716-446655440000")
         
     | 
| 
       77 
     | 
    
         
            -
                    UUID('550e8400-e29b-41d4-a716-446655440000')
         
     | 
| 
       78 
     | 
    
         
            -
                """
         
     | 
| 
       79 
     | 
    
         
            -
                # Prefer attribute access; fall back to treating obj as a raw id
         
     | 
| 
      
 36 
     | 
    
         
            +
                """Accept an Observable-like object or raw ID and return canonical UUID."""
         
     | 
| 
       80 
37 
     | 
    
         
             
                id_like = getattr(obj, "id", obj)
         
     | 
| 
       81 
38 
     | 
    
         
             
                return to_uuid(id_like)
         
     | 
| 
         @@ -4,7 +4,7 @@ 
     | 
|
| 
       4 
4 
     | 
    
         
             
            from .action_request import ActionRequest, ActionRequestContent
         
     | 
| 
       5 
5 
     | 
    
         
             
            from .action_response import ActionResponse, ActionResponseContent
         
     | 
| 
       6 
6 
     | 
    
         
             
            from .assistant_response import AssistantResponse, AssistantResponseContent
         
     | 
| 
       7 
     | 
    
         
            -
            from .base import MessageRole
         
     | 
| 
      
 7 
     | 
    
         
            +
            from .base import MESSAGE_FIELDS, MessageRole, SenderRecipient
         
     | 
| 
       8 
8 
     | 
    
         
             
            from .instruction import Instruction, InstructionContent
         
     | 
| 
       9 
9 
     | 
    
         
             
            from .manager import MessageManager
         
     | 
| 
       10 
10 
     | 
    
         
             
            from .message import MessageContent, MessageRole, RoledMessage
         
     | 
| 
         @@ -26,4 +26,6 @@ __all__ = ( 
     | 
|
| 
       26 
26 
     | 
    
         
             
                "SystemContent",
         
     | 
| 
       27 
27 
     | 
    
         
             
                "MessageManager",
         
     | 
| 
       28 
28 
     | 
    
         
             
                "MessageRole",
         
     | 
| 
      
 29 
     | 
    
         
            +
                "SenderRecipient",
         
     | 
| 
      
 30 
     | 
    
         
            +
                "MESSAGE_FIELDS",
         
     | 
| 
       29 
31 
     | 
    
         
             
            )
         
     | 
| 
         @@ -3,8 +3,9 @@ 
     | 
|
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            from enum import Enum
         
     | 
| 
       5 
5 
     | 
    
         
             
            from typing import Any, TypeAlias
         
     | 
| 
      
 6 
     | 
    
         
            +
            from uuid import UUID
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
            from ..generic.element import ID, Element,  
     | 
| 
      
 8 
     | 
    
         
            +
            from ..generic.element import ID, Element, Observable
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
10 
     | 
    
         
             
            __all__ = (
         
     | 
| 
       10 
11 
     | 
    
         
             
                "MessageRole",
         
     | 
| 
         @@ -27,10 +28,10 @@ class MessageRole(str, Enum): 
     | 
|
| 
       27 
28 
     | 
    
         
             
                ACTION = "action"
         
     | 
| 
       28 
29 
     | 
    
         | 
| 
       29 
30 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
            SenderRecipient: TypeAlias =  
     | 
| 
      
 31 
     | 
    
         
            +
            SenderRecipient: TypeAlias = MessageRole | str | UUID
         
     | 
| 
       31 
32 
     | 
    
         
             
            """
         
     | 
| 
       32 
33 
     | 
    
         
             
            A union type indicating that a sender or recipient could be:
         
     | 
| 
       33 
     | 
    
         
            -
            - A  
     | 
| 
      
 34 
     | 
    
         
            +
            - A UUID,
         
     | 
| 
       34 
35 
     | 
    
         
             
            - A string-based role or ID,
         
     | 
| 
       35 
36 
     | 
    
         
             
            - A specific enum role from `MessageRole`.
         
     | 
| 
       36 
37 
     | 
    
         
             
            """
         
     | 
| 
         @@ -69,7 +70,7 @@ def validate_sender_recipient(value: Any, /) -> SenderRecipient: 
     | 
|
| 
       69 
70 
     | 
    
         
             
                if isinstance(value, MessageRole):
         
     | 
| 
       70 
71 
     | 
    
         
             
                    return value
         
     | 
| 
       71 
72 
     | 
    
         | 
| 
       72 
     | 
    
         
            -
                if isinstance(value,  
     | 
| 
      
 73 
     | 
    
         
            +
                if isinstance(value, UUID):
         
     | 
| 
       73 
74 
     | 
    
         
             
                    return value
         
     | 
| 
       74 
75 
     | 
    
         | 
| 
       75 
76 
     | 
    
         
             
                if isinstance(value, Observable):
         
     | 
| 
         @@ -86,7 +87,7 @@ def validate_sender_recipient(value: Any, /) -> SenderRecipient: 
     | 
|
| 
       86 
87 
     | 
    
         
             
                    # Try to parse as ID first, but allow plain strings as fallback
         
     | 
| 
       87 
88 
     | 
    
         
             
                    try:
         
     | 
| 
       88 
89 
     | 
    
         
             
                        return ID.get_id(value)
         
     | 
| 
       89 
     | 
    
         
            -
                    except  
     | 
| 
      
 90 
     | 
    
         
            +
                    except Exception:
         
     | 
| 
       90 
91 
     | 
    
         
             
                        return value
         
     | 
| 
       91 
92 
     | 
    
         | 
| 
       92 
93 
     | 
    
         
             
                raise ValueError("Invalid sender or recipient")
         
     | 
| 
         @@ -98,7 +99,7 @@ def serialize_sender_recipient(value: Any) -> str | None: 
     | 
|
| 
       98 
99 
     | 
    
         
             
                # Check instance types first before enum membership
         
     | 
| 
       99 
100 
     | 
    
         
             
                if isinstance(value, Element):
         
     | 
| 
       100 
101 
     | 
    
         
             
                    return str(value.id)
         
     | 
| 
       101 
     | 
    
         
            -
                if isinstance(value,  
     | 
| 
      
 102 
     | 
    
         
            +
                if isinstance(value, UUID):
         
     | 
| 
       102 
103 
     | 
    
         
             
                    return str(value)
         
     | 
| 
       103 
104 
     | 
    
         
             
                if isinstance(value, MessageRole):
         
     | 
| 
       104 
105 
     | 
    
         
             
                    return value.value
         
     | 
    
        lionagi/protocols/types.py
    CHANGED
    
    | 
         @@ -5,7 +5,7 @@ from ._concepts import Collective, Communicatable, Condition, Manager 
     | 
|
| 
       5 
5 
     | 
    
         
             
            from ._concepts import Observable as LegacyObservable
         
     | 
| 
       6 
6 
     | 
    
         
             
            from ._concepts import Observer, Ordering, Relational, Sendable
         
     | 
| 
       7 
7 
     | 
    
         
             
            from .contracts import Observable, ObservableProto
         
     | 
| 
       8 
     | 
    
         
            -
            from .generic.element import ID, Element,  
     | 
| 
      
 8 
     | 
    
         
            +
            from .generic.element import ID, Element, validate_order
         
     | 
| 
       9 
9 
     | 
    
         
             
            from .generic.event import Event, EventStatus, Execution
         
     | 
| 
       10 
10 
     | 
    
         
             
            from .generic.log import (
         
     | 
| 
       11 
11 
     | 
    
         
             
                DataLogger,
         
     | 
| 
         @@ -20,8 +20,6 @@ from .generic.progression import Progression, prog 
     | 
|
| 
       20 
20 
     | 
    
         
             
            from .graph.edge import EdgeCondition
         
     | 
| 
       21 
21 
     | 
    
         
             
            from .graph.graph import Edge, Graph, Node
         
     | 
| 
       22 
22 
     | 
    
         
             
            from .ids import canonical_id, to_uuid
         
     | 
| 
       23 
     | 
    
         
            -
            from .mail.exchange import Exchange, Mail, Mailbox, Package, PackageCategory
         
     | 
| 
       24 
     | 
    
         
            -
            from .mail.manager import MailManager
         
     | 
| 
       25 
23 
     | 
    
         
             
            from .messages.base import (
         
     | 
| 
       26 
24 
     | 
    
         
             
                MESSAGE_FIELDS,
         
     | 
| 
       27 
25 
     | 
    
         
             
                MessageField,
         
     | 
| 
         @@ -55,8 +53,6 @@ __all__ = ( 
     | 
|
| 
       55 
53 
     | 
    
         
             
                "to_uuid",  # ID conversion utility
         
     | 
| 
       56 
54 
     | 
    
         
             
                "ID",
         
     | 
| 
       57 
55 
     | 
    
         
             
                "Element",
         
     | 
| 
       58 
     | 
    
         
            -
                "IDError",
         
     | 
| 
       59 
     | 
    
         
            -
                "IDType",
         
     | 
| 
       60 
56 
     | 
    
         
             
                "validate_order",
         
     | 
| 
       61 
57 
     | 
    
         
             
                "Event",
         
     | 
| 
       62 
58 
     | 
    
         
             
                "EventStatus",
         
     | 
| 
         @@ -74,11 +70,6 @@ __all__ = ( 
     | 
|
| 
       74 
70 
     | 
    
         
             
                "Edge",
         
     | 
| 
       75 
71 
     | 
    
         
             
                "Graph",
         
     | 
| 
       76 
72 
     | 
    
         
             
                "Node",
         
     | 
| 
       77 
     | 
    
         
            -
                "Exchange",
         
     | 
| 
       78 
     | 
    
         
            -
                "Mail",
         
     | 
| 
       79 
     | 
    
         
            -
                "Mailbox",
         
     | 
| 
       80 
     | 
    
         
            -
                "Package",
         
     | 
| 
       81 
     | 
    
         
            -
                "PackageCategory",
         
     | 
| 
       82 
73 
     | 
    
         
             
                "MESSAGE_FIELDS",
         
     | 
| 
       83 
74 
     | 
    
         
             
                "MessageField",
         
     | 
| 
       84 
75 
     | 
    
         
             
                "MessageRole",
         
     | 
| 
         @@ -91,7 +82,6 @@ __all__ = ( 
     | 
|
| 
       91 
82 
     | 
    
         
             
                "RoledMessage",
         
     | 
| 
       92 
83 
     | 
    
         
             
                "SenderRecipient",
         
     | 
| 
       93 
84 
     | 
    
         
             
                "System",
         
     | 
| 
       94 
     | 
    
         
            -
                "MailManager",
         
     | 
| 
       95 
85 
     | 
    
         
             
                "DataLogger",
         
     | 
| 
       96 
86 
     | 
    
         
             
                "DataLoggerConfig",
         
     | 
| 
       97 
87 
     | 
    
         
             
            )
         
     | 
| 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Copyright (c) 2023-2025, HaiyangLi <quantocean.li at gmail dot com>
         
     | 
| 
       2 
2 
     | 
    
         
             
            # SPDX-License-Identifier: Apache-2.0
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
      
 4 
     | 
    
         
            +
            from .api_calling import APICalling
         
     | 
| 
       4 
5 
     | 
    
         
             
            from .endpoint import Endpoint
         
     | 
| 
       5 
6 
     | 
    
         
             
            from .endpoint_config import EndpointConfig
         
     | 
| 
       6 
7 
     | 
    
         
             
            from .header_factory import HeaderFactory
         
     | 
| 
         @@ -11,4 +12,6 @@ __all__ = ( 
     | 
|
| 
       11 
12 
     | 
    
         
             
                "EndpointConfig",
         
     | 
| 
       12 
13 
     | 
    
         
             
                "HeaderFactory",
         
     | 
| 
       13 
14 
     | 
    
         
             
                "match_endpoint",
         
     | 
| 
      
 15 
     | 
    
         
            +
                "APICalling",
         
     | 
| 
      
 16 
     | 
    
         
            +
                "match_endpoint",
         
     | 
| 
       14 
17 
     | 
    
         
             
            )
         
     | 
| 
         @@ -84,8 +84,9 @@ class ClaudeCodeCLIEndpoint(Endpoint): 
     | 
|
| 
       84 
84 
     | 
    
         
             
                async def stream(
         
     | 
| 
       85 
85 
     | 
    
         
             
                    self, request: dict | BaseModel, **kwargs
         
     | 
| 
       86 
86 
     | 
    
         
             
                ) -> AsyncIterator[ClaudeChunk | dict | ClaudeSession]:
         
     | 
| 
       87 
     | 
    
         
            -
                    payload, _ = self.create_payload(request, **kwargs) 
     | 
| 
       88 
     | 
    
         
            -
                     
     | 
| 
      
 87 
     | 
    
         
            +
                    payload, _ = self.create_payload(request, **kwargs)
         
     | 
| 
      
 88 
     | 
    
         
            +
                    request_obj = payload["request"]
         
     | 
| 
      
 89 
     | 
    
         
            +
                    async for chunk in stream_claude_code_cli(request_obj):
         
     | 
| 
       89 
90 
     | 
    
         
             
                        yield chunk
         
     | 
| 
       90 
91 
     | 
    
         | 
| 
       91 
92 
     | 
    
         
             
                async def _call(
         
     | 
    
        lionagi/service/hooks/_types.py
    CHANGED
    
    
    
        lionagi/service/hooks/_utils.py
    CHANGED
    
    
| 
         @@ -3,7 +3,7 @@ 
     | 
|
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            from __future__ import annotations
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
            from typing import  
     | 
| 
      
 6 
     | 
    
         
            +
            from typing import Any
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
            import anyio
         
     | 
| 
       9 
9 
     | 
    
         
             
            from pydantic import Field, PrivateAttr, field_validator
         
     | 
| 
         @@ -12,19 +12,14 @@ from lionagi.ln.concurrency import fail_after, get_cancelled_exc_class 
     | 
|
| 
       12 
12 
     | 
    
         
             
            from lionagi.protocols.types import Event, EventStatus
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
            from ._types import AssosiatedEventInfo, HookEventTypes
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
            if TYPE_CHECKING:
         
     | 
| 
       17 
     | 
    
         
            -
                from .hook_registry import HookRegistry
         
     | 
| 
       18 
     | 
    
         
            -
            else:
         
     | 
| 
       19 
     | 
    
         
            -
                # Import at runtime for Pydantic
         
     | 
| 
       20 
     | 
    
         
            -
                from .hook_registry import HookRegistry
         
     | 
| 
      
 15 
     | 
    
         
            +
            from .hook_registry import HookRegistry
         
     | 
| 
       21 
16 
     | 
    
         | 
| 
       22 
17 
     | 
    
         | 
| 
       23 
18 
     | 
    
         
             
            class HookEvent(Event):
         
     | 
| 
       24 
19 
     | 
    
         
             
                registry: HookRegistry = Field(..., exclude=True)
         
     | 
| 
       25 
20 
     | 
    
         
             
                hook_type: HookEventTypes
         
     | 
| 
       26 
21 
     | 
    
         
             
                exit: bool = Field(False, exclude=True)
         
     | 
| 
       27 
     | 
    
         
            -
                timeout: int = Field(30, exclude=True)
         
     | 
| 
      
 22 
     | 
    
         
            +
                timeout: int | float = Field(30, exclude=True)
         
     | 
| 
       28 
23 
     | 
    
         
             
                params: dict[str, Any] = Field(default_factory=dict, exclude=True)
         
     | 
| 
       29 
24 
     | 
    
         
             
                event_like: Event | type[Event] = Field(..., exclude=True)
         
     | 
| 
       30 
25 
     | 
    
         
             
                _should_exit: bool = PrivateAttr(False)
         
     | 
| 
         @@ -6,8 +6,8 @@ from __future__ import annotations 
     | 
|
| 
       6 
6 
     | 
    
         
             
            from typing import Any, TypeVar
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
            from lionagi.ln.concurrency import get_cancelled_exc_class
         
     | 
| 
      
 9 
     | 
    
         
            +
            from lionagi.ln.types import Undefined
         
     | 
| 
       9 
10 
     | 
    
         
             
            from lionagi.protocols.types import Event, EventStatus
         
     | 
| 
       10 
     | 
    
         
            -
            from lionagi.utils import UNDEFINED
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
            from ._types import HookDict, HookEventTypes, StreamHandlers
         
     | 
| 
       13 
13 
     | 
    
         
             
            from ._utils import get_handler, validate_hooks, validate_stream_handlers
         
     | 
| 
         @@ -99,7 +99,7 @@ class HookRegistry: 
     | 
|
| 
       99 
99 
     | 
    
         
             
                        )
         
     | 
| 
       100 
100 
     | 
    
         
             
                        return (res, False, EventStatus.COMPLETED)
         
     | 
| 
       101 
101 
     | 
    
         
             
                    except get_cancelled_exc_class() as e:
         
     | 
| 
       102 
     | 
    
         
            -
                        return (( 
     | 
| 
      
 102 
     | 
    
         
            +
                        return ((Undefined, e), True, EventStatus.CANCELLED)
         
     | 
| 
       103 
103 
     | 
    
         
             
                    except Exception as e:
         
     | 
| 
       104 
104 
     | 
    
         
             
                        return (e, exit, EventStatus.CANCELLED)
         
     | 
| 
       105 
105 
     | 
    
         | 
| 
         @@ -125,7 +125,7 @@ class HookRegistry: 
     | 
|
| 
       125 
125 
     | 
    
         
             
                        )
         
     | 
| 
       126 
126 
     | 
    
         
             
                        return (res, False, EventStatus.COMPLETED)
         
     | 
| 
       127 
127 
     | 
    
         
             
                    except get_cancelled_exc_class() as e:
         
     | 
| 
       128 
     | 
    
         
            -
                        return (( 
     | 
| 
      
 128 
     | 
    
         
            +
                        return ((Undefined, e), True, EventStatus.CANCELLED)
         
     | 
| 
       129 
129 
     | 
    
         
             
                    except Exception as e:
         
     | 
| 
       130 
130 
     | 
    
         
             
                        return (e, exit, EventStatus.CANCELLED)
         
     | 
| 
       131 
131 
     | 
    
         | 
| 
         @@ -147,7 +147,7 @@ class HookRegistry: 
     | 
|
| 
       147 
147 
     | 
    
         
             
                        )
         
     | 
| 
       148 
148 
     | 
    
         
             
                        return (res, False, EventStatus.COMPLETED)
         
     | 
| 
       149 
149 
     | 
    
         
             
                    except get_cancelled_exc_class() as e:
         
     | 
| 
       150 
     | 
    
         
            -
                        return (( 
     | 
| 
      
 150 
     | 
    
         
            +
                        return ((Undefined, e), True, EventStatus.CANCELLED)
         
     | 
| 
       151 
151 
     | 
    
         
             
                    except Exception as e:
         
     | 
| 
       152 
152 
     | 
    
         
             
                        return (e, exit, EventStatus.ABORTED)
         
     | 
| 
       153 
153 
     | 
    
         | 
| 
         @@ -171,7 +171,7 @@ class HookRegistry: 
     | 
|
| 
       171 
171 
     | 
    
         
             
                        )
         
     | 
| 
       172 
172 
     | 
    
         
             
                        return (res, False, None)
         
     | 
| 
       173 
173 
     | 
    
         
             
                    except get_cancelled_exc_class() as e:
         
     | 
| 
       174 
     | 
    
         
            -
                        return (( 
     | 
| 
      
 174 
     | 
    
         
            +
                        return ((Undefined, e), True, EventStatus.CANCELLED)
         
     | 
| 
       175 
175 
     | 
    
         
             
                    except Exception as e:
         
     | 
| 
       176 
176 
     | 
    
         
             
                        return (e, exit, EventStatus.ABORTED)
         
     | 
| 
       177 
177 
     | 
    
         |