import os
from pydantic import SecretStr
from openhands.sdk import LLM, Conversation
from openhands.sdk.preset.default import get_default_agent
# Configure LLM
api_key = os.getenv("LLM_API_KEY")
assert api_key is not None, "LLM_API_KEY environment variable is not set."
llm = LLM(
model="openhands/claude-sonnet-4-5-20250929",
api_key=SecretStr(api_key),
)
# Create agent with default tools and configuration
agent = get_default_agent(
llm=llm,
working_dir=os.getcwd(),
cli_mode=True, # Disable browser tools for CLI environments
)
# Create conversation, send a message, and run
conversation = Conversation(agent=agent)
conversation.send_message("Create a Python file that prints 'Hello, World!'")
conversation.run()