Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/uipath-pydantic-ai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies = [
"pydantic-ai>=1.63.0, <2.0.0",
"openinference-instrumentation-pydantic-ai>=0.1.12",
"uipath>=2.10.2, <2.11.0",
"uipath-core>=0.5.18, <0.7.0",
"uipath-runtime>=0.11.0, <0.12.0",
]
classifiers = [
Expand All @@ -27,6 +28,9 @@ register = "uipath_pydantic_ai.middlewares:register_middleware"
[project.entry-points."uipath.runtime.factories"]
pydantic-ai = "uipath_pydantic_ai.runtime:register_runtime_factory"

[project.entry-points."uipath.governance.adapters"]
pydantic-ai = "uipath_pydantic_ai.governance:register_governance_adapter"

[project.urls]
Homepage = "https://uipath.com"
Repository = "https://github.com/UiPath/uipath-integrations-python"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Governance integration for ``uipath-pydantic-ai``.

Registers :class:`PydanticAIAdapter` with the adapter registry in
``uipath.core.adapters`` so the governance host can attach the
Pydantic-AI-specific governance (BEFORE_MODEL, AFTER_MODEL, TOOL_CALL,
AFTER_TOOL) when it sees a ``pydantic_ai.Agent``.

Registration is **idempotent**: calling :func:`register_governance_adapter`
twice is a no-op on the second call.

Wiring: the package exposes :func:`register_governance_adapter` as an entry
point under ``uipath.governance.adapters``. The governance adapter discovery
path calls it to register the adapter. Importing this module does not, by
itself, mutate the global registry.
"""

from __future__ import annotations

import logging

from uipath.core.adapters import get_adapter_registry

from .adapter import GovernanceCallbacks, GovernanceModel, PydanticAIAdapter

logger = logging.getLogger(__name__)

_registered: bool = False


def register_governance_adapter() -> None:
"""Register :class:`PydanticAIAdapter` with the global registry.

Idempotent — safe to call multiple times.
"""
global _registered
if _registered:
return
registry = get_adapter_registry()
if any(a.name == "PydanticAI" for a in registry.get_all()):
_registered = True
return
registry.register(PydanticAIAdapter())
_registered = True
logger.debug("Registered uipath-pydantic-ai governance adapter")


__all__ = [
"GovernanceCallbacks",
"GovernanceModel",
"PydanticAIAdapter",
"register_governance_adapter",
]
Loading
Loading