190<dependency>190<dependency>
191 <groupId>com.openai</groupId>191 <groupId>com.openai</groupId>
192 <artifactId>openai-java</artifactId>192 <artifactId>openai-java</artifactId>
193 <version>4.69.2</version>193 <version>4.69.3</version>
194</dependency>194</dependency>
195```195```
196 196
382 382
383 383
384 384
385 Start with the Agents API to build agents with a managed Codex harness.](https://developers.openai.com/api/docs/guides/agents-api/quickstart)385 Use the Agents SDK to build, run, and observe agent workflows.](https://developers.openai.com/api/docs/guides/agents)
386 386
387## Analyze images and files387## Analyze images and files
388 388
2151 2151
2152## Build agents2152## Build agents
2153 2153
2154For new agent applications, start with the [Agents API](https://developers.openai.com/api/docs/guides/agents-api/overview). OpenAI manages the Codex harness, sessions, and orchestration while your application provides tools and chooses where execution happens.2154Use the OpenAI platform to build [agents](https://developers.openai.com/api/docs/guides/agents) capable of taking action—like [controlling computers](https://developers.openai.com/api/docs/guides/tools-computer-use)—on behalf of your users. Use the [Agents SDK](https://developers.openai.com/api/docs/guides/agents) to create orchestration logic on your server.
2155 2155
2156This example creates an OpenAI-hosted sandbox and asks the agent to write and run a Python script. Follow the [Agents API prerequisites](https://developers.openai.com/api/docs/guides/agents-api/quickstart#prerequisites) for API-key permissions and SDK setup. The Agents API is in beta; these examples use the standard OpenAI client libraries.2156Build a language triage agent
2157
2158Create and run a directory-tree script
2159 2157
2160```javascript2158```javascript
2161import OpenAI from "openai";2159import { Agent, run } from "@openai/agents";
2162 2160
2163const client = new OpenAI();2161const spanishAgent = new Agent({
2164const events = await client.beta.agents.sessions.create({2162 name: "Spanish agent",
2165 agent: {2163 instructions: "You only speak Spanish.",
2166 model: "gpt-6-astra",
2167 instructions: "Write clean code, run it, and report the actual output.",
2168 },
2169 environment: { type: "openai_hosted" },
2170 input:
2171 "Create tree.py, a Python script that prints a readable tree of the files in the current directory. Run it and show me the output.",
2172 stream: true,
2173});2164});
2174try {2165
2175 for await (const event of events) {2166const englishAgent = new Agent({
2176 console.log(JSON.stringify(event));2167 name: "English agent",
2177 }2168 instructions: "You only speak English",
2178} finally {2169});
2179 events.controller.abort();2170
2180}2171const triageAgent = new Agent({
2172 name: "Triage agent",
2173 instructions:
2174 "Handoff to the appropriate agent based on the language of the request.",
2175 handoffs: [spanishAgent, englishAgent],
2176});
2177
2178const result = await run(triageAgent, "Hola, ¿cómo estás?");
2179console.log(result.finalOutput);
2181```2180```
2182 2181
2183```python2182```python
2184from openai import OpenAI2183from agents import Agent, Runner
2184import asyncio
2185
2186spanish_agent = Agent(
2187 name="Spanish agent",
2188 instructions="You only speak Spanish.",
2189)
2190
2191english_agent = Agent(
2192 name="English agent",
2193 instructions="You only speak English",
2194)
2195
2196triage_agent = Agent(
2197 name="Triage agent",
2198 instructions="Handoff to the appropriate agent based on the language of the request.",
2199 handoffs=[spanish_agent, english_agent],
2200)
2185 2201
2186with OpenAI() as client:
2187 with client.beta.agents.sessions.create(
2188 agent={
2189 "model": "gpt-6-astra",
2190 "instructions": "Write clean code, run it, and report the actual output.",
2191 },
2192 environment={"type": "openai_hosted"},
2193 input="Create tree.py, a Python script that prints a readable tree of the files in the current directory. Run it and show me the output.",
2194 stream=True,
2195 ) as events:
2196 for event in events:
2197 print(event.to_json(indent=None), flush=True)
2198```
2199 2202
2203async def main():
2204 result = await Runner.run(triage_agent, input="Hola, ¿cómo estás?")
2205 print(result.final_output)
2206
2207
2208if __name__ == "__main__":
2209 asyncio.run(main())
2210```
2200 2211
2201The stream includes progress and output events. Check the [terminal result](https://developers.openai.com/api/docs/guides/agents-api/quickstart#2-follow-progress), save the session ID for follow-up work, and [delete the session](https://developers.openai.com/api/docs/guides/agents-api/quickstart#4-clean-up) when you no longer need it. Closing the stream does not delete the session.
2202 2212
2203[Build agents that can take action2213[Build agents that can take action
2204 2214
2205 2215
2206 2216
2207 Follow the Agents API quickstart to run a task, continue the session, and2217 Learn how to use the OpenAI platform to build powerful, capable AI agents.](https://developers.openai.com/api/docs/guides/agents)
2208 clean up.](https://developers.openai.com/api/docs/guides/agents-api/quickstart)