idun-agent-engine 0.3.4__py3-none-any.whl → 0.3.6__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.
- idun_agent_engine/_version.py +1 -1
- idun_agent_engine/core/config_builder.py +9 -3
- idun_agent_engine/guardrails/base.py +1 -1
- idun_agent_engine/guardrails/guardrails_hub/__init__.py +0 -0
- idun_agent_engine/guardrails/guardrails_hub/guardrails_hub.py +42 -37
- idun_agent_engine/server/lifespan.py +1 -1
- idun_agent_engine/server/routers/agent.py +6 -0
- {idun_agent_engine-0.3.4.dist-info → idun_agent_engine-0.3.6.dist-info}/METADATA +1 -1
- {idun_agent_engine-0.3.4.dist-info → idun_agent_engine-0.3.6.dist-info}/RECORD +11 -10
- {idun_agent_engine-0.3.4.dist-info → idun_agent_engine-0.3.6.dist-info}/WHEEL +0 -0
- {idun_agent_engine-0.3.4.dist-info → idun_agent_engine-0.3.6.dist-info}/entry_points.txt +0 -0
idun_agent_engine/_version.py
CHANGED
|
@@ -4,6 +4,7 @@ This module provides a fluent API for building configuration objects using Pydan
|
|
|
4
4
|
This approach ensures type safety, validation, and consistency with the rest of the codebase.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
+
import os
|
|
7
8
|
from pathlib import Path
|
|
8
9
|
from typing import Any
|
|
9
10
|
|
|
@@ -24,6 +25,7 @@ from yaml import YAMLError
|
|
|
24
25
|
|
|
25
26
|
from ..agent.base import BaseAgent
|
|
26
27
|
from .engine_config import AgentConfig, EngineConfig, ServerConfig
|
|
28
|
+
from idun_agent_schema.manager.guardrail_configs import convert_guardrail
|
|
27
29
|
|
|
28
30
|
|
|
29
31
|
class ConfigBuilder:
|
|
@@ -119,10 +121,14 @@ class ConfigBuilder:
|
|
|
119
121
|
f"Failed to parse yaml file for Engine config: {e}"
|
|
120
122
|
) from e
|
|
121
123
|
try:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
124
|
+
guardrails_data = yaml_config.get("engine_config", {}).get("guardrails")
|
|
125
|
+
|
|
126
|
+
if not guardrails_data:
|
|
125
127
|
self._guardrails = None
|
|
128
|
+
else:
|
|
129
|
+
converted_data = convert_guardrail(guardrails_data)
|
|
130
|
+
self._guardrails = Guardrails.model_validate(converted_data)
|
|
131
|
+
|
|
126
132
|
except Exception as e:
|
|
127
133
|
raise YAMLError(f"Failed to parse yaml file for Guardrails: {e}") from e
|
|
128
134
|
|
|
File without changes
|
|
@@ -2,26 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
from guardrails import Guard
|
|
4
4
|
from idun_agent_schema.engine.guardrails import Guardrail as GuardrailSchema
|
|
5
|
-
from idun_agent_schema.engine.
|
|
6
|
-
GuardrailType,
|
|
7
|
-
)
|
|
5
|
+
from idun_agent_schema.engine.guardrails_v2 import GuardrailConfigId
|
|
8
6
|
|
|
9
7
|
from ..base import BaseGuardrail
|
|
10
8
|
|
|
11
9
|
|
|
12
|
-
def get_guard_instance(name:
|
|
10
|
+
def get_guard_instance(name: GuardrailConfigId) -> Guard:
|
|
13
11
|
"""Returns a map of guard type -> guard instance."""
|
|
14
|
-
if name == "
|
|
12
|
+
if name.value == "ban_list":
|
|
15
13
|
from guardrails.hub import BanList
|
|
16
14
|
|
|
17
15
|
return BanList
|
|
18
16
|
|
|
19
|
-
elif name == "
|
|
17
|
+
elif name.value == "detect_pii":
|
|
18
|
+
from guardrails.hub import DetectPII
|
|
19
|
+
|
|
20
|
+
return DetectPII
|
|
21
|
+
|
|
22
|
+
elif name.value == "nsfw":
|
|
20
23
|
from guardrails.hub import NSFWText
|
|
21
24
|
|
|
22
25
|
return NSFWText
|
|
23
26
|
|
|
24
|
-
elif name == "
|
|
27
|
+
elif name.value == "competitor_check":
|
|
25
28
|
from guardrails.hub import CompetitorCheck
|
|
26
29
|
|
|
27
30
|
return CompetitorCheck
|
|
@@ -36,14 +39,9 @@ class GuardrailsHubGuard(BaseGuardrail):
|
|
|
36
39
|
def __init__(self, config: GuardrailSchema, position: str) -> None:
|
|
37
40
|
super().__init__(config)
|
|
38
41
|
|
|
39
|
-
self.
|
|
40
|
-
self.
|
|
41
|
-
|
|
42
|
-
if self._guard_type == GuardrailType.GUARDRAILS_HUB:
|
|
43
|
-
self._guard_url = self._guardrail_config.config["guard_url"]
|
|
44
|
-
|
|
45
|
-
self.reject_message: str = self._guard_config["reject_message"]
|
|
46
|
-
self._install_model()
|
|
42
|
+
self.guard_id = self._guardrail_config.config_id
|
|
43
|
+
self._guard_url = self._guardrail_config.guard_url
|
|
44
|
+
self.reject_message: str = self._guardrail_config.reject_message
|
|
47
45
|
self._guard: Guard | None = self.setup_guard()
|
|
48
46
|
self.position: str = position
|
|
49
47
|
|
|
@@ -53,43 +51,50 @@ class GuardrailsHubGuard(BaseGuardrail):
|
|
|
53
51
|
from guardrails import install
|
|
54
52
|
|
|
55
53
|
try:
|
|
56
|
-
api_key = self._guardrail_config.
|
|
57
|
-
|
|
54
|
+
api_key = self._guardrail_config.api_key
|
|
55
|
+
|
|
56
|
+
print("Configuring guardrails with token...")
|
|
57
|
+
result = subprocess.run(
|
|
58
58
|
[
|
|
59
59
|
"guardrails",
|
|
60
60
|
"configure",
|
|
61
61
|
"--token",
|
|
62
62
|
api_key,
|
|
63
|
-
"--disable-remote-inferencing",
|
|
63
|
+
"--disable-remote-inferencing",
|
|
64
64
|
"--disable-metrics",
|
|
65
65
|
],
|
|
66
66
|
check=True,
|
|
67
|
+
capture_output=True,
|
|
68
|
+
text=True,
|
|
67
69
|
)
|
|
70
|
+
print(f"Configure output: {result.stdout}")
|
|
71
|
+
if result.stderr:
|
|
72
|
+
print(f"Configure stderr: {result.stderr}")
|
|
68
73
|
print(f"Installing model: {self._guard_url}..")
|
|
69
|
-
install(self._guard_url, quiet=
|
|
74
|
+
install(self._guard_url, quiet=False, install_local_models=True)
|
|
75
|
+
print(f"Successfully installed: {self._guard_url}")
|
|
76
|
+
except subprocess.CalledProcessError as e:
|
|
77
|
+
raise OSError(
|
|
78
|
+
f"Cannot configure guardrails: stdout={e.stdout}, stderr={e.stderr}"
|
|
79
|
+
) from e
|
|
70
80
|
except Exception as e:
|
|
71
|
-
raise
|
|
81
|
+
raise e
|
|
72
82
|
|
|
73
83
|
def setup_guard(self) -> Guard | None:
|
|
74
84
|
"""Installs and configures the guard based on its yaml config."""
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
f"Guard: {self.guard_type} is not yet supported, or does not exist."
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
guard_instance_params = self._guardrail_config.config.get(
|
|
85
|
-
"guard_config", {}
|
|
85
|
+
self._install_model()
|
|
86
|
+
guard_name = self.guard_id
|
|
87
|
+
guard = get_guard_instance(guard_name)
|
|
88
|
+
if guard is None:
|
|
89
|
+
raise ValueError(
|
|
90
|
+
f"Guard: {self.guard_id} is not yet supported, or does not exist."
|
|
86
91
|
)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
|
|
93
|
+
guard_instance_params = self._guardrail_config.guard_params.model_dump()
|
|
94
|
+
guard_instance = guard(**guard_instance_params)
|
|
95
|
+
for param, value in guard_instance_params.items():
|
|
96
|
+
setattr(guard_instance, param, value)
|
|
97
|
+
return guard_instance
|
|
93
98
|
|
|
94
99
|
def validate(self, input: str) -> bool:
|
|
95
100
|
"""TODO."""
|
|
@@ -22,7 +22,7 @@ def _parse_guardrails(guardrails_obj: Guardrails) -> Sequence[BaseGuardrail]:
|
|
|
22
22
|
|
|
23
23
|
from ..guardrails.guardrails_hub.guardrails_hub import GuardrailsHubGuard as GHGuard
|
|
24
24
|
|
|
25
|
-
if not guardrails_obj
|
|
25
|
+
if not guardrails_obj:
|
|
26
26
|
return []
|
|
27
27
|
|
|
28
28
|
return [GHGuard(guard, position="input") for guard in guardrails_obj.input] + [
|
|
@@ -95,6 +95,7 @@ async def stream(
|
|
|
95
95
|
):
|
|
96
96
|
"""Process a message with the agent, streaming ag-ui events."""
|
|
97
97
|
try:
|
|
98
|
+
|
|
98
99
|
async def event_stream():
|
|
99
100
|
message = {"query": request.query, "session_id": request.session_id}
|
|
100
101
|
async for event in agent.stream(message):
|
|
@@ -114,6 +115,11 @@ async def copilotkit_stream(
|
|
|
114
115
|
],
|
|
115
116
|
):
|
|
116
117
|
"""Process a message with the agent, streaming ag-ui events."""
|
|
118
|
+
guardrails = getattr(request.app.state, "guardrails", [])
|
|
119
|
+
if guardrails:
|
|
120
|
+
_run_guardrails(
|
|
121
|
+
guardrails, message=input_data.messages[-1].content, position="input"
|
|
122
|
+
)
|
|
117
123
|
if isinstance(copilotkit_agent, LangGraphAGUIAgent):
|
|
118
124
|
try:
|
|
119
125
|
# Get the accept header from the request
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: idun-agent-engine
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.6
|
|
4
4
|
Summary: Python SDK and runtime to serve AI agents with FastAPI, LangGraph, and observability.
|
|
5
5
|
Project-URL: Homepage, https://github.com/geoffreyharrazi/idun-agent-platform
|
|
6
6
|
Project-URL: Repository, https://github.com/geoffreyharrazi/idun-agent-platform
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
idun_agent_engine/__init__.py,sha256=PhOL6foq5V0eXaoXw7xKUeCWXIWrOHrAFB8OuJnBqyM,550
|
|
2
|
-
idun_agent_engine/_version.py,sha256=
|
|
2
|
+
idun_agent_engine/_version.py,sha256=qOzk7siFRtqtf3NUtjI6msjuZS0-FpPHkAz7nmx9w5U,72
|
|
3
3
|
idun_agent_engine/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
idun_agent_engine/agent/__init__.py,sha256=foyOoRdI_04q1b6f2A5EXEpWSCKjZxpgWMWrKcsHNl8,220
|
|
5
5
|
idun_agent_engine/agent/base.py,sha256=c-3gljSHQpm6aY0JNDmXkaPtcW55rXdsI8Cgv9l4bCs,3294
|
|
@@ -13,12 +13,13 @@ idun_agent_engine/agent/langgraph/__init__.py,sha256=CoBdkp9P4livdy5B0bvj9o7ftoq
|
|
|
13
13
|
idun_agent_engine/agent/langgraph/langgraph.py,sha256=vM5ppt0s_2izzZVbVXXGXGCVUGSN-GZhvQ5-6YbOgVM,22904
|
|
14
14
|
idun_agent_engine/core/__init__.py,sha256=F0DMDlWcSWS_1dvh3xMbrdcVvZRHVnoAFFgREuSJfBI,408
|
|
15
15
|
idun_agent_engine/core/app_factory.py,sha256=XiLrctFT_n8LP3flKFwJoJDbiWPiw98N9lbkpR8P1O0,2597
|
|
16
|
-
idun_agent_engine/core/config_builder.py,sha256=
|
|
16
|
+
idun_agent_engine/core/config_builder.py,sha256=HpKrWwpohuArICyuOd-0eUQMG0PP2ZfhZzRGjLP9yck,25841
|
|
17
17
|
idun_agent_engine/core/engine_config.py,sha256=IR8WhbenDstNSL7ORrUW8AnzgS3exFQxtwip66pFhcM,545
|
|
18
18
|
idun_agent_engine/core/server_runner.py,sha256=vLlgLQM-xyvFgJMgFW2eWZoN1oc0x9FGL6bH8WsF6O8,4897
|
|
19
19
|
idun_agent_engine/guardrails/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
-
idun_agent_engine/guardrails/base.py,sha256=
|
|
21
|
-
idun_agent_engine/guardrails/guardrails_hub/
|
|
20
|
+
idun_agent_engine/guardrails/base.py,sha256=rvi7gcuKK8-3GtGicWzMWYsKKv0g3LjGBI-FycxgKVU,814
|
|
21
|
+
idun_agent_engine/guardrails/guardrails_hub/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
|
+
idun_agent_engine/guardrails/guardrails_hub/guardrails_hub.py,sha256=DgcUIDy9_bcVcpYVvDJowFe_QVlCpEkr8hntPRgRmS0,3456
|
|
22
23
|
idun_agent_engine/guardrails/guardrails_hub/utils.py,sha256=bC6-MsCVF7xKTr48z7OzJJUeWvqAB7BiHeNTiKsme70,20
|
|
23
24
|
idun_agent_engine/mcp/__init__.py,sha256=tsX4sJa7UZD-lr8O1acMwDrdDWJc_hMlB9IrX1NH8Wk,255
|
|
24
25
|
idun_agent_engine/mcp/helpers.py,sha256=aFiLlk63pifBjGgctREFWxuSbb-um6QDOVpyikQ5NJ0,3224
|
|
@@ -37,10 +38,10 @@ idun_agent_engine/observability/phoenix_local/__init__.py,sha256=m9dIw1GWGKAW4wP
|
|
|
37
38
|
idun_agent_engine/observability/phoenix_local/phoenix_local_handler.py,sha256=wjOZuMpAxdD5D33rzxycNEzFMunETpPnYjiHjbjz5GA,4252
|
|
38
39
|
idun_agent_engine/server/__init__.py,sha256=WaFektUsy37bNg2niAUy_TykzStukgWPnxC-t49CEwo,177
|
|
39
40
|
idun_agent_engine/server/dependencies.py,sha256=MVH8STOQ8wu-iYE_28y5dvw5FGT5PX0uQl0ldkpxw6Y,2080
|
|
40
|
-
idun_agent_engine/server/lifespan.py,sha256=
|
|
41
|
+
idun_agent_engine/server/lifespan.py,sha256=sp1EaCRKHblRFwYHWWNQzuD3deFiFpb06QlSutvoZRo,3832
|
|
41
42
|
idun_agent_engine/server/server_config.py,sha256=RYA7Y0c5aRw_WXaX8svFUIEtTPqzn3o-WQRm2p52C6g,213
|
|
42
43
|
idun_agent_engine/server/routers/__init__.py,sha256=BgNzSVvHtGPGn5zhXhomwpKlDYBkeFi7xCbdcWVOgc8,102
|
|
43
|
-
idun_agent_engine/server/routers/agent.py,sha256=
|
|
44
|
+
idun_agent_engine/server/routers/agent.py,sha256=qLaVRKgMIu-YfOi-tPEzLNRZKZ4DaZEQ8KQ-4HrWbbY,9194
|
|
44
45
|
idun_agent_engine/server/routers/agui.py,sha256=Z1G4fuo57MazQWfp7ao8QZ1or2H9BXLS_JB1nFPXAkE,1891
|
|
45
46
|
idun_agent_engine/server/routers/base.py,sha256=wICOXCokCIRjmHuDPDTWqeXqOVPes1CtDtiR_HvtsF0,3756
|
|
46
47
|
idun_agent_engine/templates/__init__.py,sha256=xxbJZXaX6VEm_UrqzAOQcuujpEji5yqYzwQfwiqig8o,31
|
|
@@ -54,7 +55,7 @@ idun_platform_cli/groups/agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5
|
|
|
54
55
|
idun_platform_cli/groups/agent/main.py,sha256=QMGQi3JZ76SeFI3miIjVWpMt0L-hGz5FwxtTPQX4-Uw,301
|
|
55
56
|
idun_platform_cli/groups/agent/package.py,sha256=LdIFAcfrlUcCssmSliYQIi0NFMuVkpx6t8WhMHATan8,2525
|
|
56
57
|
idun_platform_cli/groups/agent/serve.py,sha256=2AbL0G1WqR33jlyiGaNvAoPZ3G1o52KYUptz_HaAjIg,3863
|
|
57
|
-
idun_agent_engine-0.3.
|
|
58
|
-
idun_agent_engine-0.3.
|
|
59
|
-
idun_agent_engine-0.3.
|
|
60
|
-
idun_agent_engine-0.3.
|
|
58
|
+
idun_agent_engine-0.3.6.dist-info/METADATA,sha256=Bz5cHt9CCJaNrzOnPj7ne174MKCw_Imm9pZNxT-D0j4,10648
|
|
59
|
+
idun_agent_engine-0.3.6.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
60
|
+
idun_agent_engine-0.3.6.dist-info/entry_points.txt,sha256=XG3oxlSOaCrYKT1oyhKa0Ag1iJPMZ-WF6gaV_mzIJW4,52
|
|
61
|
+
idun_agent_engine-0.3.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|