Skip to content

OpenAI API

OpenAI Minions inherit agents.Agent and use agents.Runner for synchronous, asynchronous, and streaming execution.

gpt


Assembly: minions Filename: gpt.py Author: Terry D. Eppler Created: 09-05-2026

Last Modified By: Terry D. Eppler Last Modified On: 09-06-2026


 gpt.py
 Copyright © 2026 Terry D. Eppler

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You can contact me at: terryeppler@gmail.com or eppler.terry@epa.gov

OpenAI Agents SDK Minion implementations.

Minion(model: str, instructions: str, tools: Sequence[Tool] | None = None, max_turns: int = 10, name: str | None = None)

Bases: Agent

Provider-native OpenAI workflow agent.

Initialize an OpenAI Minion.

Parameters:

Name Type Description Default
model str

OpenAI model identifier.

required
instructions str

System instructions for the agent.

required
tools Sequence[Tool] | None

Optional OpenAI Agents SDK tools.

None
max_turns int

Maximum model turns per execution.

10
name str | None

Optional name overriding the implementation default.

None

Returns:

Name Type Description
None None

Configuration is stored on the provider-native agent.

Source code in gpt.py
def __init__( self, model: str, instructions: str,
        tools: Sequence[ Tool ] | None=None, max_turns: int=10,
        name: str | None=None ) -> None:
    """Initialize an OpenAI Minion.

    Args:
        model (str): OpenAI model identifier.
        instructions (str): System instructions for the agent.
        tools (Sequence[Tool] | None): Optional OpenAI Agents SDK tools.
        max_turns (int): Maximum model turns per execution.
        name (str | None): Optional name overriding the implementation default.

    Returns:
        None: Configuration is stored on the provider-native agent.
    """
    throw_if( 'model', model )
    throw_if( 'instructions', instructions )
    if max_turns < 1:
        raise ValueError( 'Argument "max_turns" must be at least 1!' )
    agent_name = name or self.minion_name
    throw_if( 'name', agent_name )
    super( ).__init__( name=agent_name, model=model, instructions=instructions,
        tools=list( tools or [ ] ), )
    self.max_turns = max_turns
    self.result = None

run(prompt: str) -> RunResult

Execute the complete OpenAI workflow synchronously.

Parameters:

Name Type Description Default
prompt str

User input for the workflow.

required

Returns:

Name Type Description
RunResult RunResult

Provider-native completed run.

Source code in gpt.py
def run( self, prompt: str ) -> RunResult:
    """Execute the complete OpenAI workflow synchronously.

    Args:
        prompt (str): User input for the workflow.

    Returns:
        RunResult: Provider-native completed run.
    """
    throw_if( 'prompt', prompt )
    result = Runner.run_sync( self, prompt, max_turns=self.max_turns )
    self.result = result
    return result

run_async(prompt: str) -> RunResult async

Execute the complete OpenAI workflow asynchronously.

Parameters:

Name Type Description Default
prompt str

User input for the workflow.

required

Returns:

Name Type Description
RunResult RunResult

Provider-native completed run.

Source code in gpt.py
async def run_async( self, prompt: str ) -> RunResult:
    """Execute the complete OpenAI workflow asynchronously.

    Args:
        prompt (str): User input for the workflow.

    Returns:
        RunResult: Provider-native completed run.
    """
    throw_if( 'prompt', prompt )
    result = await Runner.run( self, prompt, max_turns=self.max_turns )
    self.result = result
    return result

stream(prompt: str) -> RunResultStreaming

Start a provider-managed streamed workflow.

Parameters:

Name Type Description Default
prompt str

User input for the workflow.

required

Returns:

Name Type Description
RunResultStreaming RunResultStreaming

Native stream with automatic tool handling.

Source code in gpt.py
def stream( self, prompt: str ) -> RunResultStreaming:
    """Start a provider-managed streamed workflow.

    Args:
        prompt (str): User input for the workflow.

    Returns:
        RunResultStreaming: Native stream with automatic tool handling.
    """
    throw_if( 'prompt', prompt )
    result = Runner.run_streamed( self, prompt, max_turns=self.max_turns )
    self.result = result
    return result

DataMinion(model: str, instructions: str, tools: Sequence[Tool] | None = None, max_turns: int = 10, name: str | None = None)

