OpenAI Agents SDK
Build autonomous agents that request human review when needed.
The OpenAI Agents SDK supports MCP (Model Context Protocol) servers, allowing your agent to use Datashift tools directly. The agent decides when to request human review based on its instructions and reasoning.
Agent-Initiated Review
With MCP integration, the agent decides when to request human input. You provide guidance in the agent's instructions, but the agent autonomously determines when to call the Datashift MCP tools. For developer-enforced review where you define which actions require approval in code, see the Anthropic SDK guide.
Prerequisites
- •A Datashift account with MCP credentials
- •An OpenAI API key
- •Python 3.9+
Installation
pip install openai-agentsSet your environment variables:
export OPENAI_API_KEY=sk-...
export DATASHIFT_ACCESS_TOKEN=<your-access-token>Get your access token from Settings → Credentials → MCP.
MCP Configuration
The Datashift MCP server provides these tools to your agent:
submit_taskSubmit data for human review. Returns a task ID and resource URI.
list_queuesList available review queues and their configurations.
get_queue_configGet details about a specific queue.
When a review completes, the MCP server sends a notifications/resources/updated notification. The agent can then read the task resource to get the decision.
Full Example
Here's an agent that autonomously decides when to request human approval:
import os
from agents import Agent, Runner
from agents.mcp import MCPServerSse
# Connect to Datashift MCP server
datashift_server = MCPServerSse(
url="https://mcp.datashift.io/sse",
headers={
"Authorization": f"Bearer {os.environ['DATASHIFT_ACCESS_TOKEN']}"
}
)
# Create agent with access to Datashift MCP tools
agent = Agent(
name="Customer Support Agent",
instructions="""You are a customer support agent that helps customers.
When you need to take important actions like sending emails, updating records,
or making changes that could affect customers, use the submit_task tool from
the datashift MCP server to get human approval first.
For example, before sending any email:
1. Call submit_task with queue_key="outbound-communications"
2. Include the email details in the data field
3. Wait for the task to be reviewed
4. Read the task resource to check if it was approved
5. Only proceed if approved
You decide when human review is needed based on the sensitivity of the action.""",
mcp_servers=[datashift_server],
)
# Run the agent
runner = Runner()
response = runner.run(
agent,
messages=[{
"role": "user",
"content": "Send a follow-up email to john@example.com thanking them for their purchase"
}]
)
print(response.final_output)How It Works
Agent reasons about the task
Based on its instructions, the agent determines it should get human approval before sending an email.
Agent calls submit_task
The agent uses the Datashift MCP tool to submit the email for review.
Human reviews
A reviewer sees the task in Datashift Console and approves or rejects it.
Agent receives notification
The MCP server notifies the agent. It reads the task resource and proceeds based on the decision.
Crafting Agent Instructions
Guide the agent on when to request review. Be specific about the criteria:
agent = Agent(
name="Data Processing Agent",
instructions="""You process and enrich customer data.
When you encounter situations where you're uncertain about data quality
or need human verification, use the Datashift MCP tools:
- submit_task: Submit data for human review
- list_queues: See available review queues
- get_queue_config: Check queue settings
Use queue_key="data-verification" for data quality checks.
Use queue_key="customer-updates" for customer record changes.
You decide when to request review based on:
- Data confidence level
- Potential customer impact
- Regulatory requirements
After submitting a task, the MCP server will notify you when the review
is complete. Read the task resource to get the reviewer's decision.""",
mcp_servers=[datashift_server],
)Multi-Agent Workflows
Use handoffs to create specialized review coordination:
from agents import Agent, handoff
# Agent that handles human review via Datashift
review_agent = Agent(
name="Human Review Coordinator",
instructions="""You coordinate human reviews via Datashift.
When another agent hands off to you, submit the task for review
using the submit_task MCP tool. Monitor for completion and
return the reviewer's decision.""",
mcp_servers=[datashift_server],
)
# Main agent that can escalate to human review
main_agent = Agent(
name="Sales Agent",
instructions="""You handle sales inquiries.
For high-value deals over $10,000 or complex negotiations,
hand off to the Human Review Coordinator for approval before
finalizing any commitments.""",
handoffs=[handoff(review_agent)],
)Best Practices
Be specific in instructions
Clearly define when the agent should request review: thresholds, action types, uncertainty levels.
Include queue guidance
Tell the agent which queues to use for different types of reviews.
Handle all outcomes
Instruct the agent on what to do when reviews are approved, rejected, or time out.
Provide context
Encourage the agent to include relevant context when submitting tasks so reviewers have full information.