Skip to content

CodexAgent

Agent backed by codex app-server (JSON-RPC over stdio), one app-server process per session.

import { CodexAgent, CodexAppServer } from "@jpowersdev/effect-agent/codex"
CodexAgent.layer().pipe(
Layer.provide(CodexAppServer.layer()),
Layer.provide(NodeServices.layer),
)

Every thread runs with approvals off (approvalPolicy: "never") and, unless CodexAgentOptions.sandbox says otherwise, the sandbox off (sandbox: "danger-full-access"), without the built-in codex_apps, and asks for no configured MCP servers unless RunOptions.mcp is set. Codex 0.162.1 ignores that request for the servers in config.toml (and any per-session mcp_servers setting), so only mcp stops their calls.

status and history each start a short-lived app-server (through the Launcher, if any) and stop it before returning. RunOptions.hooks, and tools disable can’t remove, go through Codex’s command hooks (see CodexHooks).

Since v0.1.0

The Codex Agent, on top of a CodexAppServer.

Signature

declare const make: (options?: CodexAgentOptions) => Effect.Effect<
{
readonly provider: string
readonly capabilities: Effect.Effect<Capabilities, AgentError>
readonly open: (
options: RunOptions,
) => Effect.Effect<AgentSession, SessionNotFound | AgentError, Scope.Scope>
readonly status: (
options?: StatusOptions,
) => Effect.Effect<AccountStatus, AgentError>
readonly history: (
sessionId: SessionId,
options: { readonly cwd: string },
) => Effect.Effect<ReadonlyArray<AgentEvent>, SessionNotFound | AgentError>
},
never,
CodexAppServer
>

Source

Since v0.1.0

Agent backed by codex app-server; requires CodexAppServer.

Example

import { NodeServices } from "@effect/platform-node"
import { CodexAgent, CodexAppServer } from "@jpowersdev/effect-agent/codex"
import { Layer } from "effect"
// Cost is estimated from `CodexPricing` (this release's prices unless provided).
const layer = CodexAgent.layer().pipe(
Layer.provide(CodexAppServer.layer()),
Layer.provide(NodeServices.layer),
)

Signature

declare const layer: (
options?: CodexAgentOptions,
) => Layer.Layer<Agent, never, CodexAppServer>

Source

Since v0.1.0

Options for make and layer.

Signature

export interface CodexAgentOptions {
/**
* Extra per-thread config overrides (dotted config.toml keys). effect-agent's own settings win on conflict.
* `open` fails if a session needs hooks and this would stop them (`features.hooks = false`, or any `hooks` key).
*/
readonly config?: Readonly<Record<string, P.JsonValue>>
/** Default for `RunOptions.watchdog.grace` (10 seconds when neither is set). */
readonly stallGrace?: Duration.Input
/**
* Codex's sandbox for the commands the agent runs; none (`danger-full-access`) when
* omitted. See `CodexSandbox`.
*/
readonly sandbox?: CodexSandbox
}

Source

Since v0.1.0

Codex’s sandbox for the commands the agent runs, for CodexAgentOptions.sandbox. Approvals are always never: nobody is there to approve, so a command the sandbox stops fails, and the model is told.

  • danger-full-access: no sandbox, as when sandbox is omitted.
  • workspace-write: commands write only in cwd, /tmp and $TMPDIR (more roots: sandbox_workspace_write.writable_roots in config; no temp dirs: sandbox_workspace_write.exclude_slash_tmp and exclude_tmpdir_env_var), with no network unless config allows it.
  • read-only: commands write nowhere.

In a sandbox Codex asks to approve every MCP call, and with approvals never an unapproved one is refused. So a sandbox approves the tools of a session’s mcpServers (default_tools_approval_mode = "approve"; mcp.allow is still their check), and says so: mcpServerTools: "approve" is required with a sandbox, and has no place without one, where Codex asks for no approval. A server in config.toml is callable in a sandbox only if its own config approves its tools.

Example

import { CodexAgent } from "@jpowersdev/effect-agent/codex"
const options: CodexAgent.CodexAgentOptions = {
sandbox: { mode: "workspace-write", mcpServerTools: "approve" },
}

Signature

declare const CodexSandbox: Union<
readonly [
Struct<{ readonly mode: Literal<"danger-full-access"> }>,
Struct<{
readonly mode: Literals<readonly ["workspace-write", "read-only"]>
readonly mcpServerTools: Literal<"approve">
}>,
]
>

Source

Since v0.8.0

Signature

type CodexSandbox = typeof CodexSandbox.Type

Source

Since v0.8.0

The prices a Codex session estimates its cost and spendCapUsd with, read when it opens; defaultPrices unless provided. Codex reports tokens, not cost, so every Codex cost is an estimate (Cost.source is "estimated"): tokens times these prices. On a plan that doesn’t bill per token (a ChatGPT login) that is a budgeting figure, not a bill.

A model the table doesn’t have is unpriced: its turns report no cost, and spendCapUsd is refused for it. Add a "*" entry to price every model.

Example

import { CodexAgent } from "@jpowersdev/effect-agent/codex"
import { Effect } from "effect"
// For one session, or a whole program: USD per million tokens
const withOurRates = <A, E, R>(self: Effect.Effect<A, E, R>) =>
Effect.provideService(self, CodexAgent.CodexPricing, {
...CodexAgent.defaultPrices,
"gpt-5.5": { input: 5, cachedInput: 0.5, output: 30 },
})

Signature

declare const CodexPricing: Context.Reference<
Readonly<Record<string, Pricing.ModelPrice>>
>

Source

Since v0.8.0

The prices shipped with this release: OpenAI’s pricing page on defaultPricesAsOf (standard tier, text tokens, short-context rates, USD per million tokens), with no "*" entry.

Signature

declare const defaultPrices: Readonly<Record<string, Pricing.ModelPrice>>

Source

Since v0.8.0

The date defaultPrices last changed, as YYYY-MM-DD.

Signature

declare const defaultPricesAsOf: string

Source

Since v0.8.0