Bases: Minion

OpenAI Minion specialized for data workflows.

Source code in gpt.py
def __init__( self, model: str, instructions: str,
        tools: Sequence[ Tool ] | None=None, max_turns: int=10,
        name: str | None=None ) -> None:
    """Initialize an OpenAI Minion.

    Args:
        model (str): OpenAI model identifier.
        instructions (str): System instructions for the agent.
        tools (Sequence[Tool] | None): Optional OpenAI Agents SDK tools.
        max_turns (int): Maximum model turns per execution.
        name (str | None): Optional name overriding the implementation default.

    Returns:
        None: Configuration is stored on the provider-native agent.
    """
    throw_if( 'model', model )
    throw_if( 'instructions', instructions )
    if max_turns < 1:
        raise ValueError( 'Argument "max_turns" must be at least 1!' )
    agent_name = name or self.minion_name
    throw_if( 'name', agent_name )
    super( ).__init__( name=agent_name, model=model, instructions=instructions,
        tools=list( tools or [ ] ), )
    self.max_turns = max_turns
    self.result = None

GovernanceMinion(model: str, instructions: str, tools: Sequence[Tool] | None = None, max_turns: int = 10, name: str | None = None)

Bases: Minion

OpenAI Minion specialized for governance workflows.

Source code in gpt.py
def __init__( self, model: str, instructions: str,
        tools: Sequence[ Tool ] | None=None, max_turns: int=10,
        name: str | None=None ) -> None:
    """Initialize an OpenAI Minion.

    Args:
        model (str): OpenAI model identifier.
        instructions (str): System instructions for the agent.
        tools (Sequence[Tool] | None): Optional OpenAI Agents SDK tools.
        max_turns (int): Maximum model turns per execution.
        name (str | None): Optional name overriding the implementation default.

    Returns:
        None: Configuration is stored on the provider-native agent.
    """
    throw_if( 'model', model )
    throw_if( 'instructions', instructions )
    if max_turns < 1:
        raise ValueError( 'Argument "max_turns" must be at least 1!' )
    agent_name = name or self.minion_name
    throw_if( 'name', agent_name )
    super( ).__init__( name=agent_name, model=model, instructions=instructions,
        tools=list( tools or [ ] ), )
    self.max_turns = max_turns
    self.result = None

ResearchMinion(model: str, instructions: str, tools: Sequence[Tool] | None = None, max_turns: int = 10, name: str | None = None)

Bases: Minion

OpenAI Minion specialized for research workflows.

Source code in gpt.py
def __init__( self, model: str, instructions: str,
        tools: Sequence[ Tool ] | None=None, max_turns: int=10,
        name: str | None=None ) -> None:
    """Initialize an OpenAI Minion.

    Args:
        model (str): OpenAI model identifier.
        instructions (str): System instructions for the agent.
        tools (Sequence[Tool] | None): Optional OpenAI Agents SDK tools.
        max_turns (int): Maximum model turns per execution.
        name (str | None): Optional name overriding the implementation default.

    Returns:
        None: Configuration is stored on the provider-native agent.
    """
    throw_if( 'model', model )
    throw_if( 'instructions', instructions )
    if max_turns < 1:
        raise ValueError( 'Argument "max_turns" must be at least 1!' )
    agent_name = name or self.minion_name
    throw_if( 'name', agent_name )
    super( ).__init__( name=agent_name, model=model, instructions=instructions,
        tools=list( tools or [ ] ), )
    self.max_turns = max_turns
    self.result = None

CodingMinion(model: str, instructions: str, tools: Sequence[Tool] | None = None, max_turns: int = 10, name: str | None = None)

Bases: Minion

OpenAI Minion specialized for software workflows.

Source code in gpt.py
def __init__( self, model: str, instructions: str,
        tools: Sequence[ Tool ] | None=None, max_turns: int=10,
        name: str | None=None ) -> None:
    """Initialize an OpenAI Minion.

    Args:
        model (str): OpenAI model identifier.
        instructions (str): System instructions for the agent.
        tools (Sequence[Tool] | None): Optional OpenAI Agents SDK tools.
        max_turns (int): Maximum model turns per execution.
        name (str | None): Optional name overriding the implementation default.

    Returns:
        None: Configuration is stored on the provider-native agent.
    """
    throw_if( 'model', model )
    throw_if( 'instructions', instructions )
    if max_turns < 1:
        raise ValueError( 'Argument "max_turns" must be at least 1!' )
    agent_name = name or self.minion_name
    throw_if( 'name', agent_name )
    super( ).__init__( name=agent_name, model=model, instructions=instructions,
        tools=list( tools or [ ] ), )
    self.max_turns = max_turns
    self.result = None

WritingMinion(model: str, instructions: str, tools: Sequence[Tool] | None = None, max_turns: int = 10, name: str | None = None)

Bases: Minion

OpenAI Minion specialized for writing workflows.

Source code in gpt.py
def __init__( self, model: str, instructions: str,
        tools: Sequence[ Tool ] | None=None, max_turns: int=10,
        name: str | None=None ) -> None:
    """Initialize an OpenAI Minion.

    Args:
        model (str): OpenAI model identifier.
        instructions (str): System instructions for the agent.
        tools (Sequence[Tool] | None): Optional OpenAI Agents SDK tools.
        max_turns (int): Maximum model turns per execution.
        name (str | None): Optional name overriding the implementation default.

    Returns:
        None: Configuration is stored on the provider-native agent.
    """
    throw_if( 'model', model )
    throw_if( 'instructions', instructions )
    if max_turns < 1:
        raise ValueError( 'Argument "max_turns" must be at least 1!' )
    agent_name = name or self.minion_name
    throw_if( 'name', agent_name )
    super( ).__init__( name=agent_name, model=model, instructions=instructions,
        tools=list( tools or [ ] ), )
    self.max_turns = max_turns
    self.result = None

PlanningMinion(model: str, instructions: str, tools: Sequence[Tool] | None = None, max_turns: int = 10, name: str | None = None)

Bases: Minion

OpenAI Minion specialized for planning workflows.

Source code in gpt.py
def __init__( self, model: str, instructions: str,
        tools: Sequence[ Tool ] | None=None, max_turns: int=10,
        name: str | None=None ) -> None:
    """Initialize an OpenAI Minion.

    Args:
        model (str): OpenAI model identifier.
        instructions (str): System instructions for the agent.
        tools (Sequence[Tool] | None): Optional OpenAI Agents SDK tools.
        max_turns (int): Maximum model turns per execution.
        name (str | None): Optional name overriding the implementation default.

    Returns:
        None: Configuration is stored on the provider-native agent.
    """
    throw_if( 'model', model )
    throw_if( 'instructions', instructions )
    if max_turns < 1:
        raise ValueError( 'Argument "max_turns" must be at least 1!' )
    agent_name = name or self.minion_name
    throw_if( 'name', agent_name )
    super( ).__init__( name=agent_name, model=model, instructions=instructions,
        tools=list( tools or [ ] ), )
    self.max_turns = max_turns
    self.result = None

ComplianceMinion(model: str, instructions: str, tools: Sequence[Tool] | None = None, max_turns: int = 10, name: str | None = None)

Bases: Minion

OpenAI Minion specialized for compliance, legal, and budget workflows.

Source code in gpt.py
def __init__( self, model: str, instructions: str,
        tools: Sequence[ Tool ] | None=None, max_turns: int=10,
        name: str | None=None ) -> None:
    """Initialize an OpenAI Minion.

    Args:
        model (str): OpenAI model identifier.
        instructions (str): System instructions for the agent.
        tools (Sequence[Tool] | None): Optional OpenAI Agents SDK tools.
        max_turns (int): Maximum model turns per execution.
        name (str | None): Optional name overriding the implementation default.

    Returns:
        None: Configuration is stored on the provider-native agent.
    """
    throw_if( 'model', model )
    throw_if( 'instructions', instructions )
    if max_turns < 1:
        raise ValueError( 'Argument "max_turns" must be at least 1!' )
    agent_name = name or self.minion_name
    throw_if( 'name', agent_name )
    super( ).__init__( name=agent_name, model=model, instructions=instructions,
        tools=list( tools or [ ] ), )
    self.max_turns = max_turns
    self.result = None

BusinessMinion(model: str, instructions: str, tools: Sequence[Tool] | None = None, max_turns: int = 10, name: str | None = None)

