
by Pierre Placide
The computer use models are exciting. The cool thing about computer use is that we're just so, so early. It's like the GPT-2 of computer use or maybe GPT-1 of computer use right now.
We said 2025 was the year of agents. So there you have it, like a lot of new tools to build these agents for developers.
import openai
client = openai.OpenAI()
# Create a response with web search enabled
response = client.beta.responses.create(
model="gpt-4o",
tools=[{"type": "web_search"}],
messages=[
{"role": "user", "content": "What are the latest developments in quantum computing?"}
]
)
# Print the response
print(response.choices[0].message.content)
# The response includes citations to web sources
import openai
client = openai.OpenAI()
# Using web search as a tool in Responses API
response = client.beta.responses.create(
model="gpt-4o",
tools=[{"type": "web_search"}],
messages=[
{"role": "user", "content": "What were the key announcements at the last Apple event?"}
]
)
# Using the dedicated search model in Chat Completions
chat_completion = client.chat.completions.create(
model="gpt-4o-search-preview",
messages=[
{"role": "user", "content": "What were the key announcements at the last Apple event?"}
]
)
import openai
client = openai.OpenAI()
# First, upload a file
file = client.files.create(
file=open("company_policies.pdf", "rb"),
purpose="file-search"
)
# Create a file search tool
response = client.beta.responses.create(
model="gpt-4o",
tools=[{
"type": "file_search",
"file_ids": [file.id]
}],
messages=[
{"role": "user", "content": "What is our company's travel reimbursement policy?"}
]
)
# Print the response with information from the file
print(response.choices[0].message.content)
import openai
import base64
from PIL import ImageGrab
import io
client = openai.OpenAI()
# Capture screenshot
screenshot = ImageGrab.grab()
buffer = io.BytesIO()
screenshot.save(buffer, format="PNG")
screenshot_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
# Create a computer use request
response = client.beta.responses.create(
model="gpt-4o",
tools=[{
"type": "computer_use",
"environment": {
"type": "browser",
"url": "https://example.com"
}
}],
messages=[
{"role": "user", "content": "Find the contact information on this website"},
{"role": "user", "content": [
{"type": "image", "image_url": {
"url": f"data:image/png;base64,{screenshot_base64}"
}}
]}
]
)
# The response will include tool calls with actions to take
from openai_agents import Agent, Workflow
# Define a research agent
research_agent = Agent(
name="researcher",
instructions="You are a research agent. Find information on the given topic.",
tools=[{"type": "web_search"}]
)
# Define a summarization agent
summary_agent = Agent(
name="summarizer",
instructions="You are a summarization agent. Create concise summaries of research findings."
)
# Create a workflow with handoff
workflow = Workflow(
name="research_workflow",
agents=[research_agent, summary_agent],
initial_agent="researcher"
)
# Execute the workflow
result = workflow.run("What are the latest advancements in fusion energy?")
print(result)
from openai_agents import Agent, Workflow, Guardrail
# Define a content safety guardrail
safety_guardrail = Guardrail(
name="content_safety",
instructions="Ensure all content is appropriate and does not contain harmful material.",
criteria="Content must be factual, respectful, and appropriate for all audiences."
)
# Define an agent with guardrails
content_agent = Agent(
name="content_creator",
instructions="Create engaging content on the given topic.",
guardrails=[safety_guardrail]
)
# Create a workflow with the guarded agent
workflow = Workflow(
name="content_workflow",
agents=[content_agent],
initial_agent="content_creator"
)
# Execute the workflow
result = workflow.run("Write a short article about controversial political topics")
# The guardrail will intervene if the content violates the safety criteria
from openai_agents import Agent, Workflow, Tracer
from openai_agents.tracers import OpenAITracer
# Initialize the OpenAI tracer
tracer = OpenAITracer()
# Define agents
planner_agent = Agent(
name="planner",
instructions="Create a plan for completing the task."
)
executor_agent = Agent(
name="executor",
instructions="Execute the plan created by the planner."
)
# Create a workflow with tracing enabled
workflow = Workflow(
name="traced_workflow",
agents=[planner_agent, executor_agent],
initial_agent="planner",
tracer=tracer
)
# Execute the workflow
result = workflow.run("Organize a virtual team-building event")
# Trace ID can be used to view the execution in the OpenAI dashboard
print(f"View trace in dashboard: {tracer.trace_id}")
from openai_agents import Agent, ParallelWorkflow
# Define multiple research agents for different sources
news_agent = Agent(
name="news_researcher",
instructions="Research recent news articles on the topic.",
tools=[{"type": "web_search"}]
)
academic_agent = Agent(
name="academic_researcher",
instructions="Research academic papers on the topic.",
tools=[{"type": "web_search"}]
)
social_agent = Agent(
name="social_researcher",
instructions="Research social media discussions on the topic.",
tools=[{"type": "web_search"}]
)
# Create a parallel workflow
parallel_workflow = ParallelWorkflow(
name="comprehensive_research",
agents=[news_agent, academic_agent, social_agent]
)
# Execute all agents in parallel
results = parallel_workflow.run("Impact of artificial intelligence on job markets")
# Process the combined results
for agent_name, result in results.items():
print(f"Findings from {agent_name}:")
print(result)
from openai_agents import Agent, Workflow, Judge
# Define content creation agents with different styles
formal_agent = Agent(
name="formal_writer",
instructions="Write in a formal, professional style."
)
casual_agent = Agent(
name="casual_writer",
instructions="Write in a casual, conversational style."
)
# Define a judge to select the best output
style_judge = Judge(
name="style_selector",
instructions="Select the writing style that best matches the user's request.",
criteria="Consider tone, formality, and appropriateness for the intended audience."
)
# Create a workflow with judgment
workflow = Workflow(
name="adaptive_writing",
agents=[formal_agent, casual_agent],
judge=style_judge
)
# Execute the workflow with context about the audience
result = workflow.run("Write an email about our new product launch. The audience is corporate executives.")
# The judge will select the formal style for this audience
from openai_agents import Agent, Tool, Workflow
# Define specialized agents as tools
translation_agent = Agent(
name="translator",
instructions="Translate text between languages accurately."
)
summarization_agent = Agent(
name="summarizer",
instructions="Create concise summaries of longer texts."
)
# Create tools that invoke these agents
translation_tool = Tool(
name="translate",
description="Translate text to a specified language",
agent=translation_agent
)
summarization_tool = Tool(
name="summarize",
description="Create a summary of the provided text",
agent=summarization_agent
)
# Define a coordinator agent that uses these tools
coordinator_agent = Agent(
name="content_processor",
instructions="Process content according to user instructions.",
tools=[translation_tool, summarization_tool]
)
# Create a workflow
workflow = Workflow(
name="content_processing",
agents=[coordinator_agent, translation_agent, summarization_agent],
initial_agent="content_processor"
)
# Execute the workflow
result = workflow.run("Find a news article about climate change, summarize it, and translate the summary to Spanish.")
Swarm just came to life out of learning from customers directly that orchestrating agents in production was pretty hard. Simple ideas could quickly turn very complex. Like what are those guardrails? What are those handoffs, et cetera? So that came out of learning from customers. And it was initially shipped as a low-key experiment, I'd say. But we were kind of taken by surprise at how much momentum there was around this concept.




