Skip to content

TUI Service

OpenDataSciTuiService is the service layer that sits between the terminal UI (CLIController) and the underlying Agent / BaseSandbox. It owns both the agent and the sandbox for the lifetime of a terminal session.

You do not normally instantiate this class directly — the TUI creates it for you. It is documented here for integrators who want to embed the OpenDataSci TUI in a custom terminal application.

Overview

from opendatasci._tui.service import OpenDataSciTuiService
from opendatasci import create_agent, OpenDataSciConfig
from pathlib import Path

config = OpenDataSciConfig()

async with create_agent("data.csv", config=config) as agent:
    service = OpenDataSciTuiService(
        agent=agent,
        sandbox=agent._sandbox,
        workspace_path=Path(agent._workspace.get_reference()),
    )
    async for event in service.astream("Describe this dataset"):
        print(event)

Key responsibilities

  • astream(query) — delegates to the agent and yields AgentStreamEvent objects
  • reset_session() — resets both the sandbox execution state and the agent's conversation history
  • clear_context() — clears only the conversation history (sandbox variables survive)
  • compact_chat_history() — calls the agent's LLM-based compaction and returns the summary
  • get_workspace_files() — returns filenames visible in the workspace (used by /ls-workspace)

Reference

OpenDataSciTuiService

OpenDataSciTuiService(agent: BaseOpenDataSciAgent, sandbox: BaseSandbox, workspace_path: Path | None = None)

Service layer for the OpenDataSci TUI.

Owns the agent and sandbox for the lifetime of a terminal session. Create a new instance for each file or workspace loaded by the TUI.

close async

close() -> None

Release sandbox resources (e.g. stop Docker containers).

astream async

astream(query: str) -> AsyncIterator[AgentStreamEvent]

Stream events for query with token-level output.

reset_session async

reset_session() -> None

Reset the execution session and clear agent conversation.

clear_context async

clear_context() -> None

Clear all agent context: history, summaries, plan, and pending summarizations.

rewind_turn async

rewind_turn() -> None

Remove the last turn from the conversation history.

compact_chat_history async

compact_chat_history() -> str

Compact the conversation history and return the summary.

get_workspace_files

get_workspace_files() -> list[str]

Return names of files/dirs visible in the workspace, relative to its root.

Used by the /ls-workspace command.