Textual UI adapter for agent execution.
Attach a file handler to target when DEEPAGENTS_CLI_DEBUG is set.
The log file defaults to '/tmp/deepagents_debug.log' but can be overridden
with DEEPAGENTS_CLI_DEBUG_FILE. The handler appends so that multiple
modules share the same log file across a session.
Does nothing when DEEPAGENTS_CLI_DEBUG is not set.
Format a token count into a human-readable short string.
Build the LangGraph stream config dict.
Injects CLI and SDK versions into metadata["versions"] so LangSmith traces
can be correlated with specific releases.
Why the CLI sets both versions:
create_deep_agent bakes versions: {"deepagents": "X.Y.Z"} into the
compiled graph via with_config. At stream time, LangGraph merges
the graph config with the runtime config passed here. Because the
metadata merge is shallow (effectively {**graph_meta, **runtime_meta}
for top-level keys), both configs containing a versions key means
the runtime dict replaces the graph dict entirely — the SDK
version would be lost.Includes ls_integration metadata so LangSmith traces originating from the CLI
are distinguishable from bare SDK usage.
Format a duration in seconds into a human-readable string.
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.
Extract @file mentions and return the text with resolved file paths.
Parses @file mentions from the input text and resolves them to absolute
file paths. Files that do not exist or cannot be resolved are excluded with
a warning printed to the console.
Email addresses (e.g., user@example.com) are automatically excluded by
detecting email-like characters before the @ symbol.
Backslash-escaped spaces in paths (e.g., @my\ folder/file.txt) are
unescaped before resolution. Tilde paths (e.g., @~/file.txt) are expanded
via Path.expanduser(). Only regular files are returned; directories are
excluded.
This function does not raise exceptions; invalid paths are handled internally with a console warning.
Create multimodal message content with text, images, and videos.
Convert ToolMessage content into a printable string.
Print a model-usage stats table to a Rich console.
When the session spans multiple models each gets its own row with a totals row appended; single-model sessions show one row.
Execute a task with output directed to Textual UI.
This is the Textual-compatible version of execute_task() that uses the TextualUIAdapter for all UI operations.
A question to ask the user.
Request payload sent via interrupt when asking the user questions.
Runtime context passed via context= to the LangGraph graph.
Carries per-invocation overrides that ConfigurableModelMiddleware
reads from request.runtime.context.
Token stats for a single model within a session.
Stats accumulated over a single agent turn (or full session).
Collect file operation metrics during a CLI interaction.
Track pasted images and videos in the current conversation.
Widget displaying an app message.
Widget displaying an assistant message with markdown support.
Uses MarkdownStream for smoother streaming instead of re-rendering the full content on each update.
Widget displaying a diff with syntax highlighting.
Widget displaying a summarization completion notification.
Widget displaying a tool call with collapsible output.
Tool outputs are shown as a 3-line preview by default. Press Ctrl+O to expand/collapse the full output. Shows an animated "Running..." indicator while the tool is executing.
Adapter for rendering agent output to Textual widgets.
This adapter provides an abstraction layer between the agent execution and the Textual UI, allowing streaming output to be rendered as widgets.
Discriminated union for the ask_user widget Future result.
Valid spinner display states, or None to hide.