# Agents API

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.

## 1. Create a shared agent configuration



Any implementation of the Agents API starts with a [saved agent](https://developers.openai.com/api/docs/guides/agents-api/configuration#reuse-an-agent-across-sessions). It specifies which model does the work, which instructions it follows, and which **tools** it can use to take actions or get information. After it's created, you can use the agent in [future sessions](https://developers.openai.com/api/training/agents-api/2-create-isolated-sessions.md) using a unique `id`.



### Share configuration across sessions

1. **Create a common agent configuration** (Your app → OpenAI Agents API, `POST /v1/agents`)

   **Your app**: Sends the model, shared instructions, and function definitions.

   **OpenAI Agents API**: Saves the settings for reuse across sessions.

   **Request JSON**: `{"model":"gpt-6.2-astra","instructions":"You are a forward-deployed engineer for Herringbone, a payments API provider.\n…","tools":[{"type":"function","name":"get_integration_context"},{"type":"function","name":"save_integration_context"}]}`

2. **Read the agent ID** (OpenAI Agents API → Your app, HTTP response)

   **Your app**: Reads the agent ID from the response.

   **OpenAI Agents API**: Returns the saved agent and its ID.

   **Response JSON**: `{"id":"agent_abc123","name":"Herringbone forward-deployed engineer"}`

3. **Save the agent ID** (Your app → application records, Application operation)

   **Your app**: Stores the returned ID for future session requests.

   **Application record**: `{"shared_agent_id":"agent_abc123"}`



### Key components of the agent configuration

These are the key properties of an agent configuration. To change a setting for a single session, [override it when you create the session](https://developers.openai.com/api/docs/guides/agents-api/configuration#override-settings-for-one-session). [Update the saved agent](https://developers.openai.com/api/docs/guides/agents-api/configuration#update-a-saved-agent) to change the defaults for future sessions. Changes to the agent configuration aren't updated for sessions that have already started.

| Input          | Explanation                                                                                                                                                                                                                                                                                                                                                                              |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model`        | The [model ID](https://developers.openai.com/api/docs/models) selects the model that processes input, requests tool calls, and generates replies.                                                                                                                                                                                                                                                                     |
| `instructions` | The API appends this text to the agent’s base instructions. Describe the agent’s role, the rules it should follow, and when to use each tool. Send the task itself as [session input](https://developers.openai.com/api/docs/guides/agents-api/sessions#start-work).                                                                                                                                                  |
| `tools`        | List the tools the model can request, such as [web search](https://developers.openai.com/api/docs/guides/agents-api/tools/web-search) or [computer use](https://developers.openai.com/api/docs/guides/agents-api/tools/computer-use). For a [custom function](https://developers.openai.com/api/docs/guides/agents-api/tools/functions#define-a-function), supply its name, description, and a JSON Schema that defines which arguments it accepts. Your app runs the function. |




### Example: Configure an agent to review customer integrations



Herringbone, a fictional payments API provider, now returns payments one page
  at a time. Customer A’s nightly finance report must include every payment.
  Customer B’s proxy must forward requests for each page to Herringbone.
  Customer C must combine the pages into the single list its merchants expect.
  Herringbone asks each customer’s [AI forward-deployed
  engineer](https://developers.openai.com/api/training/agents-api.md#use-case-ai-forward-deployed-engineer) to review the integration
  and tell the customer what needs to change.



Herringbone’s shared instructions tell the agent to inspect the customer’s code, propose the smallest change that preserves the intended behavior, and report which tests it ran. Herringbone describes the pagination change in the [task it sends to each session](https://developers.openai.com/api/training/agents-api/3-send-tasks-and-handle-tool-calls.md), so it can reuse the same instructions for the next API change. Two function tools give the agent access to the details of each integration.

- `get_integration_context` takes no arguments. It returns the customer’s integration code, constraints, and notes from earlier reviews.
- `save_integration_context` takes one required string, `note`. It records a detail for [future sessions](https://developers.openai.com/api/training/agents-api/6-carry-context-across-sessions.md), such as who maintains the proxy or why a report needs a particular column.

When Herringbone [handles either call](https://developers.openai.com/api/training/agents-api/3-send-tasks-and-handle-tool-calls.md), its backend uses the session ID to look up the customer and check access. The agent never chooses whose records to read or write.

To run the example, [set up your API key and client library (SDK)](https://developers.openai.com/api/docs/guides/agents-api/quickstart#prerequisites). Copy the instructions from **Full prompt** into a file named `herringbone-fde.md` in the directory where you run the code. The cURL example uses `jq`, a command-line tool for building and reading JSON.



  

    

      Configure Herringbone's AI forward-deployed engineer

```typescript
import { readFile } from "node:fs/promises";
import OpenAI from "openai";

const client = new OpenAI();
const agent = await client.beta.agents.create({
  name: "Herringbone forward-deployed engineer",
  model: "gpt-6.2-astra",
  instructions: await readFile("herringbone-fde.md", "utf8"),
  tools: [
    {
      type: "function",
      name: "get_integration_context",
      description:
        "Read integration code, constraints, and saved notes for the current customer.",
      parameters: {
        type: "object",
        properties: {},
        additionalProperties: false,
      },
    },
    {
      type: "function",
      name: "save_integration_context",
      description:
        "Save a note for future sessions about this customer or integration, such as a contact, constraint, or design decision.",
      parameters: {
        type: "object",
        properties: { note: { type: "string" } },
        required: ["note"],
        additionalProperties: false,
      },
    },
  ],
});
console.log(agent.id);
```

```python
from pathlib import Path

from openai import OpenAI

client = OpenAI()
agent = client.beta.agents.create(
    name="Herringbone forward-deployed engineer",
    model="gpt-6.2-astra",
    instructions=Path("herringbone-fde.md").read_text(encoding="utf-8"),
    tools=[
        {
            "type": "function",
            "name": "get_integration_context",
            "description": (
                "Read integration code, constraints, and saved notes for the current customer."
            ),
            "parameters": {
                "type": "object",
                "properties": {},
                "additionalProperties": False,
            },
        },
        {
            "type": "function",
            "name": "save_integration_context",
            "description": "Save a note for future sessions about this customer or integration, such as a contact, constraint, or design decision.",
            "parameters": {
                "type": "object",
                "properties": {"note": {"type": "string"}},
                "required": ["note"],
                "additionalProperties": False,
            },
        },
    ],
)
print(agent.id)
```

```go
import (
	"context"
	"fmt"
	"os"

	"github.com/openai/openai-go/v3"
)

instructions, err := os.ReadFile("herringbone-fde.md")
if err != nil {
	panic(err)
}
client := openai.NewClient()
agent, err := client.Beta.Agents.New(context.Background(), openai.BetaAgentNewParams{
	Name:         openai.String("Herringbone forward-deployed engineer"),
	Model:        "gpt-6.2-astra",
	Instructions: openai.String(string(instructions)),
	Tools: []openai.PersistedAgentToolParamUnion{
		{
			OfParamFunction: &openai.PersistedAgentToolParamFunction{
				Name:        "get_integration_context",
				Description: "Read integration code, constraints, and saved notes for the current customer.",
				Parameters: map[string]any{
					"type":                 "object",
					"properties":           map[string]any{},
					"additionalProperties": false,
				},
			},
		},
		{
			OfParamFunction: &openai.PersistedAgentToolParamFunction{
				Name:        "save_integration_context",
				Description: "Save a note for future sessions about this customer or integration, such as a contact, constraint, or design decision.",
				Parameters: map[string]any{
					"type":                 "object",
					"properties":           map[string]any{"note": map[string]any{"type": "string"}},
					"required":             []string{"note"},
					"additionalProperties": false,
				},
			},
		},
	},
})
if err != nil {
	panic(err)
}
fmt.Println(agent.ID)
```

```java
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.JsonValue;
import com.openai.models.beta.agents.AgentCreateParams;
import com.openai.models.beta.agents.PersistedAgentToolParam;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;

OpenAIClient client = OpenAIOkHttpClient.fromEnv();
var agent =
    client
        .beta()
        .agents()
        .create(
            AgentCreateParams.builder()
                .name("Herringbone forward-deployed engineer")
                .model("gpt-6.2-astra")
                .instructions(Files.readString(Path.of("herringbone-fde.md")))
                .addTool(
                    PersistedAgentToolParam.Function.builder()
                        .name("get_integration_context")
                        .description(
                            "Read integration code, constraints, and saved notes for the current customer.")
                        .parameters(
                            PersistedAgentToolParam.Function.Parameters.builder()
                                .putAdditionalProperty("type", JsonValue.from("object"))
                                .putAdditionalProperty("properties", JsonValue.from(Map.of()))
                                .putAdditionalProperty(
                                    "additionalProperties", JsonValue.from(false))
                                .build())
                        .build())
                .addTool(
                    PersistedAgentToolParam.Function.builder()
                        .name("save_integration_context")
                        .description(
                            "Save a note for future sessions about this customer or integration, such as a contact, constraint, or design decision.")
                        .parameters(
                            PersistedAgentToolParam.Function.Parameters.builder()
                                .putAdditionalProperty("type", JsonValue.from("object"))
                                .putAdditionalProperty(
                                    "properties",
                                    JsonValue.from(Map.of("note", Map.of("type", "string"))))
                                .putAdditionalProperty(
                                    "required", JsonValue.from(List.of("note")))
                                .putAdditionalProperty(
                                    "additionalProperties", JsonValue.from(false))
                                .build())
                        .build())
                .build());
System.out.println(agent.id());
```

```ruby
require "openai"

client = OpenAI::Client.new
agent = client.beta.agents.create(
  name: "Herringbone forward-deployed engineer",
  model: "gpt-6.2-astra",
  instructions: File.read("herringbone-fde.md", encoding: "UTF-8"),
  tools: [
    {
      type: "function",
      name: "get_integration_context",
      description: "Read integration code, constraints, and saved notes for the current customer.",
      parameters: {
        type: "object",
        properties: {},
        additionalProperties: false
      }
    },
    {
      type: "function",
      name: "save_integration_context",
      description: "Save a note for future sessions about this customer or integration, such as a contact, constraint, or design decision.",
      parameters: {
        type: "object",
        properties: { note: { type: "string" } },
        required: ["note"],
        additionalProperties: false
      }
    }
  ]
)
puts agent.id
```

    

    

      ### Storing the agent configuration ID

The SDK examples print the saved agent’s ID. The cURL example returns the full [agent object](https://developers.openai.com/api/reference/resources/beta/subresources/agents/methods/create). Store its `id` so your app can reuse it when a customer requests a review.



**Ask your coding agent:**

```text
Create a saved agent with shared review instructions. Define get_integration_context with no arguments and save_integration_context with one required string, note. Let the agent save useful customer or integration context for future sessions. Use the session ID to look up the customer in our records. Check the user’s permissions before reading or writing any data. Store the returned agent ID for new sessions.

Read this lesson for context: https://developers.openai.com/api/training/agents-api/1-create-a-shared-agent-configuration.md
```
