Non-interactive execution mode.
Provides run_non_interactive which runs a single user task against the
agent graph, streams results to stdout, and exits with an appropriate code.
The agent runs inside a langgraph dev server subprocess, connected via
the RemoteAgent client (see server_manager.server_session).
Shell commands are gated by an optional allow-list (--shell-allow-list):
recommended or explicit list → shell enabled, commands validated
against the list; non-shell tools approved unconditionally.all → shell enabled, any command allowed, all tools auto-approved.An optional quiet mode (--quiet / -q) redirects all console output to
stderr, leaving stdout exclusively for the agent's response text.
Build a full LangSmith thread URL if tracing is configured.
Combines get_langsmith_project_name and fetch_langsmith_project_url
into a single convenience helper.
Create a chat model.
Uses init_chat_model for standard providers, or imports a custom
BaseChatModel subclass when the provider has a class_path in config.
Supports provider:model format (e.g., 'openai:gpt-5.5')
for explicit provider selection, or bare model names for auto-detection.
Check if a shell command is in the allow-list.
The allow-list matches against the first token of the command (the executable name). This allows read-only commands like ls, cat, grep, etc. to be auto-approved.
When allow_list is the SHELL_ALLOW_ALL sentinel, all non-empty commands
are approved unconditionally — dangerous pattern checks are skipped.
SECURITY: For regular allow-lists, this function rejects commands containing dangerous shell patterns (command substitution, redirects, process substitution, etc.) BEFORE parsing, to prevent injection attacks that could bypass the allow-list.
Fire matching hook commands with payload serialized as JSON on stdin.
The event name is automatically injected into the payload under the
"event" key so callers don't need to duplicate it.
The blocking subprocess work is offloaded to a thread so the caller's event loop is never stalled. Matching hooks run concurrently, each with a 5-second timeout. Errors are logged and never propagated.
Schedule dispatch_hook as a background task with a strong reference.
Use this instead of bare create_task(dispatch_hook(...)) to prevent the
task from being garbage collected before completion.
Safe to call from sync code as long as an event loop is running.
Generate a new thread ID as a full UUID7 string.
Print a model-usage stats table to a Rich console.
Each row shows the serving provider alongside the model name. When the session spans multiple models each gets its own row with a totals row appended; single-model sessions show one row.
Check a URL for suspicious Unicode and domain spoofing patterns.
Detect deceptive or hidden Unicode code points in text.
Join safety warnings into a display string with overflow indicator.
Flatten nested dict/list structures into key-path/string pairs.
Return whether a key path suggests URL-like content.
Summarize Unicode issues for warning messages.
Deduplicates by code point. When more than max_items unique entries exist,
the summary is truncated with a +N more entries suffix.
Run a single task non-interactively and exit.
The agent is created with interactive=False, which tailors the system
prompt for autonomous headless execution (no clarification questions,
reasonable assumptions).
Shell access and auto-approval are controlled by --shell-allow-list:
recommended or explicit list → shell enabled, commands gated by
allow-list; non-shell tools approved unconditionally.all → shell enabled, any command allowed, all tools auto-approved.Note: startup header rendering avoids synchronous LangSmith URL lookups. A background thread resolves the thread URL concurrently and the result is displayed after task completion if available.
Collect file operation metrics during an interaction.
Raised when model configuration or creation fails.
Stats accumulated over a single agent turn (or full session).
Raised when the HITL interrupt loop exceeds _MAX_HITL_ITERATIONS rounds.
Mutable state accumulated while iterating over the agent stream.
Best-effort background LangSmith thread URL lookup state.
Thread safety: the background thread sets url then calls done.set().
Consumers must check done.is_set() before reading url.