auth0-ai-langchain 0.1.1__tar.gz → 0.2.0__tar.gz
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-0.1.1 → auth0_ai_langchain-0.2.0}/PKG-INFO +11 -11
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/README.md +9 -9
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/ciba/ciba_poller_graph.py +29 -18
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/federated_connections/__init__.py +1 -0
- auth0_ai_langchain-0.2.0/auth0_ai_langchain/utils/interrupt.py +13 -0
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/pyproject.toml +3 -4
- auth0_ai_langchain-0.1.1/auth0_ai_langchain/utils/interrupt.py +0 -13
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/LICENSE +0 -0
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/FGARetriever.py +0 -0
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/__init__.py +0 -0
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/auth0_ai.py +0 -0
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/ciba/__init__.py +0 -0
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/ciba/ciba_graph/ciba_graph.py +0 -0
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/ciba/ciba_graph/initialize_ciba.py +0 -0
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/ciba/ciba_graph/initialize_hitl.py +0 -0
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/ciba/ciba_graph/types.py +0 -0
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/ciba/ciba_graph/utils.py +0 -0
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/ciba/types.py +0 -0
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/federated_connections/federated_connection_authorizer.py +0 -0
- {auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/fga/fga_authorizer.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: auth0-ai-langchain
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
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.
|
|
14
|
+
Requires-Dist: auth0-ai (>=0.2.0,<0.3.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,7 +28,7 @@ Description-Content-Type: text/markdown
|
|
|
28
28
|
|
|
29
29
|
## Installation
|
|
30
30
|
|
|
31
|
-
>
|
|
31
|
+
> ⚠️ **WARNING**: `auth0-ai-langchain` is currently under development and it is not intended to be used in production, and therefore has no official support.
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
34
|
pip install auth0-ai-langchain
|
|
@@ -38,12 +38,12 @@ pip install auth0-ai-langchain
|
|
|
38
38
|
|
|
39
39
|
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.
|
|
40
40
|
|
|
41
|
-
Full example of [Authorization for Tools](
|
|
41
|
+
Full example of [Authorization for Tools](https://github.com/auth0-lab/auth0-ai-python/tree/main/examples/authorization-for-tools/langchain-examples).
|
|
42
42
|
|
|
43
43
|
1. Create an instance of FGA Authorizer:
|
|
44
44
|
|
|
45
45
|
```python
|
|
46
|
-
from
|
|
46
|
+
from auth0_ai_langchain.fga.fga_authorizer import FGAAuthorizer, FGAAuthorizerOptions
|
|
47
47
|
|
|
48
48
|
fga = FGAAuthorizer.create()
|
|
49
49
|
```
|
|
@@ -104,13 +104,13 @@ buy_tool = StructuredTool(
|
|
|
104
104
|
|
|
105
105
|
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.
|
|
106
106
|
|
|
107
|
-
Full Example of [Calling APIs On User's Behalf](
|
|
107
|
+
Full Example of [Calling APIs On User's Behalf](https://github.com/auth0-lab/auth0-ai-python/tree/main/examples/calling-apis/langchain-examples).
|
|
108
108
|
|
|
109
109
|
1. Define a tool with the proper authorizer:
|
|
110
110
|
|
|
111
111
|
```python
|
|
112
|
-
from
|
|
113
|
-
from
|
|
112
|
+
from auth0_ai_langchain.auth0_ai import Auth0AI
|
|
113
|
+
from auth0_ai_langchain.federated_connections import get_access_token_for_connection
|
|
114
114
|
from langchain_core.tools import StructuredTool
|
|
115
115
|
|
|
116
116
|
auth0_ai = Auth0AI()
|
|
@@ -160,14 +160,14 @@ workflow = (
|
|
|
160
160
|
|
|
161
161
|
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.
|
|
162
162
|
|
|
163
|
-
Full Example of [RAG Application](
|
|
163
|
+
Full Example of [RAG Application](https://github.com/auth0-lab/auth0-ai-python/tree/main/examples/authorization-for-rag/langchain-examples).
|
|
164
164
|
|
|
165
165
|
Create a retriever instance using the `FGARetriever` class.
|
|
166
166
|
|
|
167
167
|
```python
|
|
168
168
|
from langchain.vectorstores import VectorStoreIndex
|
|
169
169
|
from langchain.schema import Document
|
|
170
|
-
from
|
|
170
|
+
from auth0_ai_langchain import FGARetriever
|
|
171
171
|
from openfga_sdk.client.models import ClientCheckRequest
|
|
172
172
|
from openfga_sdk import ClientConfiguration
|
|
173
173
|
from openfga_sdk.credentials import CredentialConfiguration, Credentials
|
|
@@ -217,5 +217,5 @@ print(response)
|
|
|
217
217
|
</p>
|
|
218
218
|
<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>
|
|
219
219
|
<p align="center">
|
|
220
|
-
This project is licensed under the Apache 2.0 license. See the <a href="/LICENSE"> LICENSE</a> file for more info.</p>
|
|
220
|
+
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>
|
|
221
221
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
|
-
>
|
|
9
|
+
> ⚠️ **WARNING**: `auth0-ai-langchain` is currently under development and it is not intended to be used in production, and therefore has no official support.
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
12
|
pip install auth0-ai-langchain
|
|
@@ -16,12 +16,12 @@ pip install auth0-ai-langchain
|
|
|
16
16
|
|
|
17
17
|
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.
|
|
18
18
|
|
|
19
|
-
Full example of [Authorization for Tools](
|
|
19
|
+
Full example of [Authorization for Tools](https://github.com/auth0-lab/auth0-ai-python/tree/main/examples/authorization-for-tools/langchain-examples).
|
|
20
20
|
|
|
21
21
|
1. Create an instance of FGA Authorizer:
|
|
22
22
|
|
|
23
23
|
```python
|
|
24
|
-
from
|
|
24
|
+
from auth0_ai_langchain.fga.fga_authorizer import FGAAuthorizer, FGAAuthorizerOptions
|
|
25
25
|
|
|
26
26
|
fga = FGAAuthorizer.create()
|
|
27
27
|
```
|
|
@@ -82,13 +82,13 @@ buy_tool = StructuredTool(
|
|
|
82
82
|
|
|
83
83
|
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.
|
|
84
84
|
|
|
85
|
-
Full Example of [Calling APIs On User's Behalf](
|
|
85
|
+
Full Example of [Calling APIs On User's Behalf](https://github.com/auth0-lab/auth0-ai-python/tree/main/examples/calling-apis/langchain-examples).
|
|
86
86
|
|
|
87
87
|
1. Define a tool with the proper authorizer:
|
|
88
88
|
|
|
89
89
|
```python
|
|
90
|
-
from
|
|
91
|
-
from
|
|
90
|
+
from auth0_ai_langchain.auth0_ai import Auth0AI
|
|
91
|
+
from auth0_ai_langchain.federated_connections import get_access_token_for_connection
|
|
92
92
|
from langchain_core.tools import StructuredTool
|
|
93
93
|
|
|
94
94
|
auth0_ai = Auth0AI()
|
|
@@ -138,14 +138,14 @@ workflow = (
|
|
|
138
138
|
|
|
139
139
|
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.
|
|
140
140
|
|
|
141
|
-
Full Example of [RAG Application](
|
|
141
|
+
Full Example of [RAG Application](https://github.com/auth0-lab/auth0-ai-python/tree/main/examples/authorization-for-rag/langchain-examples).
|
|
142
142
|
|
|
143
143
|
Create a retriever instance using the `FGARetriever` class.
|
|
144
144
|
|
|
145
145
|
```python
|
|
146
146
|
from langchain.vectorstores import VectorStoreIndex
|
|
147
147
|
from langchain.schema import Document
|
|
148
|
-
from
|
|
148
|
+
from auth0_ai_langchain import FGARetriever
|
|
149
149
|
from openfga_sdk.client.models import ClientCheckRequest
|
|
150
150
|
from openfga_sdk import ClientConfiguration
|
|
151
151
|
from openfga_sdk.credentials import CredentialConfiguration, Credentials
|
|
@@ -195,4 +195,4 @@ print(response)
|
|
|
195
195
|
</p>
|
|
196
196
|
<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>
|
|
197
197
|
<p align="center">
|
|
198
|
-
This project is licensed under the Apache 2.0 license. See the <a href="/LICENSE"> LICENSE</a> file for more info.</p>
|
|
198
|
+
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>
|
{auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/ciba/ciba_poller_graph.py
RENAMED
|
@@ -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,3 +1,4 @@
|
|
|
1
1
|
from auth0_ai.interrupts.federated_connection_interrupt import FederatedConnectionError as FederatedConnectionError
|
|
2
|
+
from auth0_ai.interrupts.federated_connection_interrupt import FederatedConnectionInterrupt as FederatedConnectionInterrupt
|
|
2
3
|
from auth0_ai.authorizers.federated_connection_authorizer import get_access_token_for_connection as get_access_token_for_connection
|
|
3
4
|
from .federated_connection_authorizer import FederatedConnectionAuthorizer as FederatedConnectionAuthorizer
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from auth0_ai.interrupts.auth0_interrupt import Auth0Interrupt
|
|
2
|
+
from langgraph.errors import GraphInterrupt
|
|
3
|
+
from langgraph.types import Interrupt
|
|
4
|
+
|
|
5
|
+
def to_graph_interrupt(interrupt: Auth0Interrupt) -> GraphInterrupt:
|
|
6
|
+
return GraphInterrupt([
|
|
7
|
+
Interrupt(
|
|
8
|
+
value=interrupt.to_json(),
|
|
9
|
+
when="during",
|
|
10
|
+
resumable=True,
|
|
11
|
+
ns=[f"auth0AI:{interrupt.__class__.__name__}:{interrupt.code}"]
|
|
12
|
+
)
|
|
13
|
+
])
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "auth0-ai-langchain"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
description = "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
|
homepage = "https://auth0.com"
|
|
@@ -14,17 +14,16 @@ langchain = "^0.3.20"
|
|
|
14
14
|
langgraph-sdk = "^0.1.55"
|
|
15
15
|
langchain-core = "^0.3.43"
|
|
16
16
|
langgraph = "^0.3.25"
|
|
17
|
-
auth0-ai = "^0.
|
|
17
|
+
auth0-ai = "^0.2.0"
|
|
18
|
+
# auth0-ai = { path = "../auth0-ai", develop = true }
|
|
18
19
|
|
|
19
20
|
[tool.poetry.group.test.dependencies]
|
|
20
21
|
pytest-randomly = "^3.15.0"
|
|
21
22
|
pytest-asyncio = "^0.25.0"
|
|
22
23
|
pytest = "^8.2.0"
|
|
23
24
|
|
|
24
|
-
|
|
25
25
|
[tool.poetry.group.dev.dependencies]
|
|
26
26
|
twine = "^6.1.0"
|
|
27
|
-
# auth0-ai = { path = "../auth0-ai", develop = true }
|
|
28
27
|
|
|
29
28
|
[build-system]
|
|
30
29
|
requires = ["poetry-core"]
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
from auth0_ai.interrupts.auth0_interrupt import Auth0Interrupt
|
|
2
|
-
from langgraph.errors import GraphInterrupt
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def to_graph_interrupt(interrupt: Auth0Interrupt) -> GraphInterrupt:
|
|
6
|
-
return GraphInterrupt([
|
|
7
|
-
{
|
|
8
|
-
"value": interrupt,
|
|
9
|
-
"when": "during",
|
|
10
|
-
"resumable": True,
|
|
11
|
-
"ns": [f"auth0AI:{interrupt.__class__.__name__}:{interrupt.code}"]
|
|
12
|
-
}
|
|
13
|
-
])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/ciba/ciba_graph/types.py
RENAMED
|
File without changes
|
{auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/ciba/ciba_graph/utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{auth0_ai_langchain-0.1.1 → auth0_ai_langchain-0.2.0}/auth0_ai_langchain/fga/fga_authorizer.py
RENAMED
|
File without changes
|