Repository: All-Hands-AI/OpenHands
File: openhands-cli/openhands_cli/agent_chat.py (Python)

Code before:
from openhands_cli.runner import ConversationRunner
from openhands_cli.setup import setup_agent
from openhands_cli.tui.settings.settings_screen import SettingsScreen
from openhands_cli.tui.tui import (
    CommandCompleter,
    display_help,
    display_welcome,
)
from openhands_cli.user_actions import UserConfirmation, exit_session_confirmation
from openhands_cli.locations import WORK_DIR

logger = logging.getLogger(__name__)


def run_cli_entry() -> None:
    """Run the agent chat session using the agent SDK.

    Raises:
        AgentSetupError: If agent setup fails
        KeyboardInterrupt: If user interrupts the session
        EOFError: If EOF is encountered
    """

    agent_context = AgentContext(
        system_message_suffix=f"You current working directory is: {WORK_DIR}",
    )

    conversation = setup_agent(agent_context)
    settings_screen = SettingsScreen()

    while not conversation:
        settings_screen.handle_basic_settings(escapable=False)
        conversation = setup_agent(agent_context)

    # Generate session ID
    session_id = str(uuid.uuid4())[:8]

    display_welcome(session_id)

    # Create prompt session with command completer
    session = PromptSession(completer=CommandCompleter())

    # Create conversation runner to handle state machine logic
    runner = ConversationRunner(conversation)

    # Main chat loop
    while True:
        try:
            # Get user input
            user_input = session.prompt(
                HTML("<gold>> </gold>"),

Review comment (suggestion):
Could we place this inside setup_agent itself, instead of making it an arg

Also it seems when loading the agent back in `AgentStore` we'd similarly need to update the agent context 

Code after:
from openhands_cli.runner import ConversationRunner
from openhands_cli.setup import setup_conversation, MissingAgentSpec
from openhands_cli.tui.settings.settings_screen import SettingsScreen
from openhands_cli.tui.tui import (
    CommandCompleter,
    display_help,
    display_welcome,
)
from openhands_cli.user_actions import UserConfirmation, exit_session_confirmation
from openhands_cli.locations import WORK_DIR

logger = logging.getLogger(__name__)


def run_cli_entry() -> None:
    """Run the agent chat session using the agent SDK.

    Raises:
        AgentSetupError: If agent setup fails
        KeyboardInterrupt: If user interrupts the session
        EOFError: If EOF is encountered
    """

    conversation = None
    settings_screen = SettingsScreen()

    while not conversation:
        try:
            conversation = setup_conversation()
        except MissingAgentSpec:
            settings_screen.handle_basic_settings(escapable=False)

    # Generate session ID
    session_id = str(uuid.uuid4())[:8]

    display_welcome(session_id)

    # Create prompt session with command completer
    session = PromptSession(completer=CommandCompleter())

    # Create conversation runner to handle state machine logic
    runner = ConversationRunner(conversation)

    # Main chat loop
    while True:
        try:
            # Get user input
            user_input = session.prompt(
                HTML("<gold>> </gold>"),
                multiline=False,
            )