codingsalt

OpenAI Agents API: Managed Harness for Autonomous Workflows

OpenAI launched the Agents API to manage session state, tool-calling, and sandboxed execution for autonomous developers using gpt-6-astra.

CodingSalt Editorial5 min read

What is the OpenAI Agents API?

The OpenAI Agents API is a managed framework designed to handle the orchestration, state management, and tool-calling requirements of autonomous developer workflows. By providing a dedicated harness for the gpt-6-astra model, OpenAI removes the need for developers to manually manage conversation history, context window limits, or session recovery.

According to the official OpenAI documentation, the API allows agents to operate within sandboxed environments where they can execute code, edit files, and connect to external data sources. This managed approach is intended to simplify the creation of AI coding agents that require durable, multi-turn interactions to complete complex tasks like incident response or data analysis.

Core Concepts of the Agents API

The architecture of the OpenAI Agents API is built around four fundamental entities that define how an agent interacts with its environment and the user.

  • Agent: This defines the "brain" of the operation, including the specific model (such as gpt-6-astra), system instructions, available tools, and any configured Model Context Protocol (MCP) servers.
  • Environment: This is the execution space where the agent performs work. It can be an OpenAI-hosted sandbox or a self-hosted computer where the agent runs commands and manages files.
  • Session: A session is a durable instance of an agent. It maintains the state of a task across multiple turns, allowing the agent to resume work exactly where it left off without the developer needing to resend the entire history.
  • Events and Items: These represent the granular inputs and outputs of a session. Events include user instructions, while items cover the artifacts and responses produced by the agent during its turn.

Managed Codex Harness Capabilities

OpenAI provides a "managed Codex harness" that automates several complex aspects of agentic workflows. In traditional LLM implementations, developers must handle "context compaction"—the process of summarizing or pruning history to fit within model limits. The Agents API handles this automatically.

The harness also provides:

  1. Orchestration: Managing the flow of tasks and ensuring the agent follows instructions.
  2. Context Compaction: Summarizing previous work to keep the context window efficient.
  3. Mid-turn Steering: Allowing developers to guide or interrupt an agent while it is actively working on a task.
  4. Delegation: Enabling the primary agent to break work into subtasks and assign them to subagents.
  5. Recovery: Automatically managing session state so that if a connection is lost, the agent can resume its current task.

This managed layer is particularly useful for OpenAI research acceleration, where long-running autonomous tasks frequently exceed the standard limits of simple chat completion APIs.

Environment and Sandbox Options

Developers can choose where their agents execute code and interact with files. The choice between an OpenAI-hosted sandbox and a self-hosted environment depends on the security requirements and the specific tools the agent needs to access.

Feature OpenAI-Hosted Sandbox Self-Hosted Sandbox
Management OpenAI provisions and manages the container Developer manages the host and lifecycle
Isolation Standard OpenAI container security Developer-defined security boundaries
File Access Isolated to the provided sandbox Access to local workspace and capability directories
Pricing Standard container rates apply Infrastructure costs managed by the developer
Connectivity Pre-configured internet/API access Custom networking and MCP configurations

Choosing a self-hosted sandbox does not change the data residency or retention policies of the API. Developers should consult the OpenAI Data Controls for specific details on how session data is handled.

Integrating MCP and Multi-Agent Workflows

The OpenAI Agents API natively supports the Model Context Protocol (MCP), allowing agents to connect to external data through standardized transports. This enables agents to query documentation, search the web, or interact with internal databases using a consistent interface.

The API also introduces a formal structure for multi-agent delegation. A single session can be configured to allow subagents, which are independent instances that handle specific research or execution tasks. For example, a primary agent might delegate "web search" to one subagent while another subagent "analyzes local code," combining their findings into a single final response. This is configured via the multi_agent property in the session creation request, where developers can set max_concurrent_subagents.

Implementation Example: Creating a Session

To start a session, developers send a POST request to the /v1/agents/sessions endpoint. The following example demonstrates how to configure an agent with gpt-6-astra, an MCP server for documentation, and multi-agent capabilities enabled.

from openai import OpenAI
 
client = OpenAI()
 
session = client.beta.agents.sessions.create(
    agent = {
        "model": "gpt-6-astra",
        "instructions": "Use the documentation MCP to answer technical questions.",
        "tools": [
            { "type": "programmatic_tool_calling" },
            {
                "type": "mcp",
                "server_label": "internal_docs",
                "transport": {
                    "type": "http",
                    "server_url": "https://example.com/mcp",
                },
            },
            { "type": "web_search" },
        ],
        "multi_agent": { "enabled": True, "max_concurrent_subagents": 4 },
    },
    environment = {
        "type": "self_hosted",
        "workspace_directory": "/workspace",
    },
    input = [
        {
            "role": "user",
            "content": [
                {
                    "type": "input_text",
                    "text": "Research the latest MCP updates and summarize them.",
                }
            ],
        }
    ],
)
print(session.id)

Actionable Next Steps for Developers

The OpenAI Agents API is currently in beta. To begin implementation, developers should evaluate their existing autonomous workflows to see where managed state could reduce complexity.

  • For Incident Response: Use the Agents API to create sessions that investigate alerts, using the sandbox to run diagnostic scripts and request human approval for recovery actions.
  • For Data Analysis: Deploy agents in a read-only environment with SQL tools to answer warehouse questions without manual context management.
  • For Documentation Workflows: Leverage the MCP integration to connect agents directly to your internal knowledge base, allowing them to provide context-aware answers to technical queries.

Note that the API is currently restricted to data residency in the United States and does not support Zero Data Retention (ZDR) at this time. If your project requires strict data residency outside the US, you may need to wait for further regional rollouts.

Frequently asked questions

What is the OpenAI Agents API?

The OpenAI Agents API is a managed framework that handles session persistence, orchestration, context compaction, and tool-calling for autonomous agents. It allows developers to run agents in sandboxed environments while OpenAI manages the underlying state and recovery.

Does the Agents API support data residency outside the US?

Currently, the Agents API only supports data residency within the United States. It does not yet support Zero Data Retention (ZDR), even when using a self-hosted sandbox environment.

How does the Agents API handle context window limits?

The API includes a managed Codex harness that performs context compaction. This automatically summarizes previous work to manage the context window, allowing sessions to remain durable over long-running tasks.

Sources

  1. OpenAI Agents API Overview
  2. OpenAI Data Controls

Get the next one in your inbox

One sourced article every morning — model releases, pricing moves, developer tooling.

Daily AI & engineering news in your inbox. No spam, one-click unsubscribe.