OpenAI Agents API Artifact Contract: Make Long-Running Agent Work Reviewable
From the publisher’s feed, collected in the ZeroLabs newsroom.
OpenAI Agents API Artifact ContractAn agent that says “done” has not necessarily delivered anything a person, service, or next agent can safely use. An artifact contract turns a cloud-agent run into a package with a known shape, proof, and next step.Treat the output boundary as part of the product, not an afterthought.A long-running agent can investigate an incident, write code, analyze a dataset, and produce a polished final message. Then a reviewer asks a basic question: where is the actual work? The answer is often a hunt through a temporary workspace, a chat transcript, or a folder full of files with unclear names.That gap becomes expensive as soon as agents work asynchronously or hand work to other people. A manager cannot approve a mitigation that has no evidence bundle. A service cannot reliably ingest a report whose filename changes on every run. A second agent cannot tell whether an empty folder means “nothing found,” “job failed,” or “the first agent saved it somewhere else.”The timely trigger is the new OpenAI Agents API, which brings the Codex harness and hosted or connected execution environments to developers. Hosted agents can run code, work with files, and save intermediate results. The API also exposes immutable session artifacts after a hosted turn completes. That is useful plumbing. It does not, by itself, define what a good delivery looks like.Files are not a handoff. A handoff is a small, verifiable package that tells the next person what exists, why it matters, and what still needs a decision.This guide shows how to design that package. The pattern works with OpenAI-hosted environments, your own sandbox, a coding agent, or a research workflow. The API names may change during beta; the delivery contract is deliberately tool-neutral.Why “the agent created files” is not enoughOpenAI documents a session artifact as an immutable file published by a completed hosted session turn. You can list artifacts by session, retrieve their metadata, and download their bytes after the execution environment has expired. Those properties are excellent for durability and traceability. But artifact metadata only identifies a path, size, environment, session, and turn. It does not say whether the report answered the task, which sources support it, whether a test passed, or whether a human must approve an external action.That is where teams accidentally replace one opaque chat window with another opaque storage bucket. The agent did work, but the delivery is still ambiguous.Common failure modes are surprisingly ordinary:The useful file is buried beside scratch scripts, screenshots, and cached downloads.A summary claims that a check passed but does not name the command, scope, or exit status.A reviewer cannot tell an observation from an assumption or a proposed change.One subagent overwrites another agent’s output because both use a generic filename.A downstream service receives a syntactically valid JSON file that is semantically incomplete.An artifact contains a copied secret, customer record, or raw trace that had no reason to leave the sandbox.An artifact contract makes these questions explicit before the run starts. It is close to an API contract, but it includes human review and operational proof. A JSON Schema can verify that a field exists. It cannot prove that the field is well-supported, current, or safe to act on.The five-part artifact contractKeep the contract short enough that an agent can follow it and a reviewer can scan it. For most developer workflows, five parts are enough.1. Declare the delivery surfaceName the output directory, the required top-level files, and the expected artifact types. In an OpenAI-hosted environment, make the write location part of the task rather than assuming the agent will infer it. The Agents API announcement itself uses /workspace/outputs for findings, evidence, and recommended mitigation.A useful contract does not say “write a report.” It says: write one human-readable report, one machine-readable manifest, and only the named supporting files under the run’s dedicated output path. That eliminates the treasure hunt.2. Give every file a roleDo not treat every file as equally important. A reviewer needs a front door. A service needs a stable parser target. An auditor needs evidence. Split those needs on purpose:README.md is the human entry point: outcome, changed files, risks, and recommended next action.manifest.json is the machine entry point: status, task identifier, artifact inventory, checks, and review state.evidence/ contains bounded inputs or outputs that support important claims.deliverables/ contains the actual code patch, CSV, report, diagram, or other requested work.checks/ records test commands, exit codes, scope, and links to relevant logs.This separation also helps prompt design. The agent no longer has to guess whether a terminal transcript is the final answer. It knows the transcript is evidence, while the report explains the conclusion.3. Record proof, not just confidenceRequire a claim to point to its proof. For a code change, that might be a test result and a diff. For an incident investigation, it might be a timestamped log query, a metric snapshot, and an unresolved-question list. For a data task, it could be the input version, transformation script, row counts, and validation results.Confidence can be useful, but it is not evidence. Ask the agent to label uncertainty and list missing evidence separately. A reviewer can then decide whether the open questions block release or merely deserve follow-up.The contract turns an agent run into a review path instead of a pile of output.4. Validate the package before publicationValidation should be deterministic wherever possible. Check that required files exist, the manifest parses, referenced files are present, paths do not escape the output directory, and artifacts fit a size limit. If the task requires a test, verify that the named command exited successfully. If it requires a human decision, the package should be needs_review, not complete.This is the crucial distinction: a complete package can still be awaiting approval. Do not overload “done” to mean both “the agent finished its bounded work” and “the organization approved the consequence.”5. State the handoff and retention ruleFinish the contract with a named owner and a next action. Examples: “SRE on call reviews the mitigation before any restart,” “CI uploads the signed bundle to the pull request,” or “the research lead decides whether the evidence supports publication.” Also state how long the bundle should remain available and which files must be redacted or omitted.Immutability helps preserve what was delivered, but it does not replace access control. Keep credentials out of artifacts, avoid raw customer data by default, and treat screenshots and command logs as potentially sensitive.A practical package layoutHere is a compact layout for a coding, research, or operations agent. A unique run identifier prevents parallel jobs from colliding. The exact folders are less important than their stable roles./workspace/outputs/run-8f3c/ README.md manifest.json deliverables/ remediation.patch rollout-plan.md evidence/ error-sample.json metric-snapshot.json checks/ verification.jsonThe manifest should stay boring and explicit. Avoid putting the agent’s whole narrative into it. Put the narrative in the README and retain a small set of fields that software can trust as structure.{ "contract_version": "1.0", "run_id": "run-8f3c", "task_type": "incident-investigation", "status": "needs_review", "summary_path": "README.md", "deliverables": [ { "path": "deliverables/remediation.patch", "kind": "patch" }, { "path": "deliverables/rollout-plan.md", "kind": "plan" } ], "checks": [ { "name": "targeted test", "exit_code": 0, "path": "checks/verification.json" } ], "open_questions": ["Canary timing requires owner approval"], "review": { "required": true, "owner": "sre-on-call" }}Notice what is absent: there is no unbounded “notes” field and no promise that the agent executed an unapproved action. The manifest captures delivery state, not a vague story of competence.Write the contract into the task promptThe fastest way to get inconsistent artifacts is to define the contract only in your orchestration code. The agent needs it in its working instructions. Be precise about paths and boundaries, but leave room for judgment inside the task.Investigate the elevated 5xx rate using the supplied logs and runbook.Write all final outputs only under /workspace/outputs/run-8f3c.Required: README.md, manifest.json, one evidence file for each material claim,and checks/verification.json. Use the supplied manifest schema.Separate observations, hypotheses, and recommended actions. Do not restart,deploy, change configuration, or contact external systems. If evidence ismissing, set status to needs_review and list the missing evidence.Before finishing, verify every manifest path exists and reread the final report.This creates a stronger viral promise than “autonomous SRE.” The agent can be useful without pretending it has authority. The practical benefit is immediate: a human sees the exact decision that remains, while automation can reliably collect the same package every time.Collect and verify session artifactsAfter an OpenAI-hosted session completes, list its artifacts and download only the expected package. The official API reference describes artifacts as immutable files from completed hosted session turns and provides both list and content endpoints. Your collector should not blindly accept every published file as safe or complete.import OpenAI from "openai";import path from "node:path";import { mkdir, writeFile } from "node:fs/promises";const client = new OpenAI();const sessionId = process.env.SESSION_ID;const destination = "./agent-deliveries/run-8f3c";await mkdir(destination, { recursive: true });for await (const artifact of client.beta.agents.sessions.artifacts.list(sessionId)) { if (!artifact.path.startsWith("/workspace/outputs/run-8f3c/")) continue; const name = path.basename(artifact.path); const response = await client.beta.agents.sessions.artifacts.content(artifact.id, { session_id: sessionId }); await writeFile(path.join(destination, name), Buffer.from(await response.arrayBuffer()));}In production, preserve the directory structure rather than flattening filenames, reject path traversal, enforce allowlists, and validate the manifest after download. Record the session ID, turn ID, artifact ID, and content hash in your own delivery ledger. That gives you a bridge between platform metadata and your business workflow.Important: a successful artifact download proves availability, not quality. Run the package validator before triggering a pull-request comment, ticket update, deployment review, or customer-facing workflow.Use different gates for different risksNot every artifact deserves the same approval process. A draft summary may be published to an internal review queue after structural validation. A code patch may need tests, a diff policy, and owner approval. A remediation plan that could change production should stop at a recommendation until an authorized system or person approves the action.Think in layers. The agent has permission to generate a package. A validator has permission to judge its structure. A reviewer has permission to accept the recommendation. A deployment system has permission to make a controlled change. Combining all four roles in one “complete” flag invites mistakes.The goal is faster review with better evidence, not automated rubber-stamping.Roll it out without turning every task into bureaucracyStart with one high-friction workflow: a recurring incident investigation, weekly analytics report, PR-ready code change, or vendor research task. Watch the questions reviewers repeatedly ask. If everyone asks “which logs did it use?”, add evidence references. If they ask “which files are final?”, tighten the manifest. If they ask “can I deploy this?”, add an explicit approval state.Measure review time, package-validation failures, missing-file retries, and the share of runs that receive a clear next action. Those numbers are more useful than counting agent messages. A good artifact contract reduces downstream investigation, even when the agent’s first attempt is imperfect.Do not create a 40-field manifest on day one. The best contract is the smallest one that prevents recurring ambiguity. Version it when a consumer needs a new field; keep old versions readable long enough for in-flight runs; and test the validator with deliberately broken packages.Test the contract like an interfaceAgent behavior will vary. Your delivery interface should not. Build a tiny fixture suite for the validator before you scale a workflow. One fixture should be a valid package. The rest should fail for a specific, understandable reason: missing README, malformed manifest, file outside the allowed root, unknown artifact type, absent evidence reference, or a package marked complete even though review is required.This is especially important when a parent agent delegates work. Let each subagent write under its own run-scoped directory, then have the coordinator assemble a new parent package that references the accepted child bundles. Do not let a coordinator silently copy every scratch file into the final delivery. Child output is input to the coordinator, not automatically a deliverable.A simple acceptance checklist is usually enough:Every required path exists under the approved root and has an allowed type.The manifest inventory exactly matches the published deliverables.Each material conclusion points to evidence or is labeled as a hypothesis.Each declared check has an exit status, scope, and time of execution.The package names an owner, review state, and next action.No secret, raw credential, or disallowed data class is present.That list also creates a useful evaluation target. Instead of asking an LLM judge whether an agent was “good,” measure whether it produced a complete, valid package and whether a reviewer could make the intended decision without asking a follow-up question. Reviewers can still judge nuanced engineering quality, but the contract removes avoidable ambiguity first.For a new version of the contract, run it in shadow mode: collect the package, validate it, and compare the validator’s findings with real reviewer comments. Add a new required field only when it eliminates a repeated failure. This keeps the artifact contract practical as the workflow grows.The durable definition of doneLong-running agents make it easy to confuse activity with delivery. The OpenAI Agents API gives developers durable sessions, file-capable environments, and immutable artifacts. The engineering opportunity is to put a contract around that output.When the next person can open one report, verify the evidence, identify the final files, see the unresolved question, and know who acts next, the agent has delivered useful work. Until then, “done” is only a sentence in a chat window.FAQWhat is an OpenAI Agents API artifact contract?It is a versioned definition of what an agent must deliver: required files, their roles, supporting evidence, validation checks, review status, and the next owner. It adds a reliable handoff layer on top of session artifacts.Are OpenAI Agents API artifacts immutable?OpenAI’s API reference describes a session artifact as an immutable file published by a completed hosted session turn. Immutability preserves the published file, but your workflow still needs its own validation, access controls, retention policy, and quality gates.Should every agent output use JSON?No. Use a human-readable report for explanation and a small JSON manifest for automation. The report helps reviewers understand judgment and uncertainty; the manifest helps systems locate files and enforce required fields.How do I stop an agent from publishing secrets as artifacts?Limit what the environment can access, state forbidden data classes in the task, keep secrets out of output paths, scan packages before release, and use restricted artifact access. Treat logs, screenshots, and tool outputs as sensitive by default.Can this pattern work outside OpenAI-hosted sandboxes?Yes. The same contract works with self-hosted sandboxes, CI workers, coding-agent worktrees, and workflow engines. Replace the artifact-listing step with your storage or CI-artifact API, but preserve the package roles and validation gates.What should I validate first?Start with required files, valid manifest JSON, path safety, referenced-file existence, declared checks, and an explicit review status. Add semantic checks only after you can consistently validate the basic delivery shape.Sources: OpenAI’s Agents API announcement and the official Artifacts API reference.OpenAI Agents API Artifact Contract: Make Long-Running Agent Work Reviewable was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.