DeltaKitDeltaKit

fromOpenAiAgents

Convert OpenAI Agents SDK history items to DeltaKit messages.

fromOpenAiAgents converts raw OpenAI Agents SDK response items into DeltaKit's Message<ContentPart>[] format.

import { fromOpenAiAgents } from "@deltakit/core";

Signature

function fromOpenAiAgents(
  items: Record<string, unknown>[]
): Message<ContentPart>[]
ParameterTypeDescription
itemsRecord<string, unknown>[]Raw items from OpenAI Agents SDK (JSON deserialized)

Returns an array of Message<ContentPart> in chronological order.

Usage

// Load history from your API
const history = await fetch("/api/chat/history").then((r) => r.json());

// Convert to DeltaKit messages
const messages = fromOpenAiAgents(history);
// => Message<ContentPart>[]

For using converted messages with the React hook, see Initial Messages.

Supported Item Types

The converter handles all OpenAI Agents SDK item types:

Messages

TypeMapping
message (role: user)Message with TextPart
message (role: assistant)Message with extracted ContentPart[]
Items without type but with roleHandled like message items
message (role: system/developer)Filtered out

Tool Calls

All tool calls are converted to ToolCallPart:

Typetool_name
function_callFunction name
web_search_call"web_search"
file_search_call"file_search"
computer_call"computer"
shell_call / local_shell_call"shell"
code_interpreter_call"code_interpreter"
apply_patch_call"apply_patch"
mcp_callMCP tool name
custom_tool_callCustom tool name
image_generation_callConverted to TextPart with "[Image Generated]"

Tool Outputs

Tool outputs are matched to their corresponding ToolCallPart by callId:

TypeBehavior
function_call_outputAttaches result to matching ToolCallPart
computer_call_outputAttaches screenshot placeholder
shell_call_output / local_shell_call_outputAttaches stdout/stderr output
apply_patch_call_outputAttaches status + output
custom_tool_call_outputAttaches output string

Other Items

TypeBehavior
reasoningConverted to ReasoningPart with summary text
mcp_list_tools, mcp_approval_request, mcp_approval_responseSilently filtered out
compaction, item_reference, tool_search_call, tool_search_outputSilently filtered out

Server Example (FastAPI)

@app.get("/api/chat/history/{session_id}")
async def get_history(session_id: str):
    result = await agent.run(session_id=session_id)
    return result.to_input_list()

Notes

  • Messages are returned in chronological order.
  • Consecutive assistant items (tool calls, reasoning, text) are grouped into a single Message.
  • A new user message always starts a new group.
  • Unknown item types are silently skipped.

On this page