Skip to content
Navigation

Local agent executor for Orbiter CLI. Wraps orbiter.runner.run and orbiter.runner.run.stream with Rich output formatting, error handling, timeout support, and provider resolution.

python
from orbiter_cli.executor import ExecutionResult, ExecutorError, LocalExecutor

ExecutorError

python
class ExecutorError(Exception)

Raised for execution-level errors (timeout, agent failure, streaming not available).


ExecutionResult

python
class ExecutionResult(
    *,
    output: str,
    steps: int = 0,
    elapsed: float = 0.0,
    usage: dict[str, int] | None = None,
    raw: Any = None,
)

Wraps a run result with CLI-friendly accessors.

Constructor parameters

NameTypeDefaultDescription
outputstr(required)Agent output text
stepsint0Number of LLM call steps
elapsedfloat0.0Wall-clock seconds
usagedict[str, int] | NoneNoneToken usage dict (prompt_tokens, output_tokens, total_tokens)
rawAnyNoneThe underlying RunResult object (if available)

Properties

PropertyTypeDescription
outputstrAgent output text
stepsintNumber of LLM call steps
elapsedfloatWall-clock seconds
usagedict[str, int]Copy of token usage dict
rawAnyThe underlying RunResult object

Methods

summary

python
def summary(self) -> str

Human-readable one-line summary including step count, elapsed time, and token count.

Example

python
result = ExecutionResult(output="Hello!", steps=2, elapsed=1.5, usage={"total_tokens": 150})
print(result.output)    # "Hello!"
print(result.summary()) # "2 step(s), 1.5s, 150 tokens"

LocalExecutor

python
class LocalExecutor(
    *,
    agent: Any,
    provider: Any = None,
    timeout: float = 0.0,
    max_retries: int = 3,
    console: RichConsole | None = None,
    verbose: bool = False,
)

Executes agents locally via orbiter.runner.run.

Constructor parameters

NameTypeDefaultDescription
agentAny(required)An Agent (or Swarm) instance
providerAnyNoneLLM provider. When None, auto-resolved
timeoutfloat0.0Per-execution timeout in seconds (0 = no timeout)
max_retriesint3Retry attempts for transient LLM errors
consoleRichConsole | NoneNoneRich console for formatted output (default: stderr)
verboseboolFalseWhen True, print timing and usage details

Properties

PropertyTypeDescription
agentAnyThe agent instance
timeoutfloatPer-execution timeout in seconds
verboseboolWhether verbose output is enabled

Methods

execute

python
async def execute(
    self,
    input: str,
    *,
    messages: Sequence[Any] | None = None,
) -> ExecutionResult

Run the agent and return an ExecutionResult. Calls orbiter.runner.run() with the configured agent, provider, and retry settings.

NameTypeDefaultDescription
inputstr(required)User input text
messagesSequence[Any] | NoneNoneOptional conversation history

Returns: ExecutionResult with output, steps, elapsed time, usage, and raw result.

Raises: ExecutorError — On timeout or agent failure.

stream

python
async def stream(
    self,
    input: str,
    *,
    messages: Sequence[Any] | None = None,
) -> AsyncIterator[str]

Stream agent output, yielding text chunks. Uses orbiter.runner.run.stream if available.

NameTypeDefaultDescription
inputstr(required)User input text
messagesSequence[Any] | NoneNoneOptional conversation history

Yields: str — Text chunks from the agent.

Raises: ExecutorError — If streaming is not available or fails during execution.

python
def print_result(self, result: ExecutionResult) -> None

Pretty-print an execution result to the console using a Rich Panel.

python
def print_error(self, error: Exception) -> None

Display an error to the console in red.

Example

python
from orbiter_cli import LocalExecutor

executor = LocalExecutor(agent=my_agent, timeout=30.0, verbose=True)

# Non-streaming execution
result = await executor.execute("What is Python?")
executor.print_result(result)

# Streaming execution
async for chunk in executor.stream("Explain decorators"):
    print(chunk, end="")