Class Runner

All Implemented Interfaces:
EventEmitter<RunHookEvents<Object,TextOutput>>

public class Runner extends RunHooks<Object,TextOutput>
Runner

Executes agents and manages their interactions with models.

Ported from TypeScript OpenAI Agents SDK Source: run.ts

  • Constructor Details

    • Runner

      public Runner()
  • Method Details

    • run

      public static <TContext, TOutput extends AgentOutputType> RunResult<TContext,?> run(Agent<TContext,TOutput> agent, String input)
      Static convenience method to run an agent with a single text input (blocking).

      This is the primary entry point for simple hello-world usage.

      Type Parameters:
      TContext - The context type
      TOutput - The output type
      Parameters:
      agent - The agent to run
      input - The input text
      Returns:
      The run result
    • runAsync

      public static <TContext, TOutput extends AgentOutputType> CompletableFuture<RunResult<TContext,?>> runAsync(Agent<TContext,TOutput> agent, String input)
      Static method to run an agent asynchronously with a single text input.
      Type Parameters:
      TContext - The context type
      TOutput - The output type
      Parameters:
      agent - The agent to run
      input - The input text
      Returns:
      CompletableFuture that resolves to the run result
    • run

      public static <TContext, TOutput extends AgentOutputType> RunResult<TContext,?> run(Agent<TContext,TOutput> agent, String input, RunConfig config)
      Static method to run an agent with custom configuration (blocking).
      Type Parameters:
      TContext - The context type
      TOutput - The output type
      Parameters:
      agent - The agent to run
      input - The input text
      config - Custom run configuration
      Returns:
      The run result
    • runAsync

      public static <TContext, TOutput extends AgentOutputType> CompletableFuture<RunResult<TContext,?>> runAsync(Agent<TContext,TOutput> agent, String input, RunConfig config)
      Static method to run an agent asynchronously with custom configuration.
      Type Parameters:
      TContext - The context type
      TOutput - The output type
      Parameters:
      agent - The agent to run
      input - The input text
      config - Custom run configuration
      Returns:
      CompletableFuture that resolves to the run result
    • runStreamed

      public static <TContext, TOutput extends AgentOutputType> StreamedRunResult<TContext,Agent<TContext,TOutput>> runStreamed(Agent<TContext,TOutput> agent, String input)
      Static method to run an agent with streaming event emission.

      Returns immediately with a StreamedRunResult. Events are emitted in real-time as execution progresses. Use toStream() to iterate over events.

      Type Parameters:
      TContext - The context type
      TOutput - The output type
      Parameters:
      agent - The agent to run
      input - The input text
      Returns:
      StreamedRunResult with event stream
    • runStreamed

      public static <TContext, TOutput extends AgentOutputType> StreamedRunResult<TContext,Agent<TContext,TOutput>> runStreamed(Agent<TContext,TOutput> agent, String input, RunConfig config)
      Static method to run an agent with streaming and custom configuration.
      Type Parameters:
      TContext - The context type
      TOutput - The output type
      Parameters:
      agent - The agent to run
      input - The input text
      config - Custom run configuration
      Returns:
      StreamedRunResult with event stream