Hello world example proposal. - Simplifies LLM set...
# proj-sdk
w
Hello world example proposal. • Simplifies LLM setup ā—¦ I'm guessing we had the complexity there so that we can run/test the example. I have a strong preference for a legible example over a testable one, so for at least hello-world I'd like to make an exception • Explicitly names constructs tools (I think this is very important for new users to see and understand)
Copy code
import os

from openhands.sdk import LLM, Conversation, Tool
from openhands.tools.execute_bash import BashTool
from openhands.tools.file_editor import FileEditorTool
from openhands.tools.task_tracker import TaskTrackerTool

llm = LLM(
    model="anthropic/claude-sonnet-4-5-20250929",
    api_key=os.getenv("LLM_API_KEY"),
)

agent = Agent(
    llm=llm,
    tools=[
       Tool(name=BashTool.name),
       Tool(name=FileEditorTool.name),
       Tool(name=TaskTrackerTool.name),
    ],
)

cwd = os.getcwd()
conversation = Conversation(agent=agent, workspace=cwd)

conversation.send_message("Write 3 facts about the current project into FACTS.txt.")
conversation.run()
also, is there anything stopping us from writting
Copy code
BashTool.create()
and have that return a Tool object?
c
feel free to send a PR now - i think with Rohit's PR this should work now
highfive 1
except for the api key since it requires a SecretKey.. might need a field validator there
w
hmm I thought we were accepting str there
c
If we do that, we'd probably need to add hundred lines of assert to make type checker happy šŸ˜“
w
hmm could you accept a str in the constructor, but always convert it to a secretstr under the hood?
or is pydantic not happy with that
c
pydantic is not happy with that -- this will make type check yelled at you in the example code
left the comment w/ more context in the pr, let's see if oh has better idea
w
Claude claims
I have a pydantic class with a SecretStr attribute. Can I allow users to pass in a regular string, and have it automatically convert to a SecretStr
Yes! Pydantic will automatically convert a regular string to
SecretStr
for you. This works out of the box with no special configuration needed.
c
🤷 i guess it annoys pylance
c
I think we also have a model_validator before the instance is made
c
but don't have issue in runtime
ok seems this is sufficient to support SecretStr and we have model validator to auto convert https://github.com/OpenHands/software-agent-sdk/pull/1047/commits/188327ceaf9b642627bbf997fee6d5e7138c9174
should be good for now
plus a few pylance annoyance in tests 😭
w
thanks y'all!