feat(extensions): add Agentspan execution backend#2923
feat(extensions): add Agentspan execution backend#2923manan164 wants to merge 1 commit intoopenai:mainfrom
Conversation
Adds AgentspanRunner — a drop-in replacement for Runner that executes agents on Agentspan instead of directly against OpenAI. Agentspan (https://agentspan.ai) adds durability, observability, human-in-the-loop, and horizontal scaling to any agent built with the OpenAI Agents SDK, without changing how agents are defined or how tools are written. Migration: change one import line # Before from agents import Runner # After from agents.extensions.agentspan import AgentspanRunner as Runner Everything else — Agent, @function_tool, result.final_output — is unchanged. Agentspan accepts openai-agents Agent objects directly and translates them to its execution engine transparently. Changes: - src/agents/extensions/agentspan.py: AgentspanRunner + AgentspanRunResult - src/agents/extensions/__init__.py: lazy export of AgentspanRunner - pyproject.toml: agentspan optional dependency
|
While we don't have this module as part of this core SDK, please feel free to share it as your own package. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1fb172f32f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| on_invoke = ft.on_invoke_tool | ||
|
|
||
| def _sync_wrapper(**kwargs: Any) -> Any: | ||
| result = on_invoke(None, json.dumps(kwargs)) |
There was a problem hiding this comment.
Pass a real ToolContext to converted function tools
_convert_function_tool invokes SDK tools as ft.on_invoke_tool(None, ...), but FunctionTool handlers dereference context fields (for example ctx.tool_name) during normal invocation. In practice this causes every converted @function_tool call to fail and return tool-error text instead of running the tool logic, so any agent using OpenAI Agents function tools will misbehave under AgentspanRunner.
Useful? React with 👍 / 👎.
| return AgentspanRunResult(result) | ||
|
|
||
| @classmethod | ||
| async def run_streamed( |
There was a problem hiding this comment.
Make run_streamed match Runner's synchronous API
This method is declared async, but the built-in Runner.run_streamed(...) API is synchronous and immediately returns a streaming result object. Using AgentspanRunner as Runner therefore changes call semantics: existing code that calls Runner.run_streamed(...) without await receives a coroutine instead of a stream, breaking drop-in compatibility for streaming flows.
Useful? React with 👍 / 👎.
| result = instructions() | ||
| instructions = asyncio.run(result) if asyncio.iscoroutine(result) else result | ||
| except Exception: | ||
| instructions = "" |
There was a problem hiding this comment.
Preserve callable instructions instead of clearing them
Dynamic instructions are called as instructions() with no arguments and any exception is swallowed by setting instructions = "". In this SDK, callable instructions are expected to accept (context, agent), so this path drops prompts for valid dynamic-instruction agents and silently changes model behavior instead of evaluating the instructions function correctly.
Useful? React with 👍 / 👎.
Summary
Adds
AgentspanRunner— a drop-in replacement forRunnerthat executes agents on Agentspan instead of directly against OpenAI.Agentspan adds durability, observability, human-in-the-loop (HITL), and horizontal scaling to any agent built with the OpenAI Agents SDK, without changing how agents are defined or how tools are written.
Migration
Change one import line:
Everything else stays identical —
Agent,@function_tool,result.final_output— no other code changes needed.Example
What Agentspan adds
Files changed
src/agents/extensions/agentspan.pyAgentspanRunner+AgentspanRunResultsrc/agents/extensions/__init__.pyAgentspanRunnerpyproject.tomlagentspanoptional dependencyInstallation
Requires an Agentspan server (
AGENTSPAN_SERVER_URL=http://localhost:6767/apiby default). See agentspan.ai for setup.