Codex CLI
Define a Codex agent in C#, configure its model, and execute it through the locally installed CLI.
UseCodex(...) selects local Codex CLI execution. Runiq launches the CLI under the host account, using its existing authentication and configuration. You do not supply an agent API key.
Define the Codex agent
Install Runiq.AI.Agents in a .NET 10 ASP.NET Core project. Codex requires a configuration callback with an explicit model: calling UseCodex() without arguments is a compile-time error. Leaving options.Model blank inside the callback fails validation when creating the definition.
Create Agents/CodexAgent.cs. This factory follows the repository sample and sets the model, reasoning effort, and service tier explicitly:
The instructions keep the assistant focused on the current request and make repository inspection deliberate. Instructions do not enforce filesystem permissions; the Codex executor uses a read-only sandbox by default.
Register the agent
In Program.cs, create the definition through the factory and register it before building the host:
AddRuniqServer automatically registers the Codex executor. Definition and registration do not launch or authenticate the CLI. To execute this agent, follow Running agents using codex-agent as the agent id, or enable Studio and select CodeReviewer.
Choose model settings
| Setting | Behavior |
|---|---|
Model | Required non-blank CLI model name. The example uses gpt-6-astra, matching the repository's reviewer sample. |
ReasoningEffort | Defaults to High. Accepted values are None, Minimal, Low, Medium, High, XHigh, Max, and Ultra. |
ServiceTier | Defaults to Default, preserving local CLI tier settings. Fast requests the CLI fast tier. |
There is no parameterless UseCodex() overload. Use the CLI model name without the openai/ provider prefix used by model-provider agents. Availability and supported reasoning levels depend on the installed CLI and account; Runiq does not maintain a model catalog. Settings are copied into agent.Executor!.Codex and applied on new and resumed turns.
Attach Runiq tools
Attach a typed tool to the definition before registration:
See Defining tools for the complete TextStatsTool definition. Runiq automatically exposes the agent's tools through a per-run MCP bridge; no additional MCP server registration is required. Tool calls appear in Studio using the existing tool events.
Tool code runs in the host process with host permissions, outside the CLI sandbox. Authorize and validate operations inside the tool. Native Codex tool activity is not published as Runiq tool events. Active Runiq RAG bindings are unsupported and return CodexCapabilityNotSupported.
Execute and continue a conversation
Use AgentExecutionRuntime for both completed results and streaming. Codex emits completed assistant messages as deltas; token-by-token streaming is not guaranteed. A later turn can use the confirmed ProviderSessionId; see CLI conversation continuation.
Missing installation returns CodexNotInstalled; authentication failure returns CodexAuthenticationFailed. Rejected models and reasoning combinations return CodexModelNotAvailable and CodexReasoningEffortNotSupported. CLI failures do not fall back to another executor.