agentcodex

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agentcodex adapts the native Codex app-server SDK to the optional adapter-neutral agent runtime contract.

A Core owns one shared Codex connection. Sessions attach to native threads on that connection and expose one live unified event stream. Native history queries remain available through the adapter-specific NativeClient escape hatch; this package defines no unified history or replay API.

The adapter maps root-turn session state, user and agent messages, reasoning, title and usage updates, native errors, and command, file-change, function-output, MCP, dynamic-tool, collaboration, web-search, image-view, sleep, and image-generation item activity. Child-thread item events stay on the main session stream with their source and confirmed parent identities in Meta. The session answers supported child interactions through their original native handles. Blocking child interactions keep the session in requires_action across root completion or idleness until native settlement. Child-thread lifecycle notifications remain explicit gaps.

Tool calls and results use the Codex-specific ToolName, Provider and Kind mappings, result-copy rule and native status projection defined in docs/modules/unified-agent/design.md. Tool chunks remain {id, content}.

Command, file-change and MCP tool approvals stay bound to their native request and may select only an option offered by that request. Additional sandbox permission approvals display the requested profile and its reason, when present. Callers can grant the whole profile for the turn or session, or deny it. Standard MCP form and URL elicitations support accept, decline and cancel. Native user-input forms support accepted answers; decline and cancel are rejected because their native settlement is not proven. Interaction references are opaque, session-scoped, one-shot, and remain pending until a native lifecycle fact closes them. StartOrSteer calls native turn/start only: the response turn identity decides current versus new work, a recognized native refusal returns not_applied, and an unknown outcome remains unsettled until native turn evidence arrives.

The Core supports permission, form and URL interactions. The experimental API and AgentQuestions control the native request_user_input tool independently of MCP elicitation. A nonempty unified AdditionalSystemPrompt maps to developerInstructions on thread/start and thread/resume; an empty value omits that field, and baseInstructions is never set. The complete field contract is defined in docs/modules/unified-agent/design.md#additional-system-prompt. Additional directories are rejected before opening a session. Image, audio, resource, and resource-link inputs are not advertised. Open and Resume use SessionConfig. Empty model and reasoning-effort values are omitted; nonempty values are passed literally to native thread start or resume. Runtime configuration uses the optional ConfigController.SetConfig path, mapping model and effort to native SetModel and SetThinking. Runtime updates require the experimental API and affect provider-determined later work; they do not wait for idle, interrupt, steer, or rebuild the session. A successful receipt means only that Codex accepted the request. The unified layer does not cache, infer, or report an observed current configuration from acknowledgements or settings notifications.

Several native facts intentionally have no unified representation. Codex does not provide an arbitrary selectable settings-option catalog or available-command catalog through this adapter. Archive and unarchive actions are supported, but their notifications have no unified payload. Native plan items, plan text deltas, and turn plan updates are intentionally not emitted, while their original types and notifications remain available in the native Codex package. Reasoning part boundaries are also not represented.

Successful lineage observations are attached to child event Meta. Failures are reported as non-fatal session errors. Unsupported notifications and items are reported as session errors with stable reasons and native metadata; they are not silently discarded. Saved resume history remains query-only and never becomes live unified events.

Open and Resume pass the final adapter-neutral external MCP list to the native thread config. Stdio maps Command, Args, Env, and Cwd; Streamable HTTP maps URL, Headers, EnvHeaders, and BearerTokenEnvVar to the native header and bearer environment-variable fields. Codex ambient configuration is field-level recursively merged with these declarations instead of replaced as a whole, and a warm loaded thread may ignore new resume config. The adapter does not promise ambient replacement or live MCP tool-set changes. A successful Open or Resume does not prove MCP connectivity, authentication, or tool discovery.

Index

Constants

View Source
const (
	ErrorReasonInvalidSandboxMode          = "invalid_sandbox_mode"
	ErrorReasonPermissionPresetMismatch    = "permission_preset_mismatch"
	ErrorReasonEventDecodeFailed           = "event_decode_failed"
	ErrorReasonSessionConfigNotEncodable   = "session_config_not_encodable"
	ErrorReasonFormOutcomeUnsupported      = "form_outcome_unsupported"
	ErrorReasonInvalidNativeEvent          = "invalid_native_event"
	ErrorReasonPermissionCancelUnsupported = "permission_cancel_unsupported"
	ErrorReasonCoreStartFailed             = "core_start_failed"
	ErrorReasonSandboxProfileConflict      = "sandbox_profile_conflict"
	ErrorReasonStartOrSteerIdentityMissing = "start_or_steer_identity_missing"
)

Stable Error.Reason values specific to the Codex adapter.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Stdio codex.StdioOptions
	// Tracer optionally creates a local span for each admitted StartOrSteer.
	Tracer agent.Tracer

	// TracerProvider and MeterProvider default to the host's OpenTelemetry providers.
	TracerProvider trace.TracerProvider
	MeterProvider  metric.MeterProvider
}

Config fixes the explicitly selected Codex app-server process and its native initialization. The provider owns exactly one connection created from it.

type Core

type Core struct {
	// contains filtered or unexported fields
}

Core owns one Codex app-server connection shared by all of its sessions.

func New

func New(config Config) *Core

New constructs a Codex Core. No process or connection is created until Start succeeds.

func (*Core) NativeClient

func (p *Core) NativeClient() (*codex.Client, error)

NativeClient returns the Core-owned native connection while the Core is active. Callers must not close it or invoke methods that create, attach, resume, control, or answer sessions; only read-only native queries are allowed. The concrete return type preserves the design's native escape hatch; callers that need a compile-time restriction must bind it to a query-only interface.

func (*Core) Open

func (p *Core) Open(
	ctx context.Context,
	options agent.OpenOptions,
) (agent.Session, error)

Open creates a native main session after the Core has started.

func (*Core) OpenWithPermissions

func (p *Core) OpenWithPermissions(
	ctx context.Context,
	options agent.OpenOptions,
	permissions Permissions,
) (_ agent.Session, err error)

OpenWithPermissions creates a native main session with the supplied per-thread permissions after the Core has started.

func (*Core) Resume

func (p *Core) Resume(
	ctx context.Context,
	options agent.ResumeOptions,
) (agent.Session, error)

Resume restores an existing native main session. Saved turns in the native response are not converted into live events.

func (*Core) ResumeWithPermissions

func (p *Core) ResumeWithPermissions(
	ctx context.Context,
	options agent.ResumeOptions,
	permissions Permissions,
) (_ agent.Session, err error)

ResumeWithPermissions restores an existing native main session with the supplied per-thread permission overrides.

func (*Core) Start

func (p *Core) Start(ctx context.Context) (agent.Capabilities, error)

Start acquires the single native connection owned by this Core.

func (*Core) Stop

func (p *Core) Stop(ctx context.Context) error

Stop releases the Core-owned connection. It is terminal and succeeds idempotently after the first successful stop.

type Permissions

type Permissions struct {
	ApprovalPolicy    codextypes.Optional[codextypes.AskForApproval]
	ApprovalsReviewer codextypes.Optional[codextypes.ApprovalsReviewer]
	Sandbox           codextypes.Optional[codextypes.SandboxMode]
	// ProfileID selects a named permissions profile and is mutually exclusive
	// with a Sandbox value.
	ProfileID codextypes.Optional[string]
}

Permissions carries native permission fields for one Codex thread start or resume. Its zero value omits all permission fields from the request.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL