Docs / Integrations / OpenAI Agents SDK
OpenAI Agents SDK
Mesedi ships as an @openai/agents RunHooks implementation. Wrap your entry function with mesedi.wrap() and pass a MesediRunHooks instance to Runner.run(..., { hooks }). Every agent enter / exit, handoff, and tool call flows into Mesedi as checkpoint, agent_handoff, and tool_call events.
Install
npm install mesedi @openai/agentsMesediRunHooks is duck-typed against the runtime RunHooks shape, so @openai/agents is not a required runtime dependency of mesedi. Customers who never import mesedi/integrations/openai_agents pay no install cost.
Wire it up
import { configure, wrap } from "mesedi";
import { MesediRunHooks } from "mesedi/integrations/openai_agents";
import { Agent, Runner } from "@openai/agents";
configure({ apiKey: process.env.MESEDI_API_KEY });
const triage = new Agent({ name: "triage", ...});
const planner = new Agent({ name: "planner", ...});
export const runUserRequest = wrap(async (question: string) => {
const result = await Runner.run(
triage,
question,
{ hooks: new MesediRunHooks() },
);
return result.finalOutput;
});One MesediRunHooks instance per Runner.runcall. All hook methods are async and non-blocking; event submission goes through Mesedi's background shipper so the Agents SDK runner is never blocked on Mesedi I/O.
Hook-to-event mapping
| RunHooks method | Mesedi event | Notes |
|---|---|---|
onAgentStart / onAgentEnd | checkpoint enter + exit | Agent name + truncated input/output repr. Feeds semantic_loop. |
onHandoff | agent_handoff | from_agent / to_agent from the hook arguments; handoff_kind defaults to "transfer". |
onToolStart / onToolEnd | tool_call | Payload shape matches @mesedi.tool. |
Current limitations
llm_callevents are not emitted by this adapter. The @openai/agentsRunHookssurface does not expose per-LLM-call hooks as of the version this integration was written against. For Anthropic-backed runs, use the existinginstrumentAnthropic()patch; an OpenAI-backed equivalent is not currently provided.- Streaming hooks (
Runner.runStreamed) are not currently instrumented. - Outside a wrap, all hooks silently no-op.