AgentSessionServices (in packages/coding-agent/src/core/agent-session-services.ts) is the coherent set of cwd-bound runtime services — auth, settings, model registry, resource loader, and MCP manager — created for one effective session working directory; it is infrastructure only, and the AgentSession itself is created separately.[1] The two-phase split — createAgentSessionServices followed by createAgentSessionFromServices — is intentional: it lets callers resolve model, thinking, tools, and other session inputs against the services before committing to session creation.[1] rlmDepth is the nesting depth of the current agent within a recursive agent chain; a value of 0 indicates the agent is the top-level, non-subagent session.
AgentSessionRuntimeDiagnostic carries non-fatal issues with type "info" | "warning" | "error" and a message string; diagnostics are returned to the caller rather than printed or causing process exit, leaving the app layer to decide whether to show warnings or abort startup.[1] When telemetry is enabled and the telemetry notice has not yet been shown, createAgentSessionServices pushes an "info" diagnostic explaining what is collected and how to disable it (via telemetry.enabled=false, PRIME_AGENT_TELEMETRY=0, DO_NOT_TRACK=1, or offline mode), then marks the notice as shown.[1] Passing an unknown extension flag name produces an "error" diagnostic listing the unknown --flag names; passing a string-typed flag without a string value produces a separate "error" diagnostic stating the flag requires a value.[1] Extension provider registrations stored in extensionsResult.runtime.pendingProviderRegistrations are applied at service-creation time by calling modelRegistry.registerProvider; any registration error is surfaced as an "error" diagnostic, and the pending list is cleared afterwards.[1]
createAgentSessionServices defaults agentDir to getAgentDir(), authStorage to AuthStorage.create(join(agentDir, "auth.json")), and modelRegistry to ModelRegistry.create(authStorage, join(agentDir, "models.json")) when those options are omitted.[1] The McpManager is initialized with authStorage and a getter for user MCP servers from settingsManager; when modelRegistry's OAuth providers are reset, it automatically re-registers user MCP providers via mcpManager.registerUserProviders().[1]
The built-in Herdr reporter is suppressed when noBuiltinHerdrReporter is set or resourceLoaderOptions.noExtensions is true; this covers RLM subagent runtimes, which inherit the parent's HERDR_* pane identity — two reporters on the same pane would race each other, and a subagent quit would release the pane while the parent is still running (see RLM subagents).[1] When the built-in Herdr reporter is active, it defers to Herdr's file-based integration if that file was actually loaded; deferral is late-bound to the loader's loaded extension paths so that a file which exists but is disabled or never discovered does not silence the built-in reporter.[1]
AgentSessionCreationOptions.noTools accepts "all" to suppress all tools or "builtin" to suppress only built-in tools for a session.[1] AgentSessionCreationOptions.initialGoal seeds a goal at session creation; it is applied only at rlmDepth 0 and the operation is idempotent.[1] AgentSessionCreationOptions.serviceTier sets the provider service tier; fast mode uses "priority".[1] createAgentSessionFromServices installs agent trace upload via installAgentTraceUpload before delegating to createAgentSession from sdk.js.[1]
agent-traces.ts maintains a disk-cursor outbox: trace payloads are appended to a local log at emission time, and a background cursor advances through the log as uploads succeed — ensuring traces survive session close, crashes, and daemon restarts. The agent trace upload outbox is wired into the session teardown path via agent-session-runtime.ts, agent-session.ts, in-process-agent-connection.ts, daemon-mode.ts, and interactive-mode.ts. Telemetry that must survive crashes and daemon restarts should extend the outbox pattern in agent-traces.ts rather than implementing ad-hoc upload scheduling.
Sources