feat: Add OpenAI Agents SDK adapter#31
Conversation
|
Caution Review failedFailed to post review comments 📝 WalkthroughWalkthroughAdds AgentWatchOpenAIAgentsAdapter to convert OpenAI Agents SDK lifecycle hooks into AgentWatch events (session start/end, tool call/result, planner handoff), with argument normalization and truncated outputs, plus tests and docs showing installation and usage. ChangesOpenAI Agents SDK Adapter Support
Sequence Diagram(s)sequenceDiagram
participant OpenAISDK as OpenAI Agents SDK
participant Adapter as AgentWatchOpenAIAgentsAdapter
participant EventBus as EventBus
OpenAISDK->>Adapter: on_agent_start(agent)
Adapter->>Adapter: _base() construct AgentEvent
Adapter->>EventBus: emit SESSION_START with agent_name
OpenAISDK->>Adapter: on_tool_call(tool_call)
Adapter->>Adapter: extract tool_name, parse arguments
Adapter->>EventBus: emit TOOL_CALL with ToolCallData
OpenAISDK->>Adapter: on_tool_result(result)
Adapter->>EventBus: emit TOOL_RESULT with output
OpenAISDK->>Adapter: on_handoff(source, target)
Adapter->>EventBus: emit PLANNER_OUTPUT with metadata
OpenAISDK->>Adapter: on_agent_end(agent)
Adapter->>EventBus: emit SESSION_END with status
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d67ef46a-0f7f-4d9d-8e73-e410c59f8535
📒 Files selected for processing (4)
README.mdagentwatch/adapters/openai_agents.pydocs/getting-started.mdtests/test_openai_agents_adapter.py
sreerevanth
left a comment
There was a problem hiding this comment.
Great work on this 🚀
Before merge, please address the CodeRabbit note regarding agent_name.
The top-level AgentEvent.agent_name should reflect the actual runtime agent name rather than the static "openai_agents" value, since downstream consumers may rely on it for filtering/display.
Once that’s updated, this should be good to merge.
|
Tests pass ✅ (5/5 — session lifecycle, tool call/result, handoff, string args, bad JSON args all green). One change needed before merge:
In Fix in def _base(self, event_type: EventType, run_id: str | None = None, agent: Any = None) -> AgentEvent:
event = AgentEvent(
session_id=self.session_id,
agent_id=self.agent_id,
agent_name=getattr(agent, 'name', None) or 'openai_agents', # dynamic
framework=AgentFramework.OPENAI_AGENTS,
event_type=event_type,
step_number=self._step_up(),
)Then pass |
|
Thanks @omkartike! Rebased locally onto current However, the maintainer's earlier change-request is still open. agent_name="openai_agents",while lines 71 and 77 already extract the real runtime name into Please update line 57 to something like: agent_name=getattr(agent, "name", "openai_agents"),(and probably do the same for the other Also: please rebase onto current git fetch upstream
git checkout add-openai-agents-adapter
git rebase upstream/main
# fix line 57 and re-amend if needed
git push --force-with-leaseHolding off on merge until those land. The adapter itself is solid, just need this last cleanup. Label: level: advanced | NSoC 26' |
|
@sreerevanth fixed the issues can you review and let me know if there's anything needed to be add/update |
|
❌ Tests pass but merge is blocked by a pending review request. Please fix the following before this can be merged: Issue (from repo owner @sreerevanth): In What needs fixing:
Once this is addressed, all 5 adapter tests still pass and the PR will be ready to merge. |
Summary
Resolves #3 . This PR introduces a new adapter to natively support the OpenAI Agents SDK, converting its lifecycle hooks into AgentWatch Universal Events for full observability.
What Changed
agentwatch/adapters/openai_agents.pywithAgentWatchOpenAIAgentsAdapter.on_agent_start,on_agent_end,on_tool_call,on_tool_result,on_handoff) to AgentWatchAgentEventstructures.tests/test_openai_agents_adapter.pyvalidating session lifecycle, tool execution, handoff, and argument parsing error resilience.README.mdanddocs/getting-started.mdwith installation commands and example usage for the new OpenAI Agents integration.Validation
pytest)Summary by CodeRabbit
New Features
Documentation
Tests