# execute_task_textual

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/tui/textual_adapter/execute_task_textual)

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.

## Signature

```python
execute_task_textual(
    user_input: str,
    agent: Any,
    assistant_id: str | None,
    session_state: Any,
    adapter: TextualUIAdapter,
    backend: Any = None,
    image_tracker: MediaTracker | None = None,
    context: CLIContext | None = None,
    *,
    sandbox_type: str | None = None,
    message_kwargs: dict[str, Any] | None = None,
    graph_input: dict[str, Any] | None = None,
    rubric: str | None = None,
    goal_active: bool = False,
    blocked_goal_retry_context: str | None = None,
    on_rubric_evaluation_end: Callable[[RubricEvaluationEnd], None] | None = None,
    turn_stats: SessionStats | None = None,
) -> SessionStats
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `user_input` | `str` | Yes | The user's input message |
| `agent` | `Any` | Yes | The LangGraph agent to execute |
| `assistant_id` | `str \| None` | Yes | The agent identifier |
| `session_state` | `Any` | Yes | Session state with a typed approval mode. |
| `adapter` | `TextualUIAdapter` | Yes | The TextualUIAdapter for UI operations. |
| `backend` | `Any` | No | Optional backend for file operations. (default: `None`) |
| `image_tracker` | `MediaTracker \| None` | No | Optional tracker for images. (default: `None`) |
| `context` | `CLIContext \| None` | No | Optional `CLIContext` with model override and params. The current mode is persisted and copied into runtime context before every stream iteration. (default: `None`) |
| `sandbox_type` | `str \| None` | No | Sandbox provider name for trace metadata, or `None` if no sandbox is active. (default: `None`) |
| `message_kwargs` | `dict[str, Any] \| None` | No | Extra fields merged into the stream input message dict (e.g., `additional_kwargs` for persisting skill metadata in the checkpoint). (default: `None`) |
| `graph_input` | `dict[str, Any] \| None` | No | Prepared non-conversation input for a server-side graph operation. When provided, no user message or media is constructed. (default: `None`) |
| `rubric` | `str \| None` | No | Acceptance criteria supplied to `RubricMiddleware` via graph input state. (default: `None`) |
| `goal_active` | `bool` | No | Whether the rubric belongs to an unfinished `/goal`. (default: `False`) |
| `blocked_goal_retry_context` | `str \| None` | No | One-turn model context for retrying a previously blocked goal. This is carried via runtime context so it is not parsed for file mentions or checkpointed as human input. (default: `None`) |
| `on_rubric_evaluation_end` | `Callable[[RubricEvaluationEnd], None] \| None` | No | Optional callback receiving a validated `RubricEvaluationEnd` (grading run ID and verdict) for each main-agent `rubric_evaluation_end` event. (default: `None`) |
| `turn_stats` | `SessionStats \| None` | No | Pre-created `SessionStats` to accumulate into.  When the caller holds a reference to the same object, stats are available even if this coroutine is cancelled before it can return.  If `None`, a new instance is created internally. (default: `None`) |

## Returns

`SessionStats`

Stats accumulated over this turn (request count, token counts,
wall-clock time).

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/7794b61a6e76230e8c7a49bdce808b3728305914/libs/code/deepagents_code/tui/textual_adapter.py#L696)