datarobot-genai 0.2.39__tar.gz → 0.2.42__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.
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/PKG-INFO +1 -1
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/pyproject.toml +5 -1
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/agents/base.py +5 -2
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/chat/responses.py +6 -1
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/utils/auth.py +188 -31
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/crewai/agent.py +12 -4
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/crewai/base.py +4 -1
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/crewai/events.py +11 -4
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/clients/microsoft_graph.py +96 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/microsoft_graph/tools.py +146 -1
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/langgraph/agent.py +10 -2
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/llama_index/agent.py +12 -5
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/llama_index/base.py +4 -1
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/nat/agent.py +17 -6
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/.gitignore +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/AUTHORS +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/LICENSE +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/README.md +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/agents/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/chat/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/chat/auth.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/chat/client.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/cli/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/cli/agent_environment.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/cli/agent_kernel.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/custom_model.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/mcp/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/mcp/common.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/telemetry_agent.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/utils/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/utils/urls.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/crewai/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/crewai/mcp.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/auth.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/clients.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/config.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/config_utils.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/constants.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/credentials.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dr_mcp_server.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dr_mcp_server_logo.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_prompts/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_prompts/controllers.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_prompts/dr_lib.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_prompts/register.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_prompts/utils.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_tools/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/base.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/default.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/drum.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/config.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/controllers.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/metadata.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/register.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/schemas/drum_agentic_fallback_schema.json +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/schemas/drum_prediction_fallback_schema.json +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_tools/register.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/dynamic_tools/schema.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/exceptions.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/logging.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/mcp_instance.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/memory_management/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/memory_management/manager.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/memory_management/memory_tools.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/routes.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/routes_utils.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/server_life_cycle.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/telemetry.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/tool_config.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/tool_filter.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/core/utils.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/server.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/test_utils/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/test_utils/clients/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/test_utils/clients/anthropic.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/test_utils/clients/base.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/test_utils/clients/dr_gateway.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/test_utils/clients/openai.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/test_utils/elicitation_test_tool.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/test_utils/integration_mcp_server.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/test_utils/mcp_utils_ete.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/test_utils/mcp_utils_integration.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/test_utils/test_interactive.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/test_utils/tool_base_ete.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/test_utils/utils.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/clients/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/clients/atlassian.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/clients/confluence.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/clients/gdrive.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/clients/jira.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/clients/s3.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/confluence/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/confluence/tools.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/gdrive/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/gdrive/tools.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/jira/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/jira/tools.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/microsoft_graph/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/predictive/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/predictive/data.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/predictive/deployment.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/predictive/deployment_info.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/predictive/model.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/predictive/predict.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/predictive/predict_realtime.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/predictive/project.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/drmcp/tools/predictive/training.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/langgraph/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/langgraph/mcp.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/llama_index/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/llama_index/mcp.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/nat/__init__.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/nat/datarobot_auth_provider.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/nat/datarobot_llm_clients.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/nat/datarobot_llm_providers.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/nat/datarobot_mcp_client.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/nat/helpers.py +0 -0
- {datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/py.typed +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "datarobot-genai"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.42"
|
|
8
8
|
description = "Generic helpers for GenAI"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10, <3.13"
|
|
@@ -130,6 +130,7 @@ dev = [
|
|
|
130
130
|
"pytest-asyncio>=0.23.5",
|
|
131
131
|
"responses>=0.25.8",
|
|
132
132
|
"ipdb>=0.13.13",
|
|
133
|
+
"aioresponses>=0.7.8",
|
|
133
134
|
]
|
|
134
135
|
|
|
135
136
|
|
|
@@ -186,6 +187,9 @@ fixable = [
|
|
|
186
187
|
"I001", # isort import order within functions
|
|
187
188
|
"PLC0415",# pylint import-outside-toplevel for controlled local imports
|
|
188
189
|
]
|
|
190
|
+
"src/datarobot_genai/**/*.py" = [
|
|
191
|
+
"PLC0415",# pylint import-outside-toplevel: allow lazy imports for memory optimization
|
|
192
|
+
]
|
|
189
193
|
|
|
190
194
|
[tool.ruff.lint.isort]
|
|
191
195
|
force-single-line = true
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import abc
|
|
16
18
|
import json
|
|
17
19
|
import os
|
|
@@ -19,6 +21,7 @@ from collections.abc import AsyncGenerator
|
|
|
19
21
|
from collections.abc import Mapping
|
|
20
22
|
from typing import Any
|
|
21
23
|
from typing import Generic
|
|
24
|
+
from typing import TypeAlias
|
|
22
25
|
from typing import TypedDict
|
|
23
26
|
from typing import TypeVar
|
|
24
27
|
from typing import cast
|
|
@@ -98,7 +101,7 @@ class BaseAgent(Generic[TTool], abc.ABC):
|
|
|
98
101
|
return get_api_base(self.api_base, deployment_id)
|
|
99
102
|
|
|
100
103
|
@abc.abstractmethod
|
|
101
|
-
async def invoke(self, completion_create_params: CompletionCreateParams) ->
|
|
104
|
+
async def invoke(self, completion_create_params: CompletionCreateParams) -> InvokeReturn:
|
|
102
105
|
raise NotImplementedError("Not implemented")
|
|
103
106
|
|
|
104
107
|
@classmethod
|
|
@@ -167,7 +170,7 @@ class UsageMetrics(TypedDict):
|
|
|
167
170
|
|
|
168
171
|
|
|
169
172
|
# Canonical return type for DRUM-compatible invoke implementations
|
|
170
|
-
InvokeReturn = (
|
|
173
|
+
InvokeReturn: TypeAlias = (
|
|
171
174
|
AsyncGenerator[tuple[str | Event, MultiTurnSample | None, UsageMetrics], None]
|
|
172
175
|
| tuple[str, MultiTurnSample | None, UsageMetrics]
|
|
173
176
|
)
|
{datarobot_genai-0.2.39 → datarobot_genai-0.2.42}/src/datarobot_genai/core/chat/responses.py
RENAMED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
"""OpenAI-compatible response helpers for chat interactions."""
|
|
16
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
17
19
|
import asyncio
|
|
18
20
|
import queue
|
|
19
21
|
import time
|
|
@@ -24,6 +26,7 @@ from collections.abc import AsyncGenerator
|
|
|
24
26
|
from collections.abc import AsyncIterator
|
|
25
27
|
from collections.abc import Iterator
|
|
26
28
|
from concurrent.futures import ThreadPoolExecutor
|
|
29
|
+
from typing import TYPE_CHECKING
|
|
27
30
|
from typing import Any
|
|
28
31
|
from typing import TypeVar
|
|
29
32
|
|
|
@@ -38,10 +41,12 @@ from openai.types.chat import ChatCompletionMessage
|
|
|
38
41
|
from openai.types.chat.chat_completion import Choice
|
|
39
42
|
from openai.types.chat.chat_completion_chunk import Choice as ChunkChoice
|
|
40
43
|
from openai.types.chat.chat_completion_chunk import ChoiceDelta
|
|
41
|
-
from ragas import MultiTurnSample
|
|
42
44
|
|
|
43
45
|
from datarobot_genai.core.agents import default_usage_metrics
|
|
44
46
|
|
|
47
|
+
if TYPE_CHECKING:
|
|
48
|
+
from ragas import MultiTurnSample
|
|
49
|
+
|
|
45
50
|
|
|
46
51
|
class CustomModelChatResponse(ChatCompletion):
|
|
47
52
|
pipeline_interactions: str | None = None
|
|
@@ -12,13 +12,19 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
import logging
|
|
15
|
+
import os
|
|
15
16
|
import warnings
|
|
17
|
+
from collections.abc import Sequence
|
|
16
18
|
from typing import Any
|
|
19
|
+
from typing import Protocol
|
|
17
20
|
|
|
21
|
+
import aiohttp
|
|
18
22
|
import jwt
|
|
19
|
-
from datarobot.auth.datarobot.oauth import AsyncOAuth as
|
|
23
|
+
from datarobot.auth.datarobot.oauth import AsyncOAuth as DatarobotOAuthClient
|
|
24
|
+
from datarobot.auth.exceptions import OAuthProviderNotFound
|
|
25
|
+
from datarobot.auth.exceptions import OAuthValidationErr
|
|
20
26
|
from datarobot.auth.identity import Identity
|
|
21
|
-
from datarobot.auth.oauth import
|
|
27
|
+
from datarobot.auth.oauth import OAuthToken
|
|
22
28
|
from datarobot.auth.session import AuthCtx
|
|
23
29
|
from datarobot.core.config import DataRobotAppFrameworkBaseSettings
|
|
24
30
|
from datarobot.models.genai.agent.auth import ToolAuth
|
|
@@ -183,52 +189,203 @@ class AuthContextHeaderHandler:
|
|
|
183
189
|
return None
|
|
184
190
|
|
|
185
191
|
|
|
192
|
+
# --- OAuth Token Provider Implementation ---
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
class TokenRetriever(Protocol):
|
|
196
|
+
"""Protocol for OAuth token retrievers."""
|
|
197
|
+
|
|
198
|
+
def filter_identities(self, identities: Sequence[Identity]) -> list[Identity]:
|
|
199
|
+
"""Filter identities to only those valid for this retriever implementation."""
|
|
200
|
+
...
|
|
201
|
+
|
|
202
|
+
async def refresh_access_token(self, identity: Identity) -> OAuthToken:
|
|
203
|
+
"""Refresh the access token for the given identity ID.
|
|
204
|
+
|
|
205
|
+
Parameters
|
|
206
|
+
----------
|
|
207
|
+
identity_id : str
|
|
208
|
+
The provider identity ID to refresh the token for.
|
|
209
|
+
|
|
210
|
+
Returns
|
|
211
|
+
-------
|
|
212
|
+
OAuthToken
|
|
213
|
+
The refreshed OAuth token.
|
|
214
|
+
"""
|
|
215
|
+
...
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
class DatarobotTokenRetriever:
|
|
219
|
+
"""Retrieves OAuth tokens using the DataRobot platform."""
|
|
220
|
+
|
|
221
|
+
def __init__(self) -> None:
|
|
222
|
+
self._client = DatarobotOAuthClient()
|
|
223
|
+
|
|
224
|
+
def filter_identities(self, identities: Sequence[Identity]) -> list[Identity]:
|
|
225
|
+
"""Filter oauth2 identities to only those with provider_identity_id.
|
|
226
|
+
|
|
227
|
+
The `provider_identity_id` is required in order to identify the provider
|
|
228
|
+
and retrieve the access token from DataRobot OAuth Providers service.
|
|
229
|
+
"""
|
|
230
|
+
return [i for i in identities if i.type == "oauth2" and i.provider_identity_id]
|
|
231
|
+
|
|
232
|
+
async def refresh_access_token(self, identity: Identity) -> OAuthToken:
|
|
233
|
+
"""Refresh the access token using DataRobot's OAuth client."""
|
|
234
|
+
return await self._client.refresh_access_token(identity_id=identity.provider_identity_id)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
class AuthlibTokenRetriever:
|
|
238
|
+
"""Retrieves OAuth tokens from a generic Authlib-based endpoint."""
|
|
239
|
+
|
|
240
|
+
def __init__(self, application_endpoint: str) -> None:
|
|
241
|
+
if not application_endpoint:
|
|
242
|
+
raise ValueError("AuthlibTokenRetriever requires 'application_endpoint'.")
|
|
243
|
+
self.application_endpoint = application_endpoint.rstrip("/")
|
|
244
|
+
|
|
245
|
+
def filter_identities(self, identities: Sequence[Identity]) -> list[Identity]:
|
|
246
|
+
"""Filter identities to only OAuth2 identities."""
|
|
247
|
+
return [i for i in identities if i.type == "oauth2" and i.provider_identity_id is None]
|
|
248
|
+
|
|
249
|
+
async def refresh_access_token(self, identity: Identity) -> OAuthToken:
|
|
250
|
+
"""Retrieve an OAuth token via an HTTP POST request.
|
|
251
|
+
|
|
252
|
+
Parameters
|
|
253
|
+
----------
|
|
254
|
+
identity : Identity
|
|
255
|
+
The identity to retrieve the token for.
|
|
256
|
+
|
|
257
|
+
Returns
|
|
258
|
+
-------
|
|
259
|
+
OAuthToken
|
|
260
|
+
The retrieved OAuth token.
|
|
261
|
+
"""
|
|
262
|
+
api_token = os.environ.get("DATAROBOT_API_TOKEN")
|
|
263
|
+
if not api_token:
|
|
264
|
+
raise ValueError("DATAROBOT_API_TOKEN environment variable is required but not set.")
|
|
265
|
+
|
|
266
|
+
token_url = f"{self.application_endpoint}/oauth/token/"
|
|
267
|
+
headers = {"Authorization": f"Bearer {api_token}"}
|
|
268
|
+
payload = {"identity_id": identity.id}
|
|
269
|
+
timeout = aiohttp.ClientTimeout(total=30)
|
|
270
|
+
|
|
271
|
+
try:
|
|
272
|
+
async with aiohttp.ClientSession(timeout=timeout) as session:
|
|
273
|
+
async with session.post(token_url, headers=headers, json=payload) as response:
|
|
274
|
+
response.raise_for_status()
|
|
275
|
+
data = await response.json()
|
|
276
|
+
logger.debug(f"Retrieved access token from {token_url}")
|
|
277
|
+
return OAuthToken(**data)
|
|
278
|
+
except aiohttp.ClientError as e:
|
|
279
|
+
logger.error(f"Error retrieving token from {token_url}: {e}")
|
|
280
|
+
raise
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
class OAuthConfig(BaseModel):
|
|
284
|
+
"""Configuration extracted from AuthCtx metadata for OAuth operations."""
|
|
285
|
+
|
|
286
|
+
implementation: str = "datarobot"
|
|
287
|
+
application_endpoint: str | None = None
|
|
288
|
+
|
|
289
|
+
@classmethod
|
|
290
|
+
def from_auth_ctx(cls, auth_ctx: AuthCtx) -> "OAuthConfig":
|
|
291
|
+
metadata = auth_ctx.metadata or {}
|
|
292
|
+
return cls(
|
|
293
|
+
implementation=metadata.get("oauth_implementation", "datarobot"),
|
|
294
|
+
application_endpoint=metadata.get("application_endpoint"),
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def create_token_retriever(config: OAuthConfig) -> TokenRetriever:
|
|
299
|
+
"""Create a token retriever based on the OAuth configuration.
|
|
300
|
+
|
|
301
|
+
Parameters
|
|
302
|
+
----------
|
|
303
|
+
config : OAuthConfig
|
|
304
|
+
The OAuth configuration specifying implementation type and endpoints.
|
|
305
|
+
|
|
306
|
+
Returns
|
|
307
|
+
-------
|
|
308
|
+
TokenRetriever
|
|
309
|
+
The configured token retriever instance.
|
|
310
|
+
"""
|
|
311
|
+
if config.implementation == "datarobot":
|
|
312
|
+
return DatarobotTokenRetriever()
|
|
313
|
+
|
|
314
|
+
if config.implementation == "authlib":
|
|
315
|
+
if not config.application_endpoint:
|
|
316
|
+
raise ValueError("Required 'application_endpoint' not found in metadata.")
|
|
317
|
+
return AuthlibTokenRetriever(config.application_endpoint)
|
|
318
|
+
|
|
319
|
+
raise ValueError(
|
|
320
|
+
f"Unsupported OAuth implementation: '{config.implementation}'. "
|
|
321
|
+
f"Supported values: datarobot, authlib."
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
|
|
186
325
|
class AsyncOAuthTokenProvider:
|
|
187
|
-
"""
|
|
326
|
+
"""Provides OAuth tokens for authorized users.
|
|
327
|
+
|
|
328
|
+
This class manages OAuth token retrieval for users with multiple identity providers.
|
|
329
|
+
It uses either DataRobot or Authlib as the OAuth token storage and refresh backend
|
|
330
|
+
based on the auth context metadata.
|
|
331
|
+
"""
|
|
188
332
|
|
|
189
333
|
def __init__(self, auth_ctx: AuthCtx) -> None:
|
|
334
|
+
"""Initialize the provider with an authorization context.
|
|
335
|
+
|
|
336
|
+
Parameters
|
|
337
|
+
----------
|
|
338
|
+
auth_ctx : AuthCtx
|
|
339
|
+
The authorization context containing user identities and metadata.
|
|
340
|
+
"""
|
|
190
341
|
self.auth_ctx = auth_ctx
|
|
191
|
-
|
|
342
|
+
config = OAuthConfig.from_auth_ctx(auth_ctx)
|
|
343
|
+
self._retriever = create_token_retriever(config)
|
|
192
344
|
|
|
193
345
|
def _get_identity(self, provider_type: str | None) -> Identity:
|
|
194
|
-
"""
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
raise ValueError("No identities found in authorization context.")
|
|
346
|
+
"""Get identity from auth context, filtered by provider_type if specified."""
|
|
347
|
+
oauth_identities = self._retriever.filter_identities(self.auth_ctx.identities)
|
|
348
|
+
if not oauth_identities:
|
|
349
|
+
raise OAuthProviderNotFound("No OAuth provider found.")
|
|
199
350
|
|
|
200
351
|
if provider_type is None:
|
|
201
|
-
if len(
|
|
202
|
-
raise
|
|
203
|
-
"Multiple
|
|
352
|
+
if len(oauth_identities) > 1:
|
|
353
|
+
raise OAuthValidationErr(
|
|
354
|
+
"Multiple OAuth providers found. Specify 'provider_type' parameter."
|
|
204
355
|
)
|
|
205
|
-
return
|
|
206
|
-
|
|
207
|
-
identity = next((id for id in identities if id.provider_type == provider_type), None)
|
|
356
|
+
return oauth_identities[0]
|
|
208
357
|
|
|
358
|
+
identity = next((i for i in oauth_identities if i.provider_type == provider_type), None)
|
|
209
359
|
if identity is None:
|
|
210
|
-
raise
|
|
211
|
-
|
|
360
|
+
raise OAuthValidationErr(f"No identity found for provider '{provider_type}'.")
|
|
212
361
|
return identity
|
|
213
362
|
|
|
214
363
|
async def get_token(self, auth_type: ToolAuth, provider_type: str | None = None) -> str:
|
|
215
|
-
"""Get OAuth access token
|
|
364
|
+
"""Get an OAuth access token for the specified auth type and provider.
|
|
365
|
+
|
|
366
|
+
Parameters
|
|
367
|
+
----------
|
|
368
|
+
auth_type : ToolAuth
|
|
369
|
+
Authentication type (only OBO is supported).
|
|
370
|
+
provider_type : str, optional
|
|
371
|
+
The specific provider to use (e.g., 'google'). Required if multiple
|
|
372
|
+
identities are available.
|
|
373
|
+
|
|
374
|
+
Returns
|
|
375
|
+
-------
|
|
376
|
+
str
|
|
377
|
+
The retrieved OAuth access token.
|
|
378
|
+
|
|
379
|
+
Raises
|
|
380
|
+
------
|
|
381
|
+
ValueError
|
|
382
|
+
If the auth type is unsupported or if a suitable identity cannot be found.
|
|
383
|
+
"""
|
|
216
384
|
if auth_type != ToolAuth.OBO:
|
|
217
385
|
raise ValueError(
|
|
218
|
-
f"Unsupported auth type: {auth_type}. Only
|
|
386
|
+
f"Unsupported auth type: {auth_type}. Only OBO (on-behalf-of) is supported."
|
|
219
387
|
)
|
|
220
388
|
|
|
221
389
|
identity = self._get_identity(provider_type)
|
|
222
|
-
token_data = await self.
|
|
223
|
-
identity_id=identity.provider_identity_id
|
|
224
|
-
)
|
|
390
|
+
token_data = await self._retriever.refresh_access_token(identity)
|
|
225
391
|
return token_data.access_token
|
|
226
|
-
|
|
227
|
-
def _create_oauth_client(self) -> AsyncOAuthComponent:
|
|
228
|
-
"""Create either DataRobot or Authlib OAuth client based on
|
|
229
|
-
authorization context.
|
|
230
|
-
|
|
231
|
-
Note: at the moment, only DataRobot OAuth client is supported.
|
|
232
|
-
"""
|
|
233
|
-
logger.debug("Using DataRobot OAuth client")
|
|
234
|
-
return DatarobotAsyncOAuthClient()
|
|
@@ -11,15 +11,20 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from typing import TYPE_CHECKING
|
|
14
17
|
|
|
15
18
|
from crewai import LLM
|
|
16
|
-
from ragas import MultiTurnSample
|
|
17
|
-
from ragas.messages import AIMessage
|
|
18
|
-
from ragas.messages import HumanMessage
|
|
19
|
-
from ragas.messages import ToolMessage
|
|
20
19
|
|
|
21
20
|
from datarobot_genai.core.utils.urls import get_api_base
|
|
22
21
|
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from ragas import MultiTurnSample
|
|
24
|
+
from ragas.messages import AIMessage
|
|
25
|
+
from ragas.messages import HumanMessage
|
|
26
|
+
from ragas.messages import ToolMessage
|
|
27
|
+
|
|
23
28
|
|
|
24
29
|
def build_llm(
|
|
25
30
|
*,
|
|
@@ -39,4 +44,7 @@ def create_pipeline_interactions_from_messages(
|
|
|
39
44
|
) -> MultiTurnSample | None:
|
|
40
45
|
if not messages:
|
|
41
46
|
return None
|
|
47
|
+
# Lazy import to reduce memory overhead when ragas is not used
|
|
48
|
+
from ragas import MultiTurnSample
|
|
49
|
+
|
|
42
50
|
return MultiTurnSample(user_input=messages)
|
|
@@ -26,13 +26,13 @@ from __future__ import annotations
|
|
|
26
26
|
import abc
|
|
27
27
|
import asyncio
|
|
28
28
|
from collections.abc import AsyncGenerator
|
|
29
|
+
from typing import TYPE_CHECKING
|
|
29
30
|
from typing import Any
|
|
30
31
|
|
|
31
32
|
from crewai import Crew
|
|
32
33
|
from crewai.events.event_bus import CrewAIEventsBus
|
|
33
34
|
from crewai.tools import BaseTool
|
|
34
35
|
from openai.types.chat import CompletionCreateParams
|
|
35
|
-
from ragas import MultiTurnSample
|
|
36
36
|
|
|
37
37
|
from datarobot_genai.core.agents.base import BaseAgent
|
|
38
38
|
from datarobot_genai.core.agents.base import InvokeReturn
|
|
@@ -44,6 +44,9 @@ from datarobot_genai.core.agents.base import is_streaming
|
|
|
44
44
|
from .agent import create_pipeline_interactions_from_messages
|
|
45
45
|
from .mcp import mcp_tools_context
|
|
46
46
|
|
|
47
|
+
if TYPE_CHECKING:
|
|
48
|
+
from ragas import MultiTurnSample
|
|
49
|
+
|
|
47
50
|
|
|
48
51
|
class CrewAIAgent(BaseAgent[BaseTool], abc.ABC):
|
|
49
52
|
"""Abstract base agent for CrewAI workflows.
|
|
@@ -16,12 +16,13 @@ from __future__ import annotations
|
|
|
16
16
|
import importlib
|
|
17
17
|
import json
|
|
18
18
|
import logging
|
|
19
|
+
from typing import TYPE_CHECKING
|
|
19
20
|
from typing import Any
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
from ragas.messages import
|
|
23
|
-
from ragas.messages import
|
|
24
|
-
from ragas.messages import ToolMessage
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from ragas.messages import AIMessage
|
|
24
|
+
from ragas.messages import HumanMessage
|
|
25
|
+
from ragas.messages import ToolMessage
|
|
25
26
|
|
|
26
27
|
# Resolve crewai symbols at runtime to avoid mypy issues with untyped packages
|
|
27
28
|
try:
|
|
@@ -65,6 +66,12 @@ class CrewAIEventListener:
|
|
|
65
66
|
self.messages: list[HumanMessage | AIMessage | ToolMessage] = []
|
|
66
67
|
|
|
67
68
|
def setup_listeners(self, crewai_event_bus: Any) -> None:
|
|
69
|
+
# Lazy import to reduce memory overhead when ragas is not used
|
|
70
|
+
from ragas.messages import AIMessage
|
|
71
|
+
from ragas.messages import HumanMessage
|
|
72
|
+
from ragas.messages import ToolCall
|
|
73
|
+
from ragas.messages import ToolMessage
|
|
74
|
+
|
|
68
75
|
@crewai_event_bus.on(CrewKickoffStartedEvent)
|
|
69
76
|
def on_crew_execution_started(_: Any, event: Any) -> None:
|
|
70
77
|
self.messages.append(
|
|
@@ -586,6 +586,102 @@ class MicrosoftGraphClient:
|
|
|
586
586
|
f"Microsoft Graph API error {response.status_code}: {response.text}"
|
|
587
587
|
)
|
|
588
588
|
|
|
589
|
+
async def update_item_metadata(
|
|
590
|
+
self,
|
|
591
|
+
item_id: str,
|
|
592
|
+
fields_to_update: dict[str, Any],
|
|
593
|
+
site_id: str | None = None,
|
|
594
|
+
list_id: str | None = None,
|
|
595
|
+
drive_id: str | None = None,
|
|
596
|
+
) -> dict[str, Any]:
|
|
597
|
+
"""Update metadata on a SharePoint list item or OneDrive/SharePoint drive item.
|
|
598
|
+
|
|
599
|
+
For SharePoint list items: Updates custom column values via the fields endpoint.
|
|
600
|
+
For drive items: Updates properties like name and description.
|
|
601
|
+
|
|
602
|
+
Args:
|
|
603
|
+
item_id: The ID of the item to update.
|
|
604
|
+
fields_to_update: Key-value pairs of metadata fields to modify.
|
|
605
|
+
site_id: For SharePoint list items - the site ID.
|
|
606
|
+
list_id: For SharePoint list items - the list ID.
|
|
607
|
+
drive_id: For OneDrive/drive items - the drive ID.
|
|
608
|
+
|
|
609
|
+
Returns
|
|
610
|
+
-------
|
|
611
|
+
The API response containing updated item data.
|
|
612
|
+
|
|
613
|
+
Raises
|
|
614
|
+
------
|
|
615
|
+
MicrosoftGraphError: If validation fails or the API request fails.
|
|
616
|
+
"""
|
|
617
|
+
if not item_id or not item_id.strip():
|
|
618
|
+
raise MicrosoftGraphError("item_id cannot be empty")
|
|
619
|
+
if not fields_to_update:
|
|
620
|
+
raise MicrosoftGraphError("fields_to_update cannot be empty")
|
|
621
|
+
|
|
622
|
+
# Determine the endpoint based on provided parameters
|
|
623
|
+
has_sharepoint_context = site_id is not None and list_id is not None
|
|
624
|
+
has_drive_context = drive_id is not None
|
|
625
|
+
|
|
626
|
+
if has_sharepoint_context and has_drive_context:
|
|
627
|
+
raise MicrosoftGraphError(
|
|
628
|
+
"Cannot specify both SharePoint (site_id + list_id) and OneDrive "
|
|
629
|
+
"(document_library_id) context. Choose one."
|
|
630
|
+
)
|
|
631
|
+
|
|
632
|
+
if not has_sharepoint_context and not has_drive_context:
|
|
633
|
+
raise MicrosoftGraphError(
|
|
634
|
+
"Must specify either SharePoint context (site_id + list_id) or "
|
|
635
|
+
"OneDrive context (document_library_id)."
|
|
636
|
+
)
|
|
637
|
+
|
|
638
|
+
try:
|
|
639
|
+
if has_sharepoint_context:
|
|
640
|
+
# PATCH /sites/{site-id}/lists/{list-id}/items/{item-id}/fields
|
|
641
|
+
url = f"{GRAPH_API_BASE}/sites/{site_id}/lists/{list_id}/items/{item_id}/fields"
|
|
642
|
+
response = await self._client.patch(url, json=fields_to_update)
|
|
643
|
+
else:
|
|
644
|
+
# Drive item: PATCH /drives/{drive-id}/items/{item-id}
|
|
645
|
+
url = f"{GRAPH_API_BASE}/drives/{drive_id}/items/{item_id}"
|
|
646
|
+
response = await self._client.patch(url, json=fields_to_update)
|
|
647
|
+
|
|
648
|
+
response.raise_for_status()
|
|
649
|
+
return response.json()
|
|
650
|
+
except httpx.HTTPStatusError as e:
|
|
651
|
+
raise self._handle_update_metadata_error(e, item_id) from e
|
|
652
|
+
|
|
653
|
+
def _handle_update_metadata_error(
|
|
654
|
+
self,
|
|
655
|
+
error: httpx.HTTPStatusError,
|
|
656
|
+
item_id: str,
|
|
657
|
+
) -> MicrosoftGraphError:
|
|
658
|
+
"""Handle HTTP errors for metadata updates and return appropriate MicrosoftGraphError."""
|
|
659
|
+
status_code = error.response.status_code
|
|
660
|
+
error_msg = f"Failed to update metadata: HTTP {status_code}"
|
|
661
|
+
|
|
662
|
+
if status_code == 400:
|
|
663
|
+
try:
|
|
664
|
+
error_data = error.response.json()
|
|
665
|
+
api_message = error_data.get("error", {}).get("message", "Invalid request")
|
|
666
|
+
error_msg = f"Bad request updating metadata: {api_message}"
|
|
667
|
+
except Exception:
|
|
668
|
+
error_msg = "Bad request: invalid field names or values."
|
|
669
|
+
elif status_code == 401:
|
|
670
|
+
error_msg = "Authentication failed. Access token may be expired or invalid."
|
|
671
|
+
elif status_code == 403:
|
|
672
|
+
error_msg = (
|
|
673
|
+
f"Permission denied: you don't have permission to update item '{item_id}'. "
|
|
674
|
+
"Requires Sites.ReadWrite.All or Files.ReadWrite.All permission."
|
|
675
|
+
)
|
|
676
|
+
elif status_code == 404:
|
|
677
|
+
error_msg = f"Item '{item_id}' not found."
|
|
678
|
+
elif status_code == 409:
|
|
679
|
+
error_msg = f"Conflict: item '{item_id}' may have been modified concurrently."
|
|
680
|
+
elif status_code == 429:
|
|
681
|
+
error_msg = "Rate limit exceeded. Please try again later."
|
|
682
|
+
|
|
683
|
+
return MicrosoftGraphError(error_msg)
|
|
684
|
+
|
|
589
685
|
async def __aenter__(self) -> "MicrosoftGraphClient":
|
|
590
686
|
"""Async context manager entry."""
|
|
591
687
|
return self
|