auth0-ai-langchain 0.1.0__py3-none-any.whl → 0.1.2__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.
Potentially problematic release.
This version of auth0-ai-langchain might be problematic. Click here for more details.
- auth0_ai_langchain/ciba/ciba_poller_graph.py +29 -18
- {auth0_ai_langchain-0.1.0.dist-info → auth0_ai_langchain-0.1.2.dist-info}/METADATA +12 -17
- {auth0_ai_langchain-0.1.0.dist-info → auth0_ai_langchain-0.1.2.dist-info}/RECORD +5 -5
- {auth0_ai_langchain-0.1.0.dist-info → auth0_ai_langchain-0.1.2.dist-info}/LICENSE +0 -0
- {auth0_ai_langchain-0.1.0.dist-info → auth0_ai_langchain-0.1.2.dist-info}/WHEEL +0 -0
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
import os
|
|
2
|
-
from
|
|
3
|
-
|
|
4
|
-
from
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
from typing import Awaitable, Callable, Optional, TypedDict, Union
|
|
3
|
+
|
|
4
|
+
from auth0_ai.authorizers.ciba_authorizer import (
|
|
5
|
+
AuthorizeResponse,
|
|
6
|
+
CIBAAuthorizer,
|
|
7
|
+
CibaAuthorizerCheckResponse,
|
|
8
|
+
)
|
|
7
9
|
from auth0_ai.credentials import Credentials
|
|
8
10
|
from auth0_ai.token_response import TokenResponse
|
|
9
|
-
from
|
|
11
|
+
from langgraph.graph import END, START, StateGraph
|
|
12
|
+
from langgraph_sdk import get_client
|
|
13
|
+
from langgraph_sdk.schema import Command
|
|
14
|
+
|
|
15
|
+
from auth0_ai_langchain.ciba.types import Auth0Graphs
|
|
16
|
+
|
|
10
17
|
|
|
11
18
|
class State(TypedDict):
|
|
12
19
|
ciba_response: AuthorizeResponse
|
|
13
20
|
on_resume_invoke: str
|
|
14
21
|
thread_id: str
|
|
15
22
|
user_id: str
|
|
16
|
-
|
|
23
|
+
|
|
17
24
|
# Internal
|
|
18
25
|
task_id: str
|
|
19
26
|
tool_id: str
|
|
20
27
|
status: CibaAuthorizerCheckResponse
|
|
21
28
|
token_response: Optional[TokenResponse]
|
|
22
29
|
|
|
30
|
+
|
|
23
31
|
def ciba_poller_graph(on_stop_scheduler: Union[str, Callable[[State], Awaitable[None]]]):
|
|
24
32
|
"""
|
|
25
33
|
A LangGraph graph to monitor the status of a CIBA transaction.
|
|
@@ -35,22 +43,24 @@ def ciba_poller_graph(on_stop_scheduler: Union[str, Callable[[State], Awaitable[
|
|
|
35
43
|
except Exception as e:
|
|
36
44
|
print(f"Error in check_status: {e}")
|
|
37
45
|
return state
|
|
38
|
-
|
|
46
|
+
|
|
39
47
|
async def stop_scheduler(state: State):
|
|
40
48
|
try:
|
|
41
49
|
if isinstance(on_stop_scheduler, str):
|
|
42
|
-
langgraph = get_client(url=os.getenv(
|
|
50
|
+
langgraph = get_client(url=os.getenv(
|
|
51
|
+
"LANGGRAPH_API_URL", "http://localhost:54367"))
|
|
43
52
|
await langgraph.crons.create_for_thread(state.thread_id, Auth0Graphs.CIBA_POLLER.value)
|
|
44
53
|
elif callable(on_stop_scheduler):
|
|
45
54
|
await on_stop_scheduler(state)
|
|
46
55
|
except Exception as e:
|
|
47
56
|
print(f"Error in stop_scheduler: {e}")
|
|
48
57
|
return state
|
|
49
|
-
|
|
58
|
+
|
|
50
59
|
async def resume_agent(state: State):
|
|
51
|
-
langgraph = get_client(url=os.getenv(
|
|
60
|
+
langgraph = get_client(url=os.getenv(
|
|
61
|
+
"LANGGRAPH_API_URL", "http://localhost:54367"))
|
|
52
62
|
_credentials: Credentials = None
|
|
53
|
-
|
|
63
|
+
|
|
54
64
|
try:
|
|
55
65
|
if state["status"] == CibaAuthorizerCheckResponse.APPROVED:
|
|
56
66
|
_credentials = {
|
|
@@ -64,15 +74,16 @@ def ciba_poller_graph(on_stop_scheduler: Union[str, Callable[[State], Awaitable[
|
|
|
64
74
|
state["thread_id"],
|
|
65
75
|
state["on_resume_invoke"],
|
|
66
76
|
config={
|
|
67
|
-
|
|
77
|
+
# this is only for this run / thread_id
|
|
78
|
+
"configurable": {"_credentials": _credentials}
|
|
68
79
|
},
|
|
69
80
|
command=Command(resume={"status": state["status"]})
|
|
70
81
|
)
|
|
71
82
|
except Exception as e:
|
|
72
83
|
print(f"Error in resume_agent: {e}")
|
|
73
|
-
|
|
84
|
+
|
|
74
85
|
return state
|
|
75
|
-
|
|
86
|
+
|
|
76
87
|
async def should_continue(state: State):
|
|
77
88
|
status = state.get("status")
|
|
78
89
|
if status == CibaAuthorizerCheckResponse.PENDING:
|
|
@@ -82,7 +93,7 @@ def ciba_poller_graph(on_stop_scheduler: Union[str, Callable[[State], Awaitable[
|
|
|
82
93
|
elif status in [CibaAuthorizerCheckResponse.APPROVED, CibaAuthorizerCheckResponse.REJECTED]:
|
|
83
94
|
return "resume_agent"
|
|
84
95
|
return END
|
|
85
|
-
|
|
96
|
+
|
|
86
97
|
state_graph = StateGraph(State)
|
|
87
98
|
state_graph.add_node("check_status", check_status)
|
|
88
99
|
state_graph.add_node("stop_scheduler", stop_scheduler)
|
|
@@ -90,5 +101,5 @@ def ciba_poller_graph(on_stop_scheduler: Union[str, Callable[[State], Awaitable[
|
|
|
90
101
|
state_graph.add_edge(START, "check_status")
|
|
91
102
|
state_graph.add_edge("resume_agent", "stop_scheduler")
|
|
92
103
|
state_graph.add_conditional_edges("check_status", should_continue)
|
|
93
|
-
|
|
94
|
-
return state_graph
|
|
104
|
+
|
|
105
|
+
return state_graph
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: auth0-ai-langchain
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: This package is an SDK for building secure AI-powered applications using Auth0, Okta FGA and LangChain.
|
|
5
5
|
License: Apache-2.0
|
|
6
6
|
Author: Auth0
|
|
@@ -11,7 +11,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.11
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.12
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
-
Requires-Dist: auth0-ai (>=0.1.
|
|
14
|
+
Requires-Dist: auth0-ai (>=0.1.1,<0.2.0)
|
|
15
15
|
Requires-Dist: langchain (>=0.3.20,<0.4.0)
|
|
16
16
|
Requires-Dist: langchain-core (>=0.3.43,<0.4.0)
|
|
17
17
|
Requires-Dist: langgraph (>=0.3.25,<0.4.0)
|
|
@@ -28,28 +28,23 @@ Description-Content-Type: text/markdown
|
|
|
28
28
|
|
|
29
29
|
## Installation
|
|
30
30
|
|
|
31
|
-
> [!WARNING]
|
|
31
|
+
> [!WARNING]
|
|
32
|
+
> `auth0-ai-langchain` is currently under development and it is not intended to be used in production, and therefore has no official support.
|
|
32
33
|
|
|
33
34
|
```bash
|
|
34
35
|
pip install auth0-ai-langchain
|
|
35
36
|
```
|
|
36
37
|
|
|
37
|
-
## Async User Confirmation
|
|
38
|
-
|
|
39
|
-
`Auth0AI` uses CIBA (Client Initiated Backchannel Authentication) to handle user confirmation asynchronously. This is useful when you need to confirm a user action before proceeding with a tool execution.
|
|
40
|
-
|
|
41
|
-
Full Example of [Async User Confirmation](../../examples/async-user-confirmation/langchain-examples/).
|
|
42
|
-
|
|
43
38
|
## Authorization for Tools
|
|
44
39
|
|
|
45
40
|
The `FGAAuthorizer` can leverage Okta FGA to authorize tools executions. The `FGAAuthorizer.create` function can be used to create an authorizer that checks permissions before executing the tool.
|
|
46
41
|
|
|
47
|
-
Full example of [Authorization for Tools](
|
|
42
|
+
Full example of [Authorization for Tools](https://github.com/auth0-lab/auth0-ai-python/tree/main/examples/authorization-for-tools/langchain-examples).
|
|
48
43
|
|
|
49
44
|
1. Create an instance of FGA Authorizer:
|
|
50
45
|
|
|
51
46
|
```python
|
|
52
|
-
from
|
|
47
|
+
from auth0_ai_langchain.fga.fga_authorizer import FGAAuthorizer, FGAAuthorizerOptions
|
|
53
48
|
|
|
54
49
|
fga = FGAAuthorizer.create()
|
|
55
50
|
```
|
|
@@ -110,13 +105,13 @@ buy_tool = StructuredTool(
|
|
|
110
105
|
|
|
111
106
|
The `Auth0AI.with_federated_connection` function exchanges user's refresh token taken from the runnable configuration (`config.configurable._credentials.refresh_token`) for a Federated Connection API token.
|
|
112
107
|
|
|
113
|
-
Full Example of [Calling APIs On User's Behalf](
|
|
108
|
+
Full Example of [Calling APIs On User's Behalf](https://github.com/auth0-lab/auth0-ai-python/tree/main/examples/calling-apis/langchain-examples).
|
|
114
109
|
|
|
115
110
|
1. Define a tool with the proper authorizer:
|
|
116
111
|
|
|
117
112
|
```python
|
|
118
|
-
from
|
|
119
|
-
from
|
|
113
|
+
from auth0_ai_langchain.auth0_ai import Auth0AI
|
|
114
|
+
from auth0_ai_langchain.federated_connections import get_access_token_for_connection
|
|
120
115
|
from langchain_core.tools import StructuredTool
|
|
121
116
|
|
|
122
117
|
auth0_ai = Auth0AI()
|
|
@@ -166,14 +161,14 @@ workflow = (
|
|
|
166
161
|
|
|
167
162
|
The `FGARetriever` can be used to filter documents based on access control checks defined in Okta FGA. This retriever performs batch checks on retrieved documents, returning only the ones that pass the specified access criteria.
|
|
168
163
|
|
|
169
|
-
Full Example of [RAG Application](
|
|
164
|
+
Full Example of [RAG Application](https://github.com/auth0-lab/auth0-ai-python/tree/main/examples/authorization-for-rag/langchain-examples).
|
|
170
165
|
|
|
171
166
|
Create a retriever instance using the `FGARetriever` class.
|
|
172
167
|
|
|
173
168
|
```python
|
|
174
169
|
from langchain.vectorstores import VectorStoreIndex
|
|
175
170
|
from langchain.schema import Document
|
|
176
|
-
from
|
|
171
|
+
from auth0_ai_langchain import FGARetriever
|
|
177
172
|
from openfga_sdk.client.models import ClientCheckRequest
|
|
178
173
|
from openfga_sdk import ClientConfiguration
|
|
179
174
|
from openfga_sdk.credentials import CredentialConfiguration, Credentials
|
|
@@ -223,5 +218,5 @@ print(response)
|
|
|
223
218
|
</p>
|
|
224
219
|
<p align="center">Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout <a href="https://auth0.com/why-auth0">Why Auth0?</a></p>
|
|
225
220
|
<p align="center">
|
|
226
|
-
This project is licensed under the Apache 2.0 license. See the <a href="/LICENSE"> LICENSE</a> file for more info.</p>
|
|
221
|
+
This project is licensed under the Apache 2.0 license. See the <a href="https://github.com/auth0-lab/auth0-ai-python/blob/main/LICENSE"> LICENSE</a> file for more info.</p>
|
|
227
222
|
|
|
@@ -7,13 +7,13 @@ auth0_ai_langchain/ciba/ciba_graph/initialize_ciba.py,sha256=a41KedBzxfLqG2AhvkF
|
|
|
7
7
|
auth0_ai_langchain/ciba/ciba_graph/initialize_hitl.py,sha256=CR3jMolZYYOBHx1AXb6yERBaZThMg677qGGo_vRy6I8,1901
|
|
8
8
|
auth0_ai_langchain/ciba/ciba_graph/types.py,sha256=NZS99vPOgJRc2O7mO5MWj6nAa4RSG1R5oSvzYhkz0RA,4234
|
|
9
9
|
auth0_ai_langchain/ciba/ciba_graph/utils.py,sha256=ZPAh0Gs7Hj59_xngg8M7yx1v52dTn2pNpMNRpFKCSII,560
|
|
10
|
-
auth0_ai_langchain/ciba/ciba_poller_graph.py,sha256=
|
|
10
|
+
auth0_ai_langchain/ciba/ciba_poller_graph.py,sha256=rjlxsTheJrN2J6E5BCE9aVyDO8V7UFhdKyX4KT_hB8k,3828
|
|
11
11
|
auth0_ai_langchain/ciba/types.py,sha256=gybqYEprklZwcMBgaWFooBsJ1GcNUK8ZWRvAX5PZWdE,177
|
|
12
12
|
auth0_ai_langchain/federated_connections/__init__.py,sha256=OJCWTnxYuaWjn8FyFGjCAF7m5Y4Eigkzx7a59atFFFg,356
|
|
13
13
|
auth0_ai_langchain/federated_connections/federated_connection_authorizer.py,sha256=ZLF4p7fPTrODOeHWIShfBTsReSy27u73rIp0L_Umhjg,2218
|
|
14
14
|
auth0_ai_langchain/fga/fga_authorizer.py,sha256=uDaGDSXaxQd1X-2w2zTvnfizMB-DtQ-1G6SIaDNBrho,137
|
|
15
15
|
auth0_ai_langchain/utils/interrupt.py,sha256=JoYJkigDEAPRHZtjo6gw6k3439E4i1O7F4_0ExkL_RE,405
|
|
16
|
-
auth0_ai_langchain-0.1.
|
|
17
|
-
auth0_ai_langchain-0.1.
|
|
18
|
-
auth0_ai_langchain-0.1.
|
|
19
|
-
auth0_ai_langchain-0.1.
|
|
16
|
+
auth0_ai_langchain-0.1.2.dist-info/LICENSE,sha256=Lu_2YH0oK8b_VVisAhNQ2WIdtwY8pSU2PLbll-y6Cj8,9792
|
|
17
|
+
auth0_ai_langchain-0.1.2.dist-info/METADATA,sha256=synK995x8fRtUFH2yR0oyh5vwGzZTEdC2zUJygtzAwQ,7786
|
|
18
|
+
auth0_ai_langchain-0.1.2.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
19
|
+
auth0_ai_langchain-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|