dao-ai 0.1.8__py3-none-any.whl → 0.1.10__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.
- dao_ai/apps/__init__.py +24 -0
- dao_ai/apps/handlers.py +84 -0
- dao_ai/apps/model_serving.py +29 -0
- dao_ai/apps/resources.py +1029 -0
- dao_ai/apps/server.py +39 -0
- dao_ai/cli.py +62 -1
- dao_ai/config.py +120 -37
- dao_ai/memory/postgres.py +29 -4
- dao_ai/models.py +327 -370
- dao_ai/providers/base.py +28 -2
- dao_ai/providers/databricks.py +238 -4
- dao_ai/state.py +1 -0
- dao_ai/tools/mcp.py +165 -68
- {dao_ai-0.1.8.dist-info → dao_ai-0.1.10.dist-info}/METADATA +2 -2
- {dao_ai-0.1.8.dist-info → dao_ai-0.1.10.dist-info}/RECORD +18 -14
- dao_ai/agent_as_code.py +0 -22
- {dao_ai-0.1.8.dist-info → dao_ai-0.1.10.dist-info}/WHEEL +0 -0
- {dao_ai-0.1.8.dist-info → dao_ai-0.1.10.dist-info}/entry_points.txt +0 -0
- {dao_ai-0.1.8.dist-info → dao_ai-0.1.10.dist-info}/licenses/LICENSE +0 -0
dao_ai/providers/base.py
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
|
-
from typing import Any, Sequence
|
|
2
|
+
from typing import TYPE_CHECKING, Any, Sequence
|
|
3
3
|
|
|
4
4
|
from dao_ai.config import (
|
|
5
5
|
AppModel,
|
|
6
6
|
DatasetModel,
|
|
7
|
+
DeploymentTarget,
|
|
7
8
|
SchemaModel,
|
|
8
9
|
UnityCatalogFunctionSqlModel,
|
|
9
10
|
VectorStoreModel,
|
|
10
11
|
VolumeModel,
|
|
11
12
|
)
|
|
12
13
|
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from dao_ai.config import AppConfig
|
|
16
|
+
|
|
13
17
|
|
|
14
18
|
class ServiceProvider(ABC):
|
|
15
19
|
@abstractmethod
|
|
@@ -52,4 +56,26 @@ class ServiceProvider(ABC):
|
|
|
52
56
|
) -> Any: ...
|
|
53
57
|
|
|
54
58
|
@abstractmethod
|
|
55
|
-
def
|
|
59
|
+
def deploy_model_serving_agent(self, config: "AppConfig") -> Any:
|
|
60
|
+
"""Deploy agent to Databricks Model Serving endpoint."""
|
|
61
|
+
...
|
|
62
|
+
|
|
63
|
+
@abstractmethod
|
|
64
|
+
def deploy_apps_agent(self, config: "AppConfig") -> Any:
|
|
65
|
+
"""Deploy agent as a Databricks App."""
|
|
66
|
+
...
|
|
67
|
+
|
|
68
|
+
@abstractmethod
|
|
69
|
+
def deploy_agent(
|
|
70
|
+
self,
|
|
71
|
+
config: "AppConfig",
|
|
72
|
+
target: DeploymentTarget = DeploymentTarget.MODEL_SERVING,
|
|
73
|
+
) -> Any:
|
|
74
|
+
"""
|
|
75
|
+
Deploy agent to the specified target.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
config: The AppConfig containing deployment configuration
|
|
79
|
+
target: The deployment target (MODEL_SERVING or APPS)
|
|
80
|
+
"""
|
|
81
|
+
...
|
dao_ai/providers/databricks.py
CHANGED
|
@@ -23,7 +23,7 @@ from databricks.sdk.service.catalog import (
|
|
|
23
23
|
)
|
|
24
24
|
from databricks.sdk.service.database import DatabaseCredential
|
|
25
25
|
from databricks.sdk.service.iam import User
|
|
26
|
-
from databricks.sdk.service.workspace import GetSecretResponse
|
|
26
|
+
from databricks.sdk.service.workspace import GetSecretResponse, ImportFormat
|
|
27
27
|
from databricks.vector_search.client import VectorSearchClient
|
|
28
28
|
from databricks.vector_search.index import VectorSearchIndex
|
|
29
29
|
from loguru import logger
|
|
@@ -48,6 +48,7 @@ from dao_ai.config import (
|
|
|
48
48
|
DatabaseModel,
|
|
49
49
|
DatabricksAppModel,
|
|
50
50
|
DatasetModel,
|
|
51
|
+
DeploymentTarget,
|
|
51
52
|
FunctionModel,
|
|
52
53
|
GenieRoomModel,
|
|
53
54
|
HasFullName,
|
|
@@ -326,7 +327,7 @@ class DatabricksProvider(ServiceProvider):
|
|
|
326
327
|
raise FileNotFoundError(f"Code path does not exist: {path}")
|
|
327
328
|
|
|
328
329
|
model_root_path: Path = Path(dao_ai.__file__).parent
|
|
329
|
-
model_path: Path = model_root_path / "
|
|
330
|
+
model_path: Path = model_root_path / "apps" / "model_serving.py"
|
|
330
331
|
|
|
331
332
|
pip_requirements: Sequence[str] = config.app.pip_requirements
|
|
332
333
|
|
|
@@ -439,8 +440,19 @@ class DatabricksProvider(ServiceProvider):
|
|
|
439
440
|
version=aliased_model.version,
|
|
440
441
|
)
|
|
441
442
|
|
|
442
|
-
def
|
|
443
|
-
|
|
443
|
+
def deploy_model_serving_agent(self, config: AppConfig) -> None:
|
|
444
|
+
"""
|
|
445
|
+
Deploy agent to Databricks Model Serving endpoint.
|
|
446
|
+
|
|
447
|
+
This is the original deployment method that creates/updates a Model Serving
|
|
448
|
+
endpoint with the registered model.
|
|
449
|
+
|
|
450
|
+
Args:
|
|
451
|
+
config: The AppConfig containing deployment configuration
|
|
452
|
+
"""
|
|
453
|
+
logger.info(
|
|
454
|
+
"Deploying agent to Model Serving", endpoint_name=config.app.endpoint_name
|
|
455
|
+
)
|
|
444
456
|
mlflow.set_registry_uri("databricks-uc")
|
|
445
457
|
|
|
446
458
|
endpoint_name: str = config.app.endpoint_name
|
|
@@ -499,6 +511,228 @@ class DatabricksProvider(ServiceProvider):
|
|
|
499
511
|
permission_level=PermissionLevel[entitlement],
|
|
500
512
|
)
|
|
501
513
|
|
|
514
|
+
def deploy_apps_agent(self, config: AppConfig) -> None:
|
|
515
|
+
"""
|
|
516
|
+
Deploy agent as a Databricks App.
|
|
517
|
+
|
|
518
|
+
This method creates or updates a Databricks App that serves the agent
|
|
519
|
+
using the app_server module.
|
|
520
|
+
|
|
521
|
+
The deployment process:
|
|
522
|
+
1. Determine the workspace source path for the app
|
|
523
|
+
2. Upload the configuration file to the workspace
|
|
524
|
+
3. Create the app if it doesn't exist
|
|
525
|
+
4. Deploy the app
|
|
526
|
+
|
|
527
|
+
Args:
|
|
528
|
+
config: The AppConfig containing deployment configuration
|
|
529
|
+
|
|
530
|
+
Note:
|
|
531
|
+
The config file must be loaded via AppConfig.from_file() so that
|
|
532
|
+
the source_config_path is available for upload.
|
|
533
|
+
"""
|
|
534
|
+
import io
|
|
535
|
+
|
|
536
|
+
from databricks.sdk.service.apps import (
|
|
537
|
+
App,
|
|
538
|
+
AppDeployment,
|
|
539
|
+
AppDeploymentMode,
|
|
540
|
+
AppDeploymentState,
|
|
541
|
+
)
|
|
542
|
+
|
|
543
|
+
# Normalize app name: lowercase, replace underscores with dashes
|
|
544
|
+
raw_name: str = config.app.name
|
|
545
|
+
app_name: str = raw_name.lower().replace("_", "-")
|
|
546
|
+
if app_name != raw_name:
|
|
547
|
+
logger.info(
|
|
548
|
+
"Normalized app name for Databricks Apps",
|
|
549
|
+
original=raw_name,
|
|
550
|
+
normalized=app_name,
|
|
551
|
+
)
|
|
552
|
+
logger.info("Deploying agent to Databricks Apps", app_name=app_name)
|
|
553
|
+
|
|
554
|
+
# Use convention-based workspace path: /Workspace/Users/{user}/apps/{app_name}
|
|
555
|
+
current_user: User = self.w.current_user.me()
|
|
556
|
+
user_name: str = current_user.user_name or "default"
|
|
557
|
+
source_path: str = f"/Workspace/Users/{user_name}/apps/{app_name}"
|
|
558
|
+
|
|
559
|
+
logger.info("Using workspace source path", source_path=source_path)
|
|
560
|
+
|
|
561
|
+
# Upload the configuration file to the workspace
|
|
562
|
+
source_config_path: str | None = config.source_config_path
|
|
563
|
+
if source_config_path:
|
|
564
|
+
# Read the config file and upload to workspace
|
|
565
|
+
config_file_name: str = "model_config.yaml"
|
|
566
|
+
workspace_config_path: str = f"{source_path}/{config_file_name}"
|
|
567
|
+
|
|
568
|
+
logger.info(
|
|
569
|
+
"Uploading config file to workspace",
|
|
570
|
+
source=source_config_path,
|
|
571
|
+
destination=workspace_config_path,
|
|
572
|
+
)
|
|
573
|
+
|
|
574
|
+
# Read the source config file
|
|
575
|
+
with open(source_config_path, "rb") as f:
|
|
576
|
+
config_content: bytes = f.read()
|
|
577
|
+
|
|
578
|
+
# Create the directory if it doesn't exist and upload the file
|
|
579
|
+
try:
|
|
580
|
+
self.w.workspace.mkdirs(source_path)
|
|
581
|
+
except Exception as e:
|
|
582
|
+
logger.debug(f"Directory may already exist: {e}")
|
|
583
|
+
|
|
584
|
+
# Upload the config file
|
|
585
|
+
self.w.workspace.upload(
|
|
586
|
+
path=workspace_config_path,
|
|
587
|
+
content=io.BytesIO(config_content),
|
|
588
|
+
format=ImportFormat.AUTO,
|
|
589
|
+
overwrite=True,
|
|
590
|
+
)
|
|
591
|
+
logger.info("Config file uploaded", path=workspace_config_path)
|
|
592
|
+
else:
|
|
593
|
+
logger.warning(
|
|
594
|
+
"No source config path available. "
|
|
595
|
+
"Ensure DAO_AI_CONFIG_PATH is set in the app environment or "
|
|
596
|
+
"model_config.yaml exists in the app source directory."
|
|
597
|
+
)
|
|
598
|
+
|
|
599
|
+
# Generate and upload app.yaml with dynamically discovered resources
|
|
600
|
+
from dao_ai.apps.resources import generate_app_yaml
|
|
601
|
+
|
|
602
|
+
app_yaml_content: str = generate_app_yaml(
|
|
603
|
+
config,
|
|
604
|
+
command=[
|
|
605
|
+
"/bin/bash",
|
|
606
|
+
"-c",
|
|
607
|
+
"pip install dao-ai && python -m dao_ai.apps.server",
|
|
608
|
+
],
|
|
609
|
+
include_resources=True,
|
|
610
|
+
)
|
|
611
|
+
|
|
612
|
+
app_yaml_path: str = f"{source_path}/app.yaml"
|
|
613
|
+
self.w.workspace.upload(
|
|
614
|
+
path=app_yaml_path,
|
|
615
|
+
content=io.BytesIO(app_yaml_content.encode("utf-8")),
|
|
616
|
+
format=ImportFormat.AUTO,
|
|
617
|
+
overwrite=True,
|
|
618
|
+
)
|
|
619
|
+
logger.info("app.yaml with resources uploaded", path=app_yaml_path)
|
|
620
|
+
|
|
621
|
+
# Generate SDK resources from the config
|
|
622
|
+
from dao_ai.apps.resources import (
|
|
623
|
+
generate_sdk_resources,
|
|
624
|
+
generate_user_api_scopes,
|
|
625
|
+
)
|
|
626
|
+
|
|
627
|
+
sdk_resources = generate_sdk_resources(config)
|
|
628
|
+
if sdk_resources:
|
|
629
|
+
logger.info(
|
|
630
|
+
"Discovered app resources from config",
|
|
631
|
+
resource_count=len(sdk_resources),
|
|
632
|
+
resources=[r.name for r in sdk_resources],
|
|
633
|
+
)
|
|
634
|
+
|
|
635
|
+
# Generate user API scopes for on-behalf-of-user resources
|
|
636
|
+
user_api_scopes = generate_user_api_scopes(config)
|
|
637
|
+
if user_api_scopes:
|
|
638
|
+
logger.info(
|
|
639
|
+
"Discovered user API scopes for OBO resources",
|
|
640
|
+
scopes=user_api_scopes,
|
|
641
|
+
)
|
|
642
|
+
|
|
643
|
+
# Check if app exists
|
|
644
|
+
app_exists: bool = False
|
|
645
|
+
try:
|
|
646
|
+
existing_app: App = self.w.apps.get(name=app_name)
|
|
647
|
+
app_exists = True
|
|
648
|
+
logger.debug("App already exists, updating", app_name=app_name)
|
|
649
|
+
except NotFound:
|
|
650
|
+
logger.debug("Creating new app", app_name=app_name)
|
|
651
|
+
|
|
652
|
+
# Create or update the app with resources and user_api_scopes
|
|
653
|
+
if not app_exists:
|
|
654
|
+
logger.info("Creating Databricks App", app_name=app_name)
|
|
655
|
+
app_spec = App(
|
|
656
|
+
name=app_name,
|
|
657
|
+
description=config.app.description or f"DAO AI Agent: {app_name}",
|
|
658
|
+
resources=sdk_resources if sdk_resources else None,
|
|
659
|
+
user_api_scopes=user_api_scopes if user_api_scopes else None,
|
|
660
|
+
)
|
|
661
|
+
app: App = self.w.apps.create_and_wait(app=app_spec)
|
|
662
|
+
logger.info("App created", app_name=app.name, app_url=app.url)
|
|
663
|
+
else:
|
|
664
|
+
app = existing_app
|
|
665
|
+
# Update resources and scopes on existing app
|
|
666
|
+
if sdk_resources or user_api_scopes:
|
|
667
|
+
logger.info("Updating app resources and scopes", app_name=app_name)
|
|
668
|
+
updated_app = App(
|
|
669
|
+
name=app_name,
|
|
670
|
+
description=config.app.description or app.description,
|
|
671
|
+
resources=sdk_resources if sdk_resources else None,
|
|
672
|
+
user_api_scopes=user_api_scopes if user_api_scopes else None,
|
|
673
|
+
)
|
|
674
|
+
app = self.w.apps.update(name=app_name, app=updated_app)
|
|
675
|
+
logger.info("App resources and scopes updated", app_name=app_name)
|
|
676
|
+
|
|
677
|
+
# Deploy the app with source code
|
|
678
|
+
# The app will use the dao_ai.apps.server module as the entry point
|
|
679
|
+
logger.info("Deploying app", app_name=app_name)
|
|
680
|
+
|
|
681
|
+
# Create deployment configuration
|
|
682
|
+
app_deployment = AppDeployment(
|
|
683
|
+
mode=AppDeploymentMode.SNAPSHOT,
|
|
684
|
+
source_code_path=source_path,
|
|
685
|
+
)
|
|
686
|
+
|
|
687
|
+
# Deploy the app
|
|
688
|
+
deployment: AppDeployment = self.w.apps.deploy_and_wait(
|
|
689
|
+
app_name=app_name,
|
|
690
|
+
app_deployment=app_deployment,
|
|
691
|
+
)
|
|
692
|
+
|
|
693
|
+
if (
|
|
694
|
+
deployment.status
|
|
695
|
+
and deployment.status.state == AppDeploymentState.SUCCEEDED
|
|
696
|
+
):
|
|
697
|
+
logger.info(
|
|
698
|
+
"App deployed successfully",
|
|
699
|
+
app_name=app_name,
|
|
700
|
+
deployment_id=deployment.deployment_id,
|
|
701
|
+
app_url=app.url if app else None,
|
|
702
|
+
)
|
|
703
|
+
else:
|
|
704
|
+
status_message: str = (
|
|
705
|
+
deployment.status.message if deployment.status else "Unknown error"
|
|
706
|
+
)
|
|
707
|
+
logger.error(
|
|
708
|
+
"App deployment failed",
|
|
709
|
+
app_name=app_name,
|
|
710
|
+
status=status_message,
|
|
711
|
+
)
|
|
712
|
+
raise RuntimeError(f"App deployment failed: {status_message}")
|
|
713
|
+
|
|
714
|
+
def deploy_agent(
|
|
715
|
+
self,
|
|
716
|
+
config: AppConfig,
|
|
717
|
+
target: DeploymentTarget = DeploymentTarget.MODEL_SERVING,
|
|
718
|
+
) -> None:
|
|
719
|
+
"""
|
|
720
|
+
Deploy agent to the specified target.
|
|
721
|
+
|
|
722
|
+
This is the main deployment method that routes to the appropriate
|
|
723
|
+
deployment implementation based on the target.
|
|
724
|
+
|
|
725
|
+
Args:
|
|
726
|
+
config: The AppConfig containing deployment configuration
|
|
727
|
+
target: The deployment target (MODEL_SERVING or APPS)
|
|
728
|
+
"""
|
|
729
|
+
if target == DeploymentTarget.MODEL_SERVING:
|
|
730
|
+
self.deploy_model_serving_agent(config)
|
|
731
|
+
elif target == DeploymentTarget.APPS:
|
|
732
|
+
self.deploy_apps_agent(config)
|
|
733
|
+
else:
|
|
734
|
+
raise ValueError(f"Unknown deployment target: {target}")
|
|
735
|
+
|
|
502
736
|
def create_catalog(self, schema: SchemaModel) -> CatalogInfo:
|
|
503
737
|
catalog_info: CatalogInfo
|
|
504
738
|
try:
|
dao_ai/state.py
CHANGED
dao_ai/tools/mcp.py
CHANGED
|
@@ -261,12 +261,12 @@ def _extract_text_content(result: CallToolResult) -> str:
|
|
|
261
261
|
return "\n".join(text_parts)
|
|
262
262
|
|
|
263
263
|
|
|
264
|
-
def
|
|
264
|
+
async def _afetch_tools_from_server(function: McpFunctionModel) -> list[Tool]:
|
|
265
265
|
"""
|
|
266
|
-
Fetch raw MCP tools from the server.
|
|
266
|
+
Async version: Fetch raw MCP tools from the server.
|
|
267
267
|
|
|
268
|
-
This is the
|
|
269
|
-
and
|
|
268
|
+
This is the primary async implementation that handles the actual MCP connection
|
|
269
|
+
and tool listing. It's used by both alist_mcp_tools() and acreate_mcp_tools().
|
|
270
270
|
|
|
271
271
|
Args:
|
|
272
272
|
function: The MCP function model configuration.
|
|
@@ -280,14 +280,10 @@ def _fetch_tools_from_server(function: McpFunctionModel) -> list[Tool]:
|
|
|
280
280
|
connection_config = _build_connection_config(function)
|
|
281
281
|
client = MultiServerMCPClient({"mcp_function": connection_config})
|
|
282
282
|
|
|
283
|
-
|
|
284
|
-
"""Async helper to list tools from MCP server."""
|
|
283
|
+
try:
|
|
285
284
|
async with client.session("mcp_function") as session:
|
|
286
285
|
result = await session.list_tools()
|
|
287
286
|
return result.tools if hasattr(result, "tools") else list(result)
|
|
288
|
-
|
|
289
|
-
try:
|
|
290
|
-
return asyncio.run(_list_tools_async())
|
|
291
287
|
except Exception as e:
|
|
292
288
|
if function.connection:
|
|
293
289
|
logger.error(
|
|
@@ -312,57 +308,48 @@ def _fetch_tools_from_server(function: McpFunctionModel) -> list[Tool]:
|
|
|
312
308
|
) from e
|
|
313
309
|
|
|
314
310
|
|
|
315
|
-
def
|
|
316
|
-
function: McpFunctionModel,
|
|
317
|
-
apply_filters: bool = True,
|
|
318
|
-
) -> list[MCPToolInfo]:
|
|
311
|
+
def _fetch_tools_from_server(function: McpFunctionModel) -> list[Tool]:
|
|
319
312
|
"""
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
This function connects to an MCP server and returns information about
|
|
323
|
-
all available tools. It's designed for:
|
|
324
|
-
- Tool discovery and exploration
|
|
325
|
-
- UI-based tool selection (e.g., in DAO AI Builder)
|
|
326
|
-
- Debugging and validation of MCP configurations
|
|
313
|
+
Sync wrapper: Fetch raw MCP tools from the server.
|
|
327
314
|
|
|
328
|
-
|
|
329
|
-
display tools in a UI and allow users to select which tools to use.
|
|
315
|
+
For async contexts, use _afetch_tools_from_server() directly.
|
|
330
316
|
|
|
331
317
|
Args:
|
|
332
|
-
function: The MCP function model configuration
|
|
333
|
-
- Connection details (url, connection, headers, etc.)
|
|
334
|
-
- Optional filtering (include_tools, exclude_tools)
|
|
335
|
-
apply_filters: Whether to apply include_tools/exclude_tools filters.
|
|
336
|
-
Set to False to get the complete list of available tools
|
|
337
|
-
regardless of filter configuration. Default True.
|
|
318
|
+
function: The MCP function model configuration.
|
|
338
319
|
|
|
339
320
|
Returns:
|
|
340
|
-
List of
|
|
341
|
-
Each contains name, description, and input_schema.
|
|
321
|
+
List of raw MCP Tool objects from the server.
|
|
342
322
|
|
|
343
323
|
Raises:
|
|
344
324
|
RuntimeError: If connection to MCP server fails.
|
|
325
|
+
"""
|
|
326
|
+
return asyncio.run(_afetch_tools_from_server(function))
|
|
345
327
|
|
|
346
|
-
Example:
|
|
347
|
-
# List all tools from a DBSQL MCP server
|
|
348
|
-
from dao_ai.config import McpFunctionModel
|
|
349
|
-
from dao_ai.tools.mcp import list_mcp_tools
|
|
350
328
|
|
|
351
|
-
|
|
352
|
-
|
|
329
|
+
async def alist_mcp_tools(
|
|
330
|
+
function: McpFunctionModel,
|
|
331
|
+
apply_filters: bool = True,
|
|
332
|
+
) -> list[MCPToolInfo]:
|
|
333
|
+
"""
|
|
334
|
+
Async version: List available tools from an MCP server.
|
|
335
|
+
|
|
336
|
+
This is the primary async implementation for tool discovery.
|
|
337
|
+
For sync contexts, use list_mcp_tools() instead.
|
|
353
338
|
|
|
354
|
-
|
|
355
|
-
|
|
339
|
+
Args:
|
|
340
|
+
function: The MCP function model configuration.
|
|
341
|
+
apply_filters: Whether to apply include_tools/exclude_tools filters.
|
|
356
342
|
|
|
357
|
-
|
|
358
|
-
|
|
343
|
+
Returns:
|
|
344
|
+
List of MCPToolInfo objects describing available tools.
|
|
359
345
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
This function is for discovery/display purposes only.
|
|
346
|
+
Raises:
|
|
347
|
+
RuntimeError: If connection to MCP server fails.
|
|
363
348
|
"""
|
|
364
349
|
mcp_url = function.mcp_url
|
|
365
|
-
logger.debug(
|
|
350
|
+
logger.debug(
|
|
351
|
+
"Listing MCP tools (async)", mcp_url=mcp_url, apply_filters=apply_filters
|
|
352
|
+
)
|
|
366
353
|
|
|
367
354
|
# Log connection type
|
|
368
355
|
if function.connection:
|
|
@@ -378,8 +365,8 @@ def list_mcp_tools(
|
|
|
378
365
|
mcp_url=mcp_url,
|
|
379
366
|
)
|
|
380
367
|
|
|
381
|
-
# Fetch tools from server
|
|
382
|
-
mcp_tools: list[Tool] =
|
|
368
|
+
# Fetch tools from server (async)
|
|
369
|
+
mcp_tools: list[Tool] = await _afetch_tools_from_server(function)
|
|
383
370
|
|
|
384
371
|
# Log discovered tools
|
|
385
372
|
logger.info(
|
|
@@ -433,45 +420,155 @@ def list_mcp_tools(
|
|
|
433
420
|
return tool_infos
|
|
434
421
|
|
|
435
422
|
|
|
436
|
-
def
|
|
423
|
+
def list_mcp_tools(
|
|
437
424
|
function: McpFunctionModel,
|
|
438
|
-
|
|
425
|
+
apply_filters: bool = True,
|
|
426
|
+
) -> list[MCPToolInfo]:
|
|
439
427
|
"""
|
|
440
|
-
|
|
428
|
+
Sync wrapper: List available tools from an MCP server.
|
|
429
|
+
|
|
430
|
+
For async contexts, use alist_mcp_tools() directly.
|
|
431
|
+
|
|
432
|
+
Args:
|
|
433
|
+
function: The MCP function model configuration.
|
|
434
|
+
apply_filters: Whether to apply include_tools/exclude_tools filters.
|
|
441
435
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
436
|
+
Returns:
|
|
437
|
+
List of MCPToolInfo objects describing available tools.
|
|
438
|
+
|
|
439
|
+
Raises:
|
|
440
|
+
RuntimeError: If connection to MCP server fails.
|
|
441
|
+
"""
|
|
442
|
+
return asyncio.run(alist_mcp_tools(function, apply_filters))
|
|
445
443
|
|
|
446
|
-
This function:
|
|
447
|
-
1. Fetches available tools from the MCP server
|
|
448
|
-
2. Applies include_tools/exclude_tools filters
|
|
449
|
-
3. Wraps each tool for LangChain agent execution
|
|
450
444
|
|
|
451
|
-
|
|
445
|
+
async def acreate_mcp_tools(
|
|
446
|
+
function: McpFunctionModel,
|
|
447
|
+
) -> Sequence[RunnableLike]:
|
|
448
|
+
"""
|
|
449
|
+
Async version: Create executable LangChain tools for invoking Databricks MCP functions.
|
|
452
450
|
|
|
453
|
-
|
|
451
|
+
This is the primary async implementation. For sync contexts, use create_mcp_tools().
|
|
454
452
|
|
|
455
453
|
Args:
|
|
456
|
-
function: The MCP function model configuration
|
|
457
|
-
- Connection details (url, connection, headers, etc.)
|
|
458
|
-
- Optional filtering (include_tools, exclude_tools)
|
|
454
|
+
function: The MCP function model configuration.
|
|
459
455
|
|
|
460
456
|
Returns:
|
|
461
457
|
A sequence of LangChain tools that can be used by agents.
|
|
462
458
|
|
|
463
459
|
Raises:
|
|
464
460
|
RuntimeError: If connection to MCP server fails.
|
|
461
|
+
"""
|
|
462
|
+
mcp_url = function.mcp_url
|
|
463
|
+
logger.debug("Creating MCP tools (async)", mcp_url=mcp_url)
|
|
464
|
+
|
|
465
|
+
# Fetch tools from server (async)
|
|
466
|
+
mcp_tools: list[Tool] = await _afetch_tools_from_server(function)
|
|
467
|
+
|
|
468
|
+
# Log discovered tools
|
|
469
|
+
logger.info(
|
|
470
|
+
"Discovered MCP tools from server",
|
|
471
|
+
tools_count=len(mcp_tools),
|
|
472
|
+
tool_names=[t.name for t in mcp_tools],
|
|
473
|
+
mcp_url=mcp_url,
|
|
474
|
+
)
|
|
475
|
+
|
|
476
|
+
# Apply filtering if configured
|
|
477
|
+
if function.include_tools or function.exclude_tools:
|
|
478
|
+
original_count = len(mcp_tools)
|
|
479
|
+
mcp_tools = [
|
|
480
|
+
tool
|
|
481
|
+
for tool in mcp_tools
|
|
482
|
+
if _should_include_tool(
|
|
483
|
+
tool.name,
|
|
484
|
+
function.include_tools,
|
|
485
|
+
function.exclude_tools,
|
|
486
|
+
)
|
|
487
|
+
]
|
|
488
|
+
filtered_count = original_count - len(mcp_tools)
|
|
489
|
+
|
|
490
|
+
logger.info(
|
|
491
|
+
"Filtered MCP tools",
|
|
492
|
+
original_count=original_count,
|
|
493
|
+
filtered_count=filtered_count,
|
|
494
|
+
final_count=len(mcp_tools),
|
|
495
|
+
include_patterns=function.include_tools,
|
|
496
|
+
exclude_patterns=function.exclude_tools,
|
|
497
|
+
)
|
|
498
|
+
|
|
499
|
+
# Log final tool list
|
|
500
|
+
for mcp_tool in mcp_tools:
|
|
501
|
+
logger.debug(
|
|
502
|
+
"MCP tool available",
|
|
503
|
+
tool_name=mcp_tool.name,
|
|
504
|
+
tool_description=(
|
|
505
|
+
mcp_tool.description[:100] if mcp_tool.description else None
|
|
506
|
+
),
|
|
507
|
+
)
|
|
508
|
+
|
|
509
|
+
def _create_tool_wrapper(mcp_tool: Tool) -> RunnableLike:
|
|
510
|
+
"""
|
|
511
|
+
Create a LangChain tool wrapper for an MCP tool.
|
|
512
|
+
"""
|
|
513
|
+
|
|
514
|
+
@create_tool(
|
|
515
|
+
mcp_tool.name,
|
|
516
|
+
description=mcp_tool.description or f"MCP tool: {mcp_tool.name}",
|
|
517
|
+
args_schema=mcp_tool.inputSchema,
|
|
518
|
+
)
|
|
519
|
+
async def tool_wrapper(**kwargs: Any) -> str:
|
|
520
|
+
"""Execute MCP tool with fresh session."""
|
|
521
|
+
logger.trace("Invoking MCP tool", tool_name=mcp_tool.name, args=kwargs)
|
|
522
|
+
|
|
523
|
+
invocation_client = MultiServerMCPClient(
|
|
524
|
+
{"mcp_function": _build_connection_config(function)}
|
|
525
|
+
)
|
|
526
|
+
|
|
527
|
+
try:
|
|
528
|
+
async with invocation_client.session("mcp_function") as session:
|
|
529
|
+
result: CallToolResult = await session.call_tool(
|
|
530
|
+
mcp_tool.name, kwargs
|
|
531
|
+
)
|
|
532
|
+
|
|
533
|
+
text_result = _extract_text_content(result)
|
|
534
|
+
|
|
535
|
+
logger.trace(
|
|
536
|
+
"MCP tool completed",
|
|
537
|
+
tool_name=mcp_tool.name,
|
|
538
|
+
result_length=len(text_result),
|
|
539
|
+
)
|
|
540
|
+
|
|
541
|
+
return text_result
|
|
542
|
+
|
|
543
|
+
except Exception as e:
|
|
544
|
+
logger.error(
|
|
545
|
+
"MCP tool failed",
|
|
546
|
+
tool_name=mcp_tool.name,
|
|
547
|
+
error=str(e),
|
|
548
|
+
)
|
|
549
|
+
raise
|
|
550
|
+
|
|
551
|
+
return tool_wrapper
|
|
552
|
+
|
|
553
|
+
return [_create_tool_wrapper(tool) for tool in mcp_tools]
|
|
465
554
|
|
|
466
|
-
Example:
|
|
467
|
-
from dao_ai.config import McpFunctionModel
|
|
468
|
-
from dao_ai.tools.mcp import create_mcp_tools
|
|
469
555
|
|
|
470
|
-
|
|
471
|
-
|
|
556
|
+
def create_mcp_tools(
|
|
557
|
+
function: McpFunctionModel,
|
|
558
|
+
) -> Sequence[RunnableLike]:
|
|
559
|
+
"""
|
|
560
|
+
Sync wrapper: Create executable LangChain tools for invoking Databricks MCP functions.
|
|
472
561
|
|
|
473
|
-
|
|
474
|
-
|
|
562
|
+
For async contexts, use acreate_mcp_tools() directly.
|
|
563
|
+
|
|
564
|
+
Args:
|
|
565
|
+
function: The MCP function model configuration.
|
|
566
|
+
|
|
567
|
+
Returns:
|
|
568
|
+
A sequence of LangChain tools that can be used by agents.
|
|
569
|
+
|
|
570
|
+
Raises:
|
|
571
|
+
RuntimeError: If connection to MCP server fails.
|
|
475
572
|
"""
|
|
476
573
|
mcp_url = function.mcp_url
|
|
477
574
|
logger.debug("Creating MCP tools", mcp_url=mcp_url)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dao-ai
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.10
|
|
4
4
|
Summary: DAO AI: A modular, multi-agent orchestration framework for complex AI workflows. Supports agent handoff, tool integration, and dynamic configuration via YAML.
|
|
5
5
|
Project-URL: Homepage, https://github.com/natefleming/dao-ai
|
|
6
6
|
Project-URL: Documentation, https://natefleming.github.io/dao-ai
|
|
@@ -43,7 +43,7 @@ Requires-Dist: langgraph>=1.0.5
|
|
|
43
43
|
Requires-Dist: langmem>=0.0.30
|
|
44
44
|
Requires-Dist: loguru>=0.7.3
|
|
45
45
|
Requires-Dist: mcp>=1.24.0
|
|
46
|
-
Requires-Dist: mlflow>=3.8.1
|
|
46
|
+
Requires-Dist: mlflow[databricks]>=3.8.1
|
|
47
47
|
Requires-Dist: nest-asyncio>=1.6.0
|
|
48
48
|
Requires-Dist: openevals>=0.1.3
|
|
49
49
|
Requires-Dist: openpyxl>=3.1.5
|