Skip to content

Commit db7b42a

Browse files
aditik0303claude
andcommitted
refactor(governance): rename OpenAI adapter.py -> hooks.py for #899 consistency
The module is no longer an adapter (no BaseAdapter). Name the file after its native seam — agent hooks — matching how the LangChain integration (#899) uses callbacks.py. Renames adapter.py->hooks.py and test_adapter.py->test_hooks.py; updates imports + docstrings. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent e0c7d86 commit db7b42a

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

packages/uipath-openai-agents/src/uipath_openai_agents/governance/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from __future__ import annotations
1414

15-
from .adapter import GovernanceAgentHooks, install_governance
15+
from .hooks import GovernanceAgentHooks, install_governance
1616

1717
__all__ = [
1818
"GovernanceAgentHooks",

packages/uipath-openai-agents/src/uipath_openai_agents/governance/adapter.py renamed to packages/uipath-openai-agents/src/uipath_openai_agents/governance/hooks.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
"""OpenAI Agents adapter for UiPath governance.
1+
"""OpenAI Agents governance hooks for UiPath.
22
33
Provides governance for OpenAI Agents SDK agents (``agents.Agent`` and any
4-
graph of agents reachable via ``handoffs``). Like the Google ADK adapter
5-
and unlike the LangChain adapter, which wraps a ``Runnable`` and intercepts
4+
graph of agents reachable via ``handoffs``). Like the Google ADK integration
5+
and unlike the LangChain one, which wraps a ``Runnable`` and intercepts
66
``invoke`` / ``ainvoke`` — OpenAI Agents are executed by ``Runner.run`` /
77
``Runner.run_streamed``, which hold their **own** reference to the agent
88
object. Replacing ``runtime.agent`` with a proxy would never reach the
9-
``Runner``. So this adapter installs governance directly onto each agent's
10-
native ``hooks`` attribute (an :class:`agents.AgentHooks`), mutating it in
11-
place:
9+
``Runner``. So :func:`install_governance` installs governance directly onto
10+
each agent's native ``hooks`` attribute (an :class:`agents.AgentHooks`),
11+
mutating it in place:
1212
1313
- ``on_llm_start`` → BEFORE_MODEL
1414
- ``on_llm_end`` → AFTER_MODEL
1515
- ``on_tool_start`` → TOOL_CALL
1616
- ``on_tool_end`` → AFTER_TOOL
1717
18-
Because the mutation is in place, :meth:`OpenAIAgentsAdapter.attach` returns
19-
the **original agent** (hooks installed) rather than a wrapping proxy.
18+
Because the mutation is in place, :func:`install_governance` returns the
19+
**original agent** (hooks installed) rather than a wrapping proxy.
2020
``agents.Agent`` validates that ``hooks`` is an ``AgentHooks`` instance, so
21-
:class:`GovernanceAgentHooks` subclasses it (the ADK adapter could duck-type
22-
its callbacks; here the SDK type-checks the slot).
21+
:class:`GovernanceAgentHooks` subclasses it (the ADK integration could
22+
duck-type its callbacks; here the SDK type-checks the slot).
2323
2424
``agent.hooks`` holds a **single** ``AgentHooks`` (not a list, as in ADK), so
2525
when an agent already carries user hooks we *chain*: governance runs first,
26-
then the previously-installed hooks. ``detach`` restores the original.
26+
then the previously-installed hooks.
2727
2828
Chain-level boundaries (BEFORE_AGENT / AFTER_AGENT) are owned by the
2929
governance host, so they are not fired here — that would duplicate every

packages/uipath-openai-agents/tests/governance/test_adapter.py renamed to packages/uipath-openai-agents/tests/governance/test_hooks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Unit tests for the OpenAI Agents governance adapter.
1+
"""Unit tests for the OpenAI Agents governance hooks.
22
33
``can_handle`` is tested against a real ``agents.Agent``; everything else
44
duck-types the OpenAI Agents payloads (response input/output items, tools)
@@ -20,7 +20,7 @@
2020
import pytest
2121
from uipath.core.governance.exceptions import GovernanceBlockException
2222

23-
from uipath_openai_agents.governance.adapter import (
23+
from uipath_openai_agents.governance.hooks import (
2424
_BEFORE_MODEL_TEXT_CAP,
2525
GovernanceAgentHooks,
2626
install_governance,

0 commit comments

Comments
 (0)