Bases: Minion

OpenAI Minion specialized for business, finance, and marketing workflows.

Source code in gpt.py
def __init__( self, model: str, instructions: str,
        tools: Sequence[ Tool ] | None=None, max_turns: int=10,
        name: str | None=None ) -> None:
    """Initialize an OpenAI Minion.

    Args:
        model (str): OpenAI model identifier.
        instructions (str): System instructions for the agent.
        tools (Sequence[Tool] | None): Optional OpenAI Agents SDK tools.
        max_turns (int): Maximum model turns per execution.
        name (str | None): Optional name overriding the implementation default.

    Returns:
        None: Configuration is stored on the provider-native agent.
    """
    throw_if( 'model', model )
    throw_if( 'instructions', instructions )
    if max_turns < 1:
        raise ValueError( 'Argument "max_turns" must be at least 1!' )
    agent_name = name or self.minion_name
    throw_if( 'name', agent_name )
    super( ).__init__( name=agent_name, model=model, instructions=instructions,
        tools=list( tools or [ ] ), )
    self.max_turns = max_turns
    self.result = None

ImageGenerationMinion(model: str, instructions: str, tools: Sequence[Tool] | None = None, max_turns: int = 10, name: str | None = None)

Bases: Minion

OpenAI Minion specialized for image-generation workflows.

Source code in gpt.py
def __init__( self, model: str, instructions: str,
        tools: Sequence[ Tool ] | None=None, max_turns: int=10,
        name: str | None=None ) -> None:
    """Initialize an OpenAI Minion.

    Args:
        model (str): OpenAI model identifier.
        instructions (str): System instructions for the agent.
        tools (Sequence[Tool] | None): Optional OpenAI Agents SDK tools.
        max_turns (int): Maximum model turns per execution.
        name (str | None): Optional name overriding the implementation default.

    Returns:
        None: Configuration is stored on the provider-native agent.
    """
    throw_if( 'model', model )
    throw_if( 'instructions', instructions )
    if max_turns < 1:
        raise ValueError( 'Argument "max_turns" must be at least 1!' )
    agent_name = name or self.minion_name
    throw_if( 'name', agent_name )
    super( ).__init__( name=agent_name, model=model, instructions=instructions,
        tools=list( tools or [ ] ), )
    self.max_turns = max_turns
    self.result = None

ImageAnalysisMinion(model: str, instructions: str, tools: Sequence[Tool] | None = None, max_turns: int = 10, name: str | None = None)

Bases: Minion

OpenAI Minion specialized for image-analysis workflows.

Source code in gpt.py
def __init__( self, model: str, instructions: str,
        tools: Sequence[ Tool ] | None=None, max_turns: int=10,
        name: str | None=None ) -> None:
    """Initialize an OpenAI Minion.

    Args:
        model (str): OpenAI model identifier.
        instructions (str): System instructions for the agent.
        tools (Sequence[Tool] | None): Optional OpenAI Agents SDK tools.
        max_turns (int): Maximum model turns per execution.
        name (str | None): Optional name overriding the implementation default.

    Returns:
        None: Configuration is stored on the provider-native agent.
    """
    throw_if( 'model', model )
    throw_if( 'instructions', instructions )
    if max_turns < 1:
        raise ValueError( 'Argument "max_turns" must be at least 1!' )
    agent_name = name or self.minion_name
    throw_if( 'name', agent_name )
    super( ).__init__( name=agent_name, model=model, instructions=instructions,
        tools=list( tools or [ ] ), )
    self.max_turns = max_turns
    self.result = None

ImageEditingMinion(model: str, instructions: str, tools: Sequence[Tool] | None = None, max_turns: int = 10, name: str | None = None)

Bases: Minion

OpenAI Minion specialized for image-editing workflows.

Source code in gpt.py
def __init__( self, model: str, instructions: str,
        tools: Sequence[ Tool ] | None=None, max_turns: int=10,
        name: str | None=None ) -> None:
    """Initialize an OpenAI Minion.

    Args:
        model (str): OpenAI model identifier.
        instructions (str): System instructions for the agent.
        tools (Sequence[Tool] | None): Optional OpenAI Agents SDK tools.
        max_turns (int): Maximum model turns per execution.
        name (str | None): Optional name overriding the implementation default.

    Returns:
        None: Configuration is stored on the provider-native agent.
    """
    throw_if( 'model', model )
    throw_if( 'instructions', instructions )
    if max_turns < 1:
        raise ValueError( 'Argument "max_turns" must be at least 1!' )
    agent_name = name or self.minion_name
    throw_if( 'name', agent_name )
    super( ).__init__( name=agent_name, model=model, instructions=instructions,
        tools=list( tools or [ ] ), )
    self.max_turns = max_turns
    self.result = None

TranslationMinion(model: str, instructions: str, tools: Sequence[Tool] | None = None, max_turns: int = 10, name: str | None = None)

Bases: Minion

OpenAI Minion specialized for translation workflows.

Source code in gpt.py
def __init__( self, model: str, instructions: str,
        tools: Sequence[ Tool ] | None=None, max_turns: int=10,
        name: str | None=None ) -> None:
    """Initialize an OpenAI Minion.

    Args:
        model (str): OpenAI model identifier.
        instructions (str): System instructions for the agent.
        tools (Sequence[Tool] | None): Optional OpenAI Agents SDK tools.
        max_turns (int): Maximum model turns per execution.
        name (str | None): Optional name overriding the implementation default.

    Returns:
        None: Configuration is stored on the provider-native agent.
    """
    throw_if( 'model', model )
    throw_if( 'instructions', instructions )
    if max_turns < 1:
        raise ValueError( 'Argument "max_turns" must be at least 1!' )
    agent_name = name or self.minion_name
    throw_if( 'name', agent_name )
    super( ).__init__( name=agent_name, model=model, instructions=instructions,
        tools=list( tools or [ ] ), )
    self.max_turns = max_turns
    self.result = None

TranscriptionMinion(model: str, instructions: str, tools: Sequence[Tool] | None = None, max_turns: int = 10, name: str | None = None)

Bases: Minion

OpenAI Minion specialized for transcription workflows.

Source code in gpt.py
def __init__( self, model: str, instructions: str,
        tools: Sequence[ Tool ] | None=None, max_turns: int=10,
        name: str | None=None ) -> None:
    """Initialize an OpenAI Minion.

    Args:
        model (str): OpenAI model identifier.
        instructions (str): System instructions for the agent.
        tools (Sequence[Tool] | None): Optional OpenAI Agents SDK tools.
        max_turns (int): Maximum model turns per execution.
        name (str | None): Optional name overriding the implementation default.

    Returns:
        None: Configuration is stored on the provider-native agent.
    """
    throw_if( 'model', model )
    throw_if( 'instructions', instructions )
    if max_turns < 1:
        raise ValueError( 'Argument "max_turns" must be at least 1!' )
    agent_name = name or self.minion_name
    throw_if( 'name', agent_name )
    super( ).__init__( name=agent_name, model=model, instructions=instructions,
        tools=list( tools or [ ] ), )
    self.max_turns = max_turns
    self.result = None

SpeechMinion(model: str, instructions: str, tools: Sequence[Tool] | None = None, max_turns: int = 10, name: str | None = None)

Bases: Minion

OpenAI Minion specialized for speech workflows.

Source code in gpt.py
def __init__( self, model: str, instructions: str,
        tools: Sequence[ Tool ] | None=None, max_turns: int=10,
        name: str | None=None ) -> None:
    """Initialize an OpenAI Minion.

    Args:
        model (str): OpenAI model identifier.
        instructions (str): System instructions for the agent.
        tools (Sequence[Tool] | None): Optional OpenAI Agents SDK tools.
        max_turns (int): Maximum model turns per execution.
        name (str | None): Optional name overriding the implementation default.

    Returns:
        None: Configuration is stored on the provider-native agent.
    """
    throw_if( 'model', model )
    throw_if( 'instructions', instructions )
    if max_turns < 1:
        raise ValueError( 'Argument "max_turns" must be at least 1!' )
    agent_name = name or self.minion_name
    throw_if( 'name', agent_name )
    super( ).__init__( name=agent_name, model=model, instructions=instructions,
        tools=list( tools or [ ] ), )
    self.max_turns = max_turns
    self.result = None