This page covers testing and development utilities for the OpenAI Agents SDK: helper functions for interactive mode fallbacks and citation extraction, scripted model testing with ScriptedModel.extend, demo loop execution patterns, and logging/test suite configuration.
Use input_with_fallback to return a preset string instead of prompting when EXAMPLES_INTERACTIVE_MODE=auto is set
from examples.auto_mode import input_with_fallback
user_input = input_with_fallback("Enter your question: ", "What is the weather today?")
Use confirm_with_fallback to auto-approve confirmations when EXAMPLES_INTERACTIVE_MODE=auto is set
from examples.auto_mode import confirm_with_fallback
approved = confirm_with_fallback("Proceed with action? (y/n): ", default=True)
Extract deduplicated URLCitation objects (title + URL) from a sequence of run output items using extract_url_citations
from examples.web_search_utils import extract_url_citations
citations = extract_url_citations(result.new_items)
for citation in citations:
print(citation.title, citation.url)
Run all auto-mode examples via Make, optionally filtering by substring or enabling extra categories
# Run all examples
make examples-run
# Run only examples whose path contains "basic"
make examples-run EXAMPLES_ARGS="--filter basic"
# Include server and audio examples
make examples-run EXAMPLES_ARGS="--include-server --include-audio"
Run a multi-turn non-streaming demo loop with ScriptedModel.extend providing per-turn responses, feeding simulated user input via monkeypatched builtins.input
model = ScriptedModel()
model.extend([[get_text_message("hello")], [get_text_message("good")]])
agent = Agent(name="test", model=model)
inputs = iter(["Hi", "How are you?", "quit"])
monkeypatch.setattr("builtins.input", lambda _=" > ": next(inputs))
await run_demo_loop(agent, stream=False)
Run a streaming demo loop that exercises tool calls, tool outputs, and agent handoffs using ScriptedModel.extend with multi-step scripted responses
model = ScriptedModel()
agent = Agent(
name="test",
model=model,
tools=[get_function_tool("foo", "tool_result")],
handoffs=[target_agent],
)
model.extend(
[
[get_function_tool_call("foo", "{}")],
[get_handoff_tool_call(target_agent)],
[get_text_message("all done")],
]
)
inputs = iter(["Hello", "exit"])
monkeypatch.setattr("builtins.input", lambda _=" > ": next(inputs))
await run_demo_loop(agent, stream=True)
ScriptedModel is a test double that replaces a real OpenAI model with a pre-programmed sequence of responses, enabling deterministic unit tests without live API calls or network access.
Control model-data and tool-data logging with OPENAI_AGENTS_DONT_LOG_MODEL_DATA / OPENAI_AGENTS_DONT_LOG_TOOL_DATA env vars; the loaders default to True when the variable is absent
# Unset → True (logging suppressed by default)
_load_dont_log_model_data() # True
# Explicit "0" or "false" → False (logging enabled)
# Explicit "1" or "true" → True (logging suppressed)
_load_dont_log_tool_data() # True when OPENAI_AGENTS_DONT_LOG_TOOL_DATA unset
Run the full test suite (xdist parallel + serial) with make tests; fix or create inline snapshots with dedicated make targets
make tests # shard-safe parallel run then serial tests
make snapshots-fix # fix broken inline-snapshot assertions
make snapshots-create # create new inline-snapshot assertions
Sources