Skip to content

Commit 651a7dd

Browse files
viswa-uipathclaude
andcommitted
refactor(core): type EvaluatorProtocol returns as AuditRecord
Closes doc item 1.2 — every ``evaluate_*`` method on ``EvaluatorProtocol`` returned ``-> Any``, forcing callers to downcast to the type they already knew the concrete evaluator was returning. The concrete ``GovernanceEvaluator`` in uipath-runtime-python already declares ``-> AuditRecord`` on each per-hook method, so narrowing the protocol contract is structurally compatible — no behavior change, no downstream code change required. Narrows the six evaluate_* return types (before_agent / after_agent / before_model / after_model / tool_call / after_tool) from Any to AuditRecord, imports the type from uipath.core.governance.models, and refreshes the class docstring (was claiming the protocol is intentionally Any because the audit record "lives in the plugin package" — but AuditRecord lives right here in uipath-core). Verified - ruff clean, mypy clean (45 source files), 230 passed + 1 skipped in uipath-core. - uipath-runtime-python's test suite (357 passed + 1 skipped) keeps green when this version of uipath-core is installed — the protocol- conformance tests in test_evaluator.py still pass because the concrete GovernanceEvaluator was already returning AuditRecord from every evaluate_* method. Rides on the same 0.5.23 version bump as the previous commit — both changes ship together as one public-surface change on uipath-core. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent da282a9 commit 651a7dd

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

packages/uipath-core/src/uipath/core/adapters/evaluator.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
"""Structural contract for the policy evaluator an adapter talks to.
1+
"""Structural contract for the policy evaluator a framework plugin talks to.
22
3-
Framework adapters call into a policy evaluator at each lifecycle hook.
3+
Framework plugins call into a policy evaluator at each lifecycle hook.
44
Concrete evaluator implementations (the native runtime evaluator, a
55
Microsoft AGT bridge, a composite, …) live in packages outside
6-
``uipath-core`` — adapters depend only on this structural protocol so
6+
``uipath-core`` — plugins depend only on this structural protocol so
77
they can be swapped against any of them without code change.
88
99
``EvaluatorProtocol`` is a :class:`typing.Protocol` so any class whose
@@ -15,15 +15,18 @@
1515

1616
from typing import Any, Protocol, runtime_checkable
1717

18+
from uipath.core.governance.models import AuditRecord
19+
1820

1921
@runtime_checkable
2022
class EvaluatorProtocol(Protocol):
21-
"""Structural protocol an adapter expects from a policy evaluator.
23+
"""Structural protocol a framework plugin expects from a policy evaluator.
2224
23-
Return types are intentionally :class:`typing.Any`: the concrete
24-
audit record shape lives in the plugin package that owns the
25-
evaluator and the policy model. Adapters in that package cast the
26-
return value back to the concrete type they know.
25+
Every ``evaluate_*`` method returns an :class:`AuditRecord` — the
26+
per-hook audit envelope holding the per-rule
27+
:class:`RuleEvaluation` list, the final action, and the trace /
28+
agent metadata. Callers get a typed result; no downcasting is
29+
required.
2730
"""
2831

2932
def evaluate_before_agent(
@@ -34,7 +37,7 @@ def evaluate_before_agent(
3437
trace_id: str,
3538
model_name: str = "",
3639
**kwargs: Any,
37-
) -> Any:
40+
) -> AuditRecord:
3841
"""Evaluate BEFORE_AGENT rules."""
3942
...
4043

@@ -45,7 +48,7 @@ def evaluate_after_agent(
4548
runtime_id: str,
4649
trace_id: str,
4750
**kwargs: Any,
48-
) -> Any:
51+
) -> AuditRecord:
4952
"""Evaluate AFTER_AGENT rules."""
5053
...
5154

@@ -58,7 +61,7 @@ def evaluate_before_model(
5861
messages: list[dict[str, Any]] | None = None,
5962
model_name: str = "",
6063
**kwargs: Any,
61-
) -> Any:
64+
) -> AuditRecord:
6265
"""Evaluate BEFORE_MODEL rules."""
6366
...
6467

@@ -69,7 +72,7 @@ def evaluate_after_model(
6972
runtime_id: str,
7073
trace_id: str,
7174
**kwargs: Any,
72-
) -> Any:
75+
) -> AuditRecord:
7376
"""Evaluate AFTER_MODEL rules."""
7477
...
7578

@@ -82,7 +85,7 @@ def evaluate_tool_call(
8285
trace_id: str,
8386
session_state: dict[str, Any] | None = None,
8487
**kwargs: Any,
85-
) -> Any:
88+
) -> AuditRecord:
8689
"""Evaluate TOOL_CALL rules."""
8790
...
8891

@@ -94,6 +97,6 @@ def evaluate_after_tool(
9497
runtime_id: str,
9598
trace_id: str,
9699
**kwargs: Any,
97-
) -> Any:
100+
) -> AuditRecord:
98101
"""Evaluate AFTER_TOOL rules."""
99102
...

0 commit comments

Comments
 (0)