dao-ai 0.1.2__py3-none-any.whl → 0.1.20__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 +105 -0
- dao_ai/apps/model_serving.py +29 -0
- dao_ai/apps/resources.py +1122 -0
- dao_ai/apps/server.py +39 -0
- dao_ai/cli.py +546 -37
- dao_ai/config.py +1179 -139
- dao_ai/evaluation.py +543 -0
- dao_ai/genie/__init__.py +55 -7
- dao_ai/genie/cache/__init__.py +34 -7
- dao_ai/genie/cache/base.py +143 -2
- dao_ai/genie/cache/context_aware/__init__.py +31 -0
- dao_ai/genie/cache/context_aware/base.py +1151 -0
- dao_ai/genie/cache/context_aware/in_memory.py +609 -0
- dao_ai/genie/cache/context_aware/persistent.py +802 -0
- dao_ai/genie/cache/context_aware/postgres.py +1166 -0
- dao_ai/genie/cache/core.py +1 -1
- dao_ai/genie/cache/lru.py +257 -75
- dao_ai/genie/cache/optimization.py +890 -0
- dao_ai/genie/core.py +235 -11
- dao_ai/memory/postgres.py +175 -39
- dao_ai/middleware/__init__.py +38 -0
- dao_ai/middleware/assertions.py +3 -3
- dao_ai/middleware/context_editing.py +230 -0
- dao_ai/middleware/core.py +4 -4
- dao_ai/middleware/guardrails.py +3 -3
- dao_ai/middleware/human_in_the_loop.py +3 -2
- dao_ai/middleware/message_validation.py +4 -4
- dao_ai/middleware/model_call_limit.py +77 -0
- dao_ai/middleware/model_retry.py +121 -0
- dao_ai/middleware/pii.py +157 -0
- dao_ai/middleware/summarization.py +1 -1
- dao_ai/middleware/tool_call_limit.py +210 -0
- dao_ai/middleware/tool_retry.py +174 -0
- dao_ai/middleware/tool_selector.py +129 -0
- dao_ai/models.py +327 -370
- dao_ai/nodes.py +9 -16
- dao_ai/orchestration/core.py +33 -9
- dao_ai/orchestration/supervisor.py +29 -13
- dao_ai/orchestration/swarm.py +6 -1
- dao_ai/{prompts.py → prompts/__init__.py} +12 -61
- dao_ai/prompts/instructed_retriever_decomposition.yaml +58 -0
- dao_ai/prompts/instruction_reranker.yaml +14 -0
- dao_ai/prompts/router.yaml +37 -0
- dao_ai/prompts/verifier.yaml +46 -0
- dao_ai/providers/base.py +28 -2
- dao_ai/providers/databricks.py +363 -33
- dao_ai/state.py +1 -0
- dao_ai/tools/__init__.py +5 -3
- dao_ai/tools/genie.py +103 -26
- dao_ai/tools/instructed_retriever.py +366 -0
- dao_ai/tools/instruction_reranker.py +202 -0
- dao_ai/tools/mcp.py +539 -97
- dao_ai/tools/router.py +89 -0
- dao_ai/tools/slack.py +13 -2
- dao_ai/tools/sql.py +7 -3
- dao_ai/tools/unity_catalog.py +32 -10
- dao_ai/tools/vector_search.py +493 -160
- dao_ai/tools/verifier.py +159 -0
- dao_ai/utils.py +182 -2
- dao_ai/vector_search.py +46 -1
- {dao_ai-0.1.2.dist-info → dao_ai-0.1.20.dist-info}/METADATA +45 -9
- dao_ai-0.1.20.dist-info/RECORD +89 -0
- dao_ai/agent_as_code.py +0 -22
- dao_ai/genie/cache/semantic.py +0 -970
- dao_ai-0.1.2.dist-info/RECORD +0 -64
- {dao_ai-0.1.2.dist-info → dao_ai-0.1.20.dist-info}/WHEEL +0 -0
- {dao_ai-0.1.2.dist-info → dao_ai-0.1.20.dist-info}/entry_points.txt +0 -0
- {dao_ai-0.1.2.dist-info → dao_ai-0.1.20.dist-info}/licenses/LICENSE +0 -0
dao_ai/apps/__init__.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Databricks Apps deployment module for dao-ai.
|
|
3
|
+
|
|
4
|
+
This subpackage contains all modules related to deploying dao-ai agents
|
|
5
|
+
as Databricks Apps or Model Serving endpoints.
|
|
6
|
+
|
|
7
|
+
Modules:
|
|
8
|
+
handlers: MLflow AgentServer request handlers (@invoke, @stream)
|
|
9
|
+
server: Entry point for Databricks Apps deployment
|
|
10
|
+
resources: Databricks App resource configuration generation
|
|
11
|
+
model_serving: Entry point for Databricks Model Serving deployment
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from dao_ai.apps.resources import (
|
|
15
|
+
generate_app_resources,
|
|
16
|
+
generate_app_yaml,
|
|
17
|
+
generate_sdk_resources,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"generate_app_resources",
|
|
22
|
+
"generate_app_yaml",
|
|
23
|
+
"generate_sdk_resources",
|
|
24
|
+
]
|
dao_ai/apps/handlers.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Agent request handlers for MLflow AgentServer.
|
|
3
|
+
|
|
4
|
+
This module defines the invoke and stream handlers that are registered
|
|
5
|
+
with the MLflow AgentServer. These handlers delegate to the ResponsesAgent
|
|
6
|
+
created from the dao-ai configuration.
|
|
7
|
+
|
|
8
|
+
The handlers use async methods (apredict, apredict_stream) to be compatible
|
|
9
|
+
with both Databricks Model Serving and Databricks Apps environments.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
from typing import AsyncGenerator
|
|
14
|
+
|
|
15
|
+
import mlflow
|
|
16
|
+
from dotenv import load_dotenv
|
|
17
|
+
from mlflow.genai.agent_server import get_request_headers, invoke, stream
|
|
18
|
+
from mlflow.types.responses import (
|
|
19
|
+
ResponsesAgentRequest,
|
|
20
|
+
ResponsesAgentResponse,
|
|
21
|
+
ResponsesAgentStreamEvent,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
from dao_ai.config import AppConfig
|
|
25
|
+
from dao_ai.logging import configure_logging
|
|
26
|
+
from dao_ai.models import LanggraphResponsesAgent
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _inject_headers_into_request(request: ResponsesAgentRequest) -> None:
|
|
30
|
+
"""Inject request headers into custom_inputs for Context propagation.
|
|
31
|
+
|
|
32
|
+
Captures headers from the MLflow AgentServer context (where they're available)
|
|
33
|
+
and injects them into request.custom_inputs.configurable.headers so they
|
|
34
|
+
flow through to Context and can be used for OBO authentication.
|
|
35
|
+
"""
|
|
36
|
+
headers: dict[str, str] = get_request_headers()
|
|
37
|
+
if headers:
|
|
38
|
+
if request.custom_inputs is None:
|
|
39
|
+
request.custom_inputs = {}
|
|
40
|
+
if "configurable" not in request.custom_inputs:
|
|
41
|
+
request.custom_inputs["configurable"] = {}
|
|
42
|
+
request.custom_inputs["configurable"]["headers"] = headers
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# Load environment variables from .env.local if it exists
|
|
46
|
+
load_dotenv(dotenv_path=".env.local", override=True)
|
|
47
|
+
|
|
48
|
+
# Configure MLflow
|
|
49
|
+
mlflow.set_registry_uri("databricks-uc")
|
|
50
|
+
mlflow.set_tracking_uri("databricks")
|
|
51
|
+
mlflow.langchain.autolog()
|
|
52
|
+
|
|
53
|
+
# Get config path from environment or use default
|
|
54
|
+
config_path: str = os.environ.get("DAO_AI_CONFIG_PATH", "dao_ai.yaml")
|
|
55
|
+
|
|
56
|
+
# Load configuration using AppConfig.from_file (consistent with CLI, notebook, builder)
|
|
57
|
+
config: AppConfig = AppConfig.from_file(config_path)
|
|
58
|
+
|
|
59
|
+
# Configure logging
|
|
60
|
+
if config.app and config.app.log_level:
|
|
61
|
+
configure_logging(level=config.app.log_level)
|
|
62
|
+
|
|
63
|
+
# Create the ResponsesAgent - cast to LanggraphResponsesAgent to access async methods
|
|
64
|
+
_responses_agent: LanggraphResponsesAgent = config.as_responses_agent() # type: ignore[assignment]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@invoke()
|
|
68
|
+
async def non_streaming(request: ResponsesAgentRequest) -> ResponsesAgentResponse:
|
|
69
|
+
"""
|
|
70
|
+
Handle non-streaming requests by delegating to the ResponsesAgent.
|
|
71
|
+
|
|
72
|
+
Uses the async apredict() method for compatibility with both
|
|
73
|
+
Model Serving and Apps environments.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
request: The incoming ResponsesAgentRequest
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
ResponsesAgentResponse with the complete output
|
|
80
|
+
"""
|
|
81
|
+
# Capture headers while in the AgentServer async context (before they're lost)
|
|
82
|
+
_inject_headers_into_request(request)
|
|
83
|
+
return await _responses_agent.apredict(request)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@stream()
|
|
87
|
+
async def streaming(
|
|
88
|
+
request: ResponsesAgentRequest,
|
|
89
|
+
) -> AsyncGenerator[ResponsesAgentStreamEvent, None]:
|
|
90
|
+
"""
|
|
91
|
+
Handle streaming requests by delegating to the ResponsesAgent.
|
|
92
|
+
|
|
93
|
+
Uses the async apredict_stream() method for compatibility with both
|
|
94
|
+
Model Serving and Apps environments.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
request: The incoming ResponsesAgentRequest
|
|
98
|
+
|
|
99
|
+
Yields:
|
|
100
|
+
ResponsesAgentStreamEvent objects as they are generated
|
|
101
|
+
"""
|
|
102
|
+
# Capture headers while in the AgentServer async context (before they're lost)
|
|
103
|
+
_inject_headers_into_request(request)
|
|
104
|
+
async for event in _responses_agent.apredict_stream(request):
|
|
105
|
+
yield event
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Apply nest_asyncio FIRST before any other imports
|
|
2
|
+
# This allows dao-ai's async/sync patterns to work in Model Serving
|
|
3
|
+
# where there may already be an event loop running (e.g., notebook context)
|
|
4
|
+
import nest_asyncio
|
|
5
|
+
|
|
6
|
+
nest_asyncio.apply()
|
|
7
|
+
|
|
8
|
+
import mlflow # noqa: E402
|
|
9
|
+
from mlflow.models import ModelConfig # noqa: E402
|
|
10
|
+
from mlflow.pyfunc import ResponsesAgent # noqa: E402
|
|
11
|
+
|
|
12
|
+
from dao_ai.config import AppConfig # noqa: E402
|
|
13
|
+
from dao_ai.logging import configure_logging # noqa: E402
|
|
14
|
+
|
|
15
|
+
mlflow.set_registry_uri("databricks-uc")
|
|
16
|
+
mlflow.set_tracking_uri("databricks")
|
|
17
|
+
|
|
18
|
+
mlflow.langchain.autolog()
|
|
19
|
+
|
|
20
|
+
model_config: ModelConfig = ModelConfig()
|
|
21
|
+
config: AppConfig = AppConfig(**model_config.to_dict())
|
|
22
|
+
|
|
23
|
+
log_level: str = config.app.log_level
|
|
24
|
+
|
|
25
|
+
configure_logging(level=log_level)
|
|
26
|
+
|
|
27
|
+
app: ResponsesAgent = config.as_responses_agent()
|
|
28
|
+
|
|
29
|
+
mlflow.models.set_model(app)
|