Skip to content

Add Agents API support (public beta) - #204

Merged
jamesrochabrun merged 3 commits into
mainfrom
jroch-agents-api
Oct 5, 2026
Merged

jamesrochabrun merged 3 commits into
mainfrom
jroch-agents-api

Conversation

@jamesrochabrun

Copy link
Copy Markdown
Owner

Summary

Adds support for the Agents API (public beta), announced at OpenAI DevDay 2026. The Agents API exposes the managed Codex harness: hosted execution, memory, tools, and multi-agent support, with OpenAI handling sessions, orchestration, context compaction and recovery.

Stacked on #203 (GPT-6 models + Ultrafast tier).

New service methods

  • createAgentSession(_:) — POST /v1/agents/sessions
  • createAgentSessionStream(_:) — same endpoint with SSE streaming
  • agentSessionEventStream(sessionID:) — GET /v1/agents/sessions/{id}/events (reopen the stream)
  • submitAgentSessionEvents(sessionID:parameters:) — POST /v1/agents/sessions/{id}/events (follow-up messages, cancellations, approvals)
  • listAgentSessionItems(sessionID:limit:order:after:) — GET /v1/agents/sessions/{id}/items
  • deleteAgentSession(sessionID:) — DELETE /v1/agents/sessions/{id}

All requests send the OpenAI-Beta: agents=v1 header.

New types

  • AgentSessionParameters — agent config (model, instructions, tools), environment (openai_hosted / none, desktop), input, stream. Tools: .computerUse(includeScreenshots:), .webSearch, and .custom as an escape hatch for shapes not yet modeled (e.g. MCP servers).
  • AgentSessionEventsParameter / AgentSessionClientEvent — .message, .cancel, .custom (approvals).
  • AgentSessionObject, AgentSessionItem, AgentSessionStreamEvent.

Beta-resilient decoding

OpenAI has not published the complete Agents API schemas, so response models are deliberately lenient:

  • Documented fields are decoded as typed optionals; the complete payload is retained in a raw: OpenAIJSONValue member.
  • Unrecognized stream event types decode as .unknown(String) instead of throwing — a decode failure would otherwise terminate the whole AsyncThrowingStream.
  • submitAgentSessionEvents returns the raw JSON payload until the response schema is published.

AIProxy, Azure, and LocalModel services get fatalError stubs, consistent with how those services handle other unsupported endpoints (e.g. Conversations).

Testing

  • 8 new unit tests covering parameter/event encoding against the documented JSON shapes, stream event decoding for all documented event types, the .unknown fallback, and raw-payload retention
  • swift build and full test suite pass; swiftformat --lint clean

🤖 Generated with Claude Code

- Add gpt-6-astra, gpt-6.1-sol, and gpt-5.6-sol model IDs
- Add ServiceTier enum with auto, default, flex, priority, and ultrafast tiers
- Document Ultrafast usage in the Responses API and README
- New /v1/agents/sessions endpoints: create (with SSE streaming), event
  stream reopen, client event submission, item listing, and deletion
- AgentSessionParameters with agent config, tools (computer use, web
  search, custom), and environment settings
- Lenient beta decoding: documented fields are typed, full payloads kept
  in a raw member, unknown stream event types decode as .unknown instead
  of failing the stream
- Requests send the OpenAI-Beta: agents=v1 header
- Stubs for AIProxy, Azure, and LocalModel services; unit tests and
  README documentation
@jamesrochabrun
jamesrochabrun changed the base branch from jroch-decisions-api to main October 1, 2026 23:17
@jamesrochabrun jamesrochabrun reopened this Oct 1, 2026
@jamesrochabrun
jamesrochabrun merged commit 3beeb77 into main Oct 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant