straight-sundown-84319
09/12/2025, 3:18 PMfrom abc import ABC, abstractmethod
from openhands.sdk import Tool
from pydantic import BaseModel
from openhands.tools import BashTool, FileEditorTool, TaskTrackerTool
class ToolRequest(BaseModel, ABC):
@abstractmethod
def create_tool(self) -> Tool:
""" Create a tool """
class BashToolRequest(ToolRequest):
working_dir: str
def create_tool(self):
return BashTool.create(working_dir=self.working_dir)
class FileEditorToolRequest(ToolRequest):
def create_tool(self):
return FileEditorTool.create()
class TaskTrackerToolRequest(ToolRequest):
save_dir: str
def create_tool(self):
return TaskTrackerTool.create(save_dir=self.save_dir)
ToolRequestType = BashToolRequest | FileEditorToolRequest | TaskTrackerToolRequest
(So I use ToolRequestType in my AgentRequest in my CreateConversationRequest so FastAPI / Pydantic use it by default)wooden-umbrella-84098
09/12/2025, 3:26 PMwooden-umbrella-84098
09/12/2025, 3:26 PMstraight-sundown-84319
09/12/2025, 3:28 PMspecs Xingyao mentionedwooden-umbrella-84098
09/12/2025, 3:29 PMstraight-sundown-84319
09/12/2025, 3:32 PM@router.post("/")
async def start_conversation(request: ConversationStartRequest):
conversation = request.create_conversation(cwd)
loop = asyncio.get_running_loop()
await loop.run_in_executor(None, conversation.run)straight-sundown-84319
09/12/2025, 3:33 PMstraight-sundown-84319
09/12/2025, 3:33 PMstraight-sundown-84319
09/12/2025, 3:35 PMwooden-umbrella-84098
09/12/2025, 4:47 PM@router.post("/")
async def start_conversation(request: ConversationStartRequest):
runtime = LocalRuntime()
conversation = request.create_conversation(runtime.get_tools(cwd))
loop = asyncio.get_running_loop()
await loop.run_in_executor(None, conversation.run)wooden-umbrella-84098
09/12/2025, 4:48 PMstraight-sundown-84319
09/12/2025, 4:49 PMstraight-sundown-84319
09/12/2025, 4:49 PMwooden-umbrella-84098
09/12/2025, 4:54 PMwooden-umbrella-84098
09/12/2025, 4:54 PMwooden-umbrella-84098
09/12/2025, 4:55 PMwooden-umbrella-84098
09/12/2025, 4:55 PMstraight-sundown-84319
09/12/2025, 4:55 PMwooden-umbrella-84098
09/12/2025, 4:55 PMstraight-sundown-84319
09/12/2025, 4:56 PMchilly-france-44439
09/12/2025, 5:40 PMchilly-france-44439
09/12/2025, 5:40 PMchilly-france-44439
09/12/2025, 5:40 PMopenapi.json 😅straight-sundown-84319
09/12/2025, 5:46 PMstraight-sundown-84319
09/12/2025, 5:48 PM{
type: "object",
properties: {
"name": {type: "string"}
"params": {}
},
additionalProperties: false
}straight-sundown-84319
09/12/2025, 5:52 PM{
'$defs': {
'BashToolRequest': {
'properties': {
'working_dir': {
'title': 'Working Dir',
'type': 'string'
}
},
'required': [
'working_dir'
],
'title': 'BashToolRequest',
'type': 'object'
},
'FileEditorToolRequest': {
'properties': {
},
'title': 'FileEditorToolRequest',
'type': 'object'
},
'TaskTrackerToolRequest': {
'properties': {
'save_dir': {
'title': 'Save Dir',
'type': 'string'
}
},
'required': [
'save_dir'
],
'title': 'TaskTrackerToolRequest',
'type': 'object'
}
},
'anyOf': [
{
'$ref': '#/$defs/BashToolRequest'
},
{
'$ref': '#/$defs/FileEditorToolRequest'
},
{
'$ref': '#/$defs/TaskTrackerToolRequest'
}
]
}straight-sundown-84319
09/12/2025, 5:54 PMstraight-sundown-84319
09/12/2025, 5:54 PMToolRequestType = BashToolRequest | FileEditorToolRequest | TaskTrackerToolRequest)straight-sundown-84319
09/12/2025, 5:55 PMchilly-france-44439
09/12/2025, 6:04 PMwooden-umbrella-84098
09/12/2025, 6:17 PMwooden-umbrella-84098
09/12/2025, 6:17 PMagent.working_dir AND bash_tool.workdir?chilly-france-44439
09/12/2025, 6:17 PMwooden-umbrella-84098
09/12/2025, 6:17 PMchilly-france-44439
09/12/2025, 6:19 PMwooden-umbrella-84098
09/12/2025, 6:22 PMservice_id?wooden-umbrella-84098
09/12/2025, 6:23 PMwooden-umbrella-84098
09/12/2025, 6:24 PMLLMRequest or sthchilly-france-44439
09/12/2025, 6:24 PMMetrics for some reason 😅chilly-france-44439
09/12/2025, 6:24 PMMetrics only exists at runtime thoughwooden-umbrella-84098
09/12/2025, 6:24 PMwooden-umbrella-84098
09/12/2025, 6:24 PMMetrics not pydantic?chilly-france-44439
09/12/2025, 6:25 PMwooden-umbrella-84098
09/12/2025, 6:25 PMwooden-umbrella-84098
09/12/2025, 6:25 PMchilly-france-44439
09/12/2025, 6:25 PMwooden-umbrella-84098
09/12/2025, 6:25 PMwooden-umbrella-84098
09/12/2025, 6:25 PMget_metrics if someone needs accesswooden-umbrella-84098
09/12/2025, 6:25 PMchilly-france-44439
09/12/2025, 6:26 PM_metrics as attribute