# OpenAI Agents SDK Async Callback — Persist Delegated Results Across Runs

> AgentAddress fits the OpenAI Agents SDK as host-side function tools: create the return address, exit the run, and let a later run poll the delegated result.

## Use AgentAddress when
- A delegated worker responds after the run exits.
- The model should never hold the read credential.
- A later run must resume from trusted application state.

## 1. Provision

POST https://agentaddress.dev/api/v1/addresses
Content-Type: application/json

{"task_id":"async_task_42"}

Save the complete response. In particular, persist `credentials.read_token` and `endpoints.events_url` before the current run exits. The read token is returned only once.

## 2. Hand off

Wrap create and poll as SDK function tools; give the model only the helper's safe JSON output and keep credentials.read_token in trusted application state.

POST {endpoints.inbox_url}
Content-Type: application/json
Idempotency-Key: result-42

{"type":"delegation.completed","data":{"status":"complete"}}

## 3. Return later

GET {endpoints.events_url}?after=0&wait=25
Authorization: Bearer {credentials.read_token}

Process events in `sequence` order. Save `next_cursor`, use it as the next `after` value, and acknowledge handled events.

## Common questions

### How do I implement an async callback with the OpenAI Agents SDK?

The Agents SDK's function tools wrap application code, so put the callback plumbing behind host-side functions: one tool creates a persistent return address and returns its write-only URL to the model, and another polls the queued events later. The model hands the URL to the delegated worker and exits; AgentAddress keeps accepting the worker's delivery after the run ends, and a later run calls the poll tool to read it.

### How do I get a delegated agent's result after the run exits?

Persist the return path, not the run. Before the run ends, create an AgentAddress for the delegation, give its inbox URL to the delegated worker as the callback destination, and save the one-time read token in trusted application state — not in model context. The delegated result queues there for 30 days; the next run reads it from the ordered feed and validates the delegation identifiers before acting on it.

### How do I keep secrets out of an Agents SDK model's context?

Expose secrets only through host-side code. AgentAddress's contract is built for this: the read token is returned once at creation, and the recommended helper saves it in owner-only storage; in an Agents SDK app, your function tools hold it in application state and return only safe handoff data — the inbox URL, task name, and event envelopes — to the model. The model never needs to see or repeat the credential.

### What is a handoff result in an agent delegation workflow?

It is the outcome a delegated worker produces after the orchestrating run has ended — for example a delegation.completed event with the work's status and result. Because the orchestrating run may be gone, the result needs a durable address rather than a live connection. AgentAddress provides that address: the worker POSTs to its write-only URL, and a later run retrieves the queued event from the ordered feed.

### Does the OpenAI Agents SDK wake my agent when a result arrives?

No, and neither does AgentAddress. Both are pull-based on resumption: the SDK executes runs when your host starts them, and AgentAddress stores deliveries rather than launching runtimes. Queue the result durably, then start a later run from your host application and have it poll the saved task — the result will be waiting in sequence order.

### Can agent state and callback results live in one place?

Yes. One AgentAddress holds the delegated results, inbound email, small durable JSON state (32 keys, 65,536 bytes), and the ordered event feed that records everything, with 30-day retention and a 1,000-event capacity. The later run restores all of it from one saved credential instead of assembling state from several services.

## Runnable example

- [Run the OpenAI Agents SDK delegation example](https://github.com/zkarimi22/agentaddress-agents/tree/main/examples/openai-agents)
- [Controlled cross-run verification and its limits](https://github.com/zkarimi22/agentaddress/blob/main/docs/verification/activation-log.md)

## Machine contracts

- [OpenAPI 3.1](https://agentaddress.dev/openapi.json)
- [Agent-readable index](https://agentaddress.dev/llms.txt)
- [Complete guide](https://agentaddress.dev/llms-full.txt)
- [Capability discovery](https://agentaddress.dev/.well-known/agentaddress.json)
