Files
codex/sdk/python/src/openai_codex/__init__.py
T
Ahmed Ibrahim 1a4096e273 Add untrusted external messages to the Python SDK (#44086)
## Why

Applications need to deliver content from other agents, tools, or services with tool-level authority, without treating it as user input or granting authorization.

## What changed

- Export `ExternalMessage` for sync and async `run(...)` and `turn(...)`, accepting text or structured content with a tool name and optional namespace. Send it through `toolOutput` and require CLI 0.151.0 or newer.
- Support starting a turn or joining an active regular turn while preserving external content as function output in history. Keep external messages separate from user-input lists and `steer(...)`.
- Give turn handles independent subscriptions, replaying completed items and latest usage to joining handles. Release consumed transient events and clean up subscriptions on closure, failure, or cancellation.
- Document the authority boundary and add sync and async examples.

## Testing

Add coverage for wire representations, input validation, runtime compatibility, tool authority across resume, active-turn joins, and tool-output truncation. Add subscription tests for replay, concurrent consumers, early completion, cancellation, and cleanup.

GitOrigin-RevId: 6106327085fd9c4bd11b71e20b3d8e74738b8bb5
2026-09-09 06:54:18 +00:00

96 lines
2.0 KiB
Python

"""Python SDK for running Codex workflows.
Start with :class:`Codex` for synchronous applications or
:class:`AsyncCodex` for async applications. Most programs create a thread and
run a turn::
from openai_codex import Codex, Sandbox
with Codex() as codex:
thread = codex.thread_start(sandbox=Sandbox.workspace_write)
result = thread.run("Describe this project.")
print(result.final_response)
"""
from ._version import __version__
from .api import (
ApprovalMode,
AsyncChatgptLoginHandle,
AsyncCodex,
AsyncDeviceCodeLoginHandle,
AsyncThread,
AsyncTurnHandle,
ChatgptLoginHandle,
Codex,
DeviceCodeLoginHandle,
ExternalMessage,
ImageInput,
Input,
InputItem,
LocalImageInput,
MentionInput,
RunInput,
Sandbox,
SkillInput,
TextInput,
Thread,
TurnHandle,
TurnResult,
)
from .client import CodexConfig
from .errors import (
CodexError,
CodexRpcError,
InternalRpcError,
InvalidParamsError,
InvalidRequestError,
JsonRpcError,
MethodNotFoundError,
ParseError,
RetryLimitExceededError,
ServerBusyError,
TransportClosedError,
is_retryable_error,
)
from .retry import retry_on_overload
__all__ = [
"__version__",
"CodexConfig",
"Codex",
"AsyncCodex",
"ApprovalMode",
"Sandbox",
"ChatgptLoginHandle",
"DeviceCodeLoginHandle",
"AsyncChatgptLoginHandle",
"AsyncDeviceCodeLoginHandle",
"Thread",
"AsyncThread",
"TurnHandle",
"AsyncTurnHandle",
"TurnResult",
"Input",
"InputItem",
"RunInput",
"ExternalMessage",
"TextInput",
"ImageInput",
"LocalImageInput",
"SkillInput",
"MentionInput",
"retry_on_overload",
"CodexError",
"TransportClosedError",
"JsonRpcError",
"CodexRpcError",
"ParseError",
"InvalidRequestError",
"MethodNotFoundError",
"InvalidParamsError",
"InternalRpcError",
"ServerBusyError",
"RetryLimitExceededError",
"is_retryable_error",
]