lionagi 0.17.6__py3-none-any.whl → 0.17.7__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/__init__.py CHANGED
@@ -5,17 +5,20 @@
5
5
  import logging
6
6
  from typing import TYPE_CHECKING
7
7
 
8
- from . import ln as ln # Lightweight concurrency utilities
8
+ from . import ln as ln
9
9
  from .version import __version__
10
10
 
11
11
  if TYPE_CHECKING:
12
- # Type hints only - not imported at runtime
13
12
  from pydantic import BaseModel, Field
14
13
 
14
+ from . import _types as types
15
+ from .operations.builder import OperationGraphBuilder as Builder
15
16
  from .operations.node import Operation
17
+ from .protocols.action.manager import load_mcp_tools
16
18
  from .service.imodel import iModel
17
19
  from .session.session import Branch, Session
18
20
 
21
+
19
22
  logger = logging.getLogger(__name__)
20
23
  logger.setLevel(logging.INFO)
21
24
 
@@ -1,12 +1,26 @@
1
1
  # Eager imports for core functionality
2
- from .connections.api_calling import APICalling
3
- from .connections.endpoint import Endpoint, EndpointConfig
4
- from .hooks import *
5
- from .imodel import iModel
6
- from .manager import iModelManager
7
- from .rate_limited_processor import RateLimitedAPIExecutor
8
-
9
- # Lazy loading cache
2
+ from typing import TYPE_CHECKING
3
+
4
+ from .hooks import (
5
+ AssosiatedEventInfo,
6
+ HookDict,
7
+ HookedEvent,
8
+ HookEvent,
9
+ HookEventTypes,
10
+ HookRegistry,
11
+ global_hook_logger,
12
+ )
13
+
14
+ if TYPE_CHECKING:
15
+ from .broadcaster import Broadcaster
16
+ from .connections.api_calling import APICalling
17
+ from .connections.endpoint import Endpoint, EndpointConfig
18
+ from .imodel import iModel
19
+ from .manager import iModelManager
20
+ from .rate_limited_processor import RateLimitedAPIExecutor
21
+ from .token_calculator import TokenCalculator
22
+
23
+
10
24
  _lazy_imports = {}
11
25
 
12
26
 
@@ -15,12 +29,49 @@ def __getattr__(name: str):
15
29
  if name in _lazy_imports:
16
30
  return _lazy_imports[name]
17
31
 
32
+ if name == "RateLimitedAPIExecutor":
33
+ from .rate_limited_processor import RateLimitedAPIExecutor
34
+
35
+ _lazy_imports["RateLimitedAPIExecutor"] = RateLimitedAPIExecutor
36
+ return RateLimitedAPIExecutor
37
+
38
+ if name in ("Endpoint", "EndpointConfig"):
39
+ from .connections.endpoint import Endpoint, EndpointConfig
40
+
41
+ _lazy_imports["Endpoint"] = Endpoint
42
+ _lazy_imports["EndpointConfig"] = EndpointConfig
43
+ return Endpoint if name == "Endpoint" else EndpointConfig
44
+
45
+ if name == "iModelManager":
46
+ from .manager import iModelManager
47
+
48
+ _lazy_imports["iModelManager"] = iModelManager
49
+ return iModelManager
50
+
51
+ if name == "iModel":
52
+ from .imodel import iModel
53
+
54
+ _lazy_imports["iModel"] = iModel
55
+ return iModel
56
+
57
+ if name == "APICalling":
58
+ from .connections.api_calling import APICalling
59
+
60
+ _lazy_imports["APICalling"] = APICalling
61
+ return APICalling
62
+
18
63
  if name == "TokenCalculator":
19
64
  from .token_calculator import TokenCalculator
20
65
 
21
66
  _lazy_imports["TokenCalculator"] = TokenCalculator
22
67
  return TokenCalculator
23
68
 
69
+ if name == "Broadcaster":
70
+ from .broadcaster import Broadcaster
71
+
72
+ _lazy_imports["Broadcaster"] = Broadcaster
73
+ return Broadcaster
74
+
24
75
  raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
25
76
 
26
77
 
@@ -37,4 +88,12 @@ __all__ = (
37
88
  "AssosiatedEventInfo",
38
89
  "HookEvent",
39
90
  "HookRegistry",
91
+ "Broadcaster",
92
+ "HookEventTypes",
93
+ "HookDict",
94
+ "AssosiatedEventInfo",
95
+ "HookEvent",
96
+ "HookRegistry",
97
+ "global_hook_logger",
98
+ "HookedEvent",
40
99
  )
@@ -23,8 +23,8 @@ __all__ = (
23
23
 
24
24
  class HookEventTypes(str, Enum):
25
25
  PreEventCreate = "pre_event_create"
26
- PreInvokation = "pre_invokation"
27
- PostInvokation = "post_invokation"
26
+ PreInvocation = "pre_invocation"
27
+ PostInvocation = "post_invocation"
28
28
 
29
29
 
30
30
  ALLOWED_HOOKS_TYPES = HookEventTypes.allowed()
@@ -32,8 +32,8 @@ ALLOWED_HOOKS_TYPES = HookEventTypes.allowed()
32
32
 
33
33
  class HookDict(TypedDict):
34
34
  pre_event_create: Callable | None
35
- pre_invokation: Callable | None
36
- post_invokation: Callable | None
35
+ pre_invocation: Callable | None
36
+ post_invocation: Callable | None
37
37
 
38
38
 
39
39
  StreamHandlers = dict[str, Callable[[SC], Awaitable[None]]]
@@ -102,7 +102,7 @@ class HookRegistry:
102
102
  except Exception as e:
103
103
  return (e, exit, EventStatus.CANCELLED)
104
104
 
105
- async def pre_invokation(
105
+ async def pre_invocation(
106
106
  self, event: E, /, exit: bool = False, **kw
107
107
  ) -> tuple[Any, bool, EventStatus]:
108
108
  """Hook to be called when an event is dequeued and right before it is invoked.
@@ -110,12 +110,12 @@ class HookRegistry:
110
110
  Typically used to check permissions.
111
111
 
112
112
  The hook function takes the content of the event as a dictionary.
113
- It can either raise an exception to abort the event invokation or pass to continue (status: cancelled).
113
+ It can either raise an exception to abort the event invocation or pass to continue (status: cancelled).
114
114
  It cannot modify the event itself, and won't be able to access the event instance.
115
115
  """
116
116
  try:
117
117
  res = await self._call(
118
- HookEventTypes.PreInvokation,
118
+ HookEventTypes.PreInvocation,
119
119
  None,
120
120
  None,
121
121
  event,
@@ -127,16 +127,16 @@ class HookRegistry:
127
127
  except Exception as e:
128
128
  return (e, exit, EventStatus.CANCELLED)
129
129
 
130
- async def post_invokation(
130
+ async def post_invocation(
131
131
  self, event: E, /, exit: bool = False, **kw
132
132
  ) -> tuple[None | Exception, bool, EventStatus, EventStatus]:
133
133
  """Hook to be called right after event finished its execution.
134
- It can either raise an exception to abort the event invokation or pass to continue (status: aborted).
134
+ It can either raise an exception to abort the event invocation or pass to continue (status: aborted).
135
135
  It cannot modify the event itself, and won't be able to access the event instance.
136
136
  """
137
137
  try:
138
138
  res = await self._call(
139
- HookEventTypes.PostInvokation,
139
+ HookEventTypes.PostInvocation,
140
140
  None,
141
141
  None,
142
142
  event,
@@ -156,7 +156,7 @@ class HookRegistry:
156
156
  Typically used for logging or stream event abortion.
157
157
 
158
158
  The handler function signature should be: `async def handler(chunk: Any) -> None`
159
- It can either raise an exception to mark the event invokation as "failed" or pass to continue (status: aborted).
159
+ It can either raise an exception to mark the event invocation as "failed" or pass to continue (status: aborted).
160
160
  """
161
161
  try:
162
162
  res = await self._call_stream_handler(
@@ -196,14 +196,14 @@ class HookRegistry:
196
196
  match hook_type:
197
197
  case HookEventTypes.PreEventCreate:
198
198
  return await self.pre_event_create(event_like, **kw), meta
199
- case HookEventTypes.PreInvokation:
199
+ case HookEventTypes.PreInvocation:
200
200
  meta["event_id"] = str(event_like.id)
201
201
  meta["event_created_at"] = event_like.created_at
202
- return await self.pre_invokation(event_like, **kw), meta
203
- case HookEventTypes.PostInvokation:
202
+ return await self.pre_invocation(event_like, **kw), meta
203
+ case HookEventTypes.PostInvocation:
204
204
  meta["event_id"] = str(event_like.id)
205
205
  meta["event_created_at"] = event_like.created_at
206
- return await self.post_invokation(**kw), meta
206
+ return await self.post_invocation(**kw), meta
207
207
  return await self.handle_streaming_chunk(chunk_type, chunk, exit, **kw)
208
208
 
209
209
  def _can_handle(
@@ -115,7 +115,7 @@ class HookedEvent(Event):
115
115
  hook_params: dict = None,
116
116
  ):
117
117
  h_ev = HookEvent(
118
- hook_type=HookEventTypes.PreInvokation,
118
+ hook_type=HookEventTypes.PreInvocation,
119
119
  event_like=self,
120
120
  registry=hook_registry,
121
121
  exit=exit_hook,
@@ -132,7 +132,7 @@ class HookedEvent(Event):
132
132
  hook_params: dict = None,
133
133
  ):
134
134
  h_ev = HookEvent(
135
- hook_type=HookEventTypes.PostInvokation,
135
+ hook_type=HookEventTypes.PostInvocation,
136
136
  event_like=self,
137
137
  registry=hook_registry,
138
138
  exit=exit_hook,
lionagi/service/imodel.py CHANGED
@@ -11,6 +11,7 @@ from lionagi.ln import is_coro_func, now_utc
11
11
  from lionagi.protocols.generic.log import Log
12
12
  from lionagi.protocols.types import ID, Event, EventStatus, IDType
13
13
  from lionagi.service.hooks.hook_event import HookEventTypes
14
+ from lionagi.service.hooks.hooked_event import HookedEvent
14
15
 
15
16
  from .connections.api_calling import APICalling
16
17
  from .connections.endpoint import Endpoint
@@ -186,8 +187,12 @@ class iModel:
186
187
  "PreEventCreate hook requested exit without a cause"
187
188
  )
188
189
 
189
- if create_event_type is APICalling:
190
- api_call = self.create_api_calling(**kwargs)
190
+ if issubclass(create_event_type, HookedEvent):
191
+ api_call = None
192
+ if create_event_type is APICalling:
193
+ api_call = self.create_api_calling(**kwargs)
194
+ else:
195
+ api_call = create_event_type(**kwargs)
191
196
  if h_ev:
192
197
  h_ev.assosiated_event_info["event_id"] = str(api_call.id)
193
198
  h_ev.assosiated_event_info["event_created_at"] = (
@@ -196,7 +201,7 @@ class iModel:
196
201
  await global_hook_logger.alog(Log(content=h_ev.to_dict()))
197
202
 
198
203
  if self.hook_registry._can_handle(
199
- ht_=HookEventTypes.PreInvokation
204
+ ht_=HookEventTypes.PreInvocation
200
205
  ):
201
206
  api_call.create_pre_invoke_hook(
202
207
  hook_registry=self.hook_registry,
@@ -210,7 +215,7 @@ class iModel:
210
215
  )
211
216
 
212
217
  if self.hook_registry._can_handle(
213
- ht_=HookEventTypes.PostInvokation
218
+ ht_=HookEventTypes.PostInvocation
214
219
  ):
215
220
  api_call.create_post_invoke_hook(
216
221
  hook_registry=self.hook_registry,
lionagi/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.17.6"
1
+ __version__ = "0.17.7"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lionagi
3
- Version: 0.17.6
3
+ Version: 0.17.7
4
4
  Summary: An Intelligence Operating System.
5
5
  Author-email: HaiyangLi <quantocean.li@gmail.com>
6
6
  License: Apache License
@@ -1,11 +1,11 @@
1
- lionagi/__init__.py,sha256=MeFKg1esCCVXzKG_ZSS68dg-q2W26sVzRSju_prw37w,2398
1
+ lionagi/__init__.py,sha256=iS8Y4ZSsP2EPwEsqeodelqdoL1BdiK1bCAYJHak1AUM,2474
2
2
  lionagi/_class_registry.py,sha256=pfUO1DjFZIqr3OwnNMkFqL_fiEBrrf8-swkGmP_KDLE,3112
3
3
  lionagi/_errors.py,sha256=ia_VWhPSyr5FIJLSdPpl04SrNOLI2skN40VC8ePmzeQ,3748
4
4
  lionagi/_types.py,sha256=COWRrmstmABGKKn-h_cKiAREGsMp_Ik49OdR4lSS3P8,1263
5
5
  lionagi/config.py,sha256=yGnzj5D14B2TBhqVeyp1uccvAK6mk4hm0QA8dAEJUeQ,4776
6
6
  lionagi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  lionagi/utils.py,sha256=yRHKN_v9xRnUa-nYg1lTpCCK2wNDg4pCpicUEIyFwKg,7084
8
- lionagi/version.py,sha256=mmrB6n6zH1c3iHQ4iJcecY24GV6KoBQ8Vbb5t5vYe3E,23
8
+ lionagi/version.py,sha256=_9A_jQb7KUl9K8At8l-nfzMi9odK4IQSyRft9V3xoYs,23
9
9
  lionagi/adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  lionagi/adapters/_utils.py,sha256=sniMG1LDDkwJNzUF2K32jv7rA6Y1QcohgyNclYsptzI,453
11
11
  lionagi/adapters/async_postgres_adapter.py,sha256=2XlxYNPow78dFHIQs8W1oJ2zkVD5Udn3aynMBF9Nf3k,3498
@@ -146,9 +146,9 @@ lionagi/protocols/messages/templates/tool_schemas.jinja2,sha256=ozIaSDCRjIAhLyA8
146
146
  lionagi/protocols/operatives/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
147
147
  lionagi/protocols/operatives/operative.py,sha256=V7SvjQf9nT9GT3Ft36atrBSOKLfylGvwS2oeykbTCfk,13368
148
148
  lionagi/protocols/operatives/step.py,sha256=uF92QO2KZiY3YR1cxhrbD844VFidOKfmeQn2Fv637iY,9280
149
- lionagi/service/__init__.py,sha256=qcscXOKVQtDDQ7YV-_D9jcIABDkGaxAEsCKsBBtf4XE,992
149
+ lionagi/service/__init__.py,sha256=MYcfEFFLSdRS4blwYdx883T8Px2bn81JAeqSIPW9SFs,2545
150
150
  lionagi/service/broadcaster.py,sha256=XvaUaBb6awcq-DJGVNJnnAIZUrrtOPnhWcgVgZTnGq8,1941
151
- lionagi/service/imodel.py,sha256=kdoV3X_hwZ-PuHCtE3vDP-nfHr6pp-A4ilo_gwmDcaA,16386
151
+ lionagi/service/imodel.py,sha256=k-G7dowF7JOyy5qoXLgq9wjW5DYTe-pI4Gjf4nTOj7w,16609
152
152
  lionagi/service/manager.py,sha256=tN3p0kM7pg_CEs6wXK62_B_h49Q3nrU-9qniFhw2ABE,1164
153
153
  lionagi/service/rate_limited_processor.py,sha256=h2_F71aVeBrgZ0a7ARS8-8NDaAHvfWrLykI5QcNuYbk,6099
154
154
  lionagi/service/resilience.py,sha256=91RPFtQY4QyNga_nuSNLsbzNE26pXJMTAfLaQqVdvmg,18714
@@ -172,11 +172,11 @@ lionagi/service/connections/providers/ollama_.py,sha256=oqYLWn81KrWoQgId4e4GD_bg
172
172
  lionagi/service/connections/providers/perplexity_.py,sha256=1GMmxAXsKGsB-xlqxO6hW-QdqoqkU2705NLyejetFSw,1646
173
173
  lionagi/service/connections/providers/types.py,sha256=omKWbmJYu_ozK_qJLcxQezVcauXTqhp4ClOWAyENEFU,807
174
174
  lionagi/service/hooks/__init__.py,sha256=WCfzc-Aco5PkKufDMvSYxbrLqlEvmOsaZELlWKAuG2w,464
175
- lionagi/service/hooks/_types.py,sha256=piByW73lJ9sSfPFOO9NWhQ9aogyDBS6936jvvVXqMZw,1255
175
+ lionagi/service/hooks/_types.py,sha256=e1vmA24arGKweS45jEXK6pw8Ysk2NOvlBc6m1ABsKws,1255
176
176
  lionagi/service/hooks/_utils.py,sha256=51dqdRrln2aJCkCz8g4L6Ik_v9atdFHPzjm9ASu6OvA,2560
177
177
  lionagi/service/hooks/hook_event.py,sha256=NH3PdoWwAt96GQQi99TjqAu-zU-zTgWz6pDdIaKureE,2418
178
- lionagi/service/hooks/hook_registry.py,sha256=IEJF3UpLCmTXkd-7daFIo_p0CVTuAoA6Z8gzXkMIGsg,7870
179
- lionagi/service/hooks/hooked_event.py,sha256=GBM-d8OdSoB59pmmH7oFyO-bLxpJjzKuJLpVKgKLNkM,4339
178
+ lionagi/service/hooks/hook_registry.py,sha256=S6wYKKSHTUKRDN2P1opHKisdaYOXnttVIWYoMIlB_6c,7870
179
+ lionagi/service/hooks/hooked_event.py,sha256=D_1HtWCH3CriNlmsksi5lerXuF_LV2lbktcEdhZqXw0,4339
180
180
  lionagi/service/third_party/README.md,sha256=qFjWnI8rmLivIyr6Tc-hRZh-rQwntROp76af4MBNJJc,2214
181
181
  lionagi/service/third_party/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
182
182
  lionagi/service/third_party/anthropic_models.py,sha256=oqSPSlcayYG-fS5BLiLeTtkrpaxgkPhEK_YgneumrOo,4004
@@ -193,7 +193,7 @@ lionagi/tools/base.py,sha256=hEGnE4MD0CM4UqnF0xsDRKB0aM-pyrTFHl8utHhyJLU,1897
193
193
  lionagi/tools/types.py,sha256=XtJLY0m-Yi_ZLWhm0KycayvqMCZd--HxfQ0x9vFUYDE,230
194
194
  lionagi/tools/file/__init__.py,sha256=5y5joOZzfFWERl75auAcNcKC3lImVJ5ZZGvvHZUFCJM,112
195
195
  lionagi/tools/file/reader.py,sha256=Q9x1UP7YmBqN53e1kUN68OmIs-D1m9EM9VVbWfM35js,9658
196
- lionagi-0.17.6.dist-info/METADATA,sha256=yH4RA6fcmW5nqU8Y4rbA7OIUsdUfRJEU_cly2QsMj1U,23448
197
- lionagi-0.17.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
198
- lionagi-0.17.6.dist-info/licenses/LICENSE,sha256=VXFWsdoN5AAknBCgFqQNgPWYx7OPp-PFEP961zGdOjc,11288
199
- lionagi-0.17.6.dist-info/RECORD,,
196
+ lionagi-0.17.7.dist-info/METADATA,sha256=RVhAS_0eXRZlzmyY3smI143cFOMZLge0KuLP-QsT-z0,23448
197
+ lionagi-0.17.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
198
+ lionagi-0.17.7.dist-info/licenses/LICENSE,sha256=VXFWsdoN5AAknBCgFqQNgPWYx7OPp-PFEP961zGdOjc,11288
199
+ lionagi-0.17.7.dist-info/RECORD,,