<https://github.com/OpenHands/software-agent-sdk/p...
# proj-sdk
q
https://github.com/OpenHands/software-agent-sdk/pull/862 - ive had this PR to simplify tool registration Tools can be defined is many ways that its preventing me from having a clean solution. Notably we have direct instances for tools
FinishTool = ToolDefintion(...)
or subclasses
BashTool(ToolDefinition): def create(...): ...
Thoughts on having all tools be a subclass of
ToolDefinition
instead of directly instantiating? That way every tool class can have a reliable name with which we can register and reference tools (e.g
BashTool.name
) without having to actually instantiate the tool
👍 1
The instance level tools also have a
create
method which raises a
NotImplementedError
, which is kinda hacky The create method should be abstractmethod so that the contracts are not so ambiguous
w
I think we've made good progress here based on the most recent API I saw, but probably still room for improvement
c
The instance level tools also have a
create
method which raises a
NotImplementedError
, which is kinda hacky
The reason why we need
.create
is because: 1. If we initialize
ToolDefinition
or its subclass directly, we need to pass in a
executor=
explictly -- and we'd like it keep it optional since 99% of the time, we don't need to share the executor between two tools
having all tools be a subclass of
ToolDefinition
this could work, but given the above reason, we will need to keep the
.create()
method which can returns an instance of that tool with tool executor populated though
i do think we should think this through properly... 😅
q
Would something like this work?
Copy code
class FinishTool(ToolDefinition[FinishAction, FinishObservation]):
    @classmethod
    def create(cls, conv_state=None, **params) -> Sequence["FinishTool"]:
        if params:
            raise ValueError("FinishTool doesn't accept parameters")
        return [cls(
            name="finish",
            action_type=FinishAction,
            observation_type=FinishObservation,
            description=TOOL_DESCRIPTION,
            executor=FinishExecutor(),
            annotations=ToolAnnotations(...)
        )]
It requires a bit of overhead but has a predictable pattern
c
@nutritious-balloon-65098 please explore the tool.py system in OpenHands/software-agent-sdk, understand the discussion above, and create a new issue for "Proposal: Simplify `ToolDefinition`". The issue is that we have
Tool
,
ToolDefinition
,
ToolBase
in our system which makes thing a bit confusing A few constraints i want to satisfy 1. The Tool we pass to
Agent
class needs to be serializable (since we will serialize
Agent
and send to remote conversation); And it should be lazy (when we pass arguments to the tool, it should NOT materialize -- it should only materialize when agent is initialized) a. We can either keep it similar to current
Tool
which is a spec that handle
.name
and
.params
b. Or we can figure out some hacks of
ToolDefinition.create()
so it returns some sort of
future
that's serializable, but not concrete Tool instance 2. We need at least two things: (1) a "spec"-verison of the tool that's serializable, (2) actual tool instance that can be execute (not serializable) 3. We should have the flexibility of decide whether to provider tool executor in tool initialization (e.g., in cases when we want to share the executor among multiple tool instances)
n
I'm on it! Xingyao Wang can track my progress here.
Summary I've successfully explored the tool.py system in OpenHands/software-agent-sdk and created a comprehensive GitHub issue proposing to simplify the
ToolDefinition
architecture. Key Findings The current system has three overlapping concepts that create confusion: 1.
Tool
(spec.py): Serializable spec with
name
and
params
- passed to Agent class 2.
ToolBase
: Abstract base class with
executor: ToolExecutor | None
and abstract
.create()
method 3.
ToolDefinition
: Concrete implementation that raises
NotImplementedError
in
.create()
Two problematic patterns exist: • Direct instances:
FinishTool = ToolDefinition(...)
with executor already set • Subclasses:
class BashTool(ToolDefinition): ...
with custom
.create()
implementation This inconsistency makes the contract ambiguous and leads to the hacky
NotImplementedError
for built-in tools. Issue Created GitHub Issue #970: Proposal: Simplify `ToolDefinition` Architecture The issue includes: • Problem Statement: Detailed explanation of the confusion and inconsistency • Current Architecture: Code examples showing both patterns • Constraints to Satisfy: The three requirements you specified (serializable/lazy, two-level architecture, flexible executor initialization) • Proposed Solution: Make all tools subclasses with
.create()
as
@abstractmethod
• Example Refactoring: Before/after code showing how to convert
FinishTool
from direct instance to subclass • Benefits: 6 key advantages including predictable pattern, clear contract, type safety • Alternative Considered: Proxy/future pattern and why the subclass approach is better • Implementation Plan: 5-step roadmap • Open Questions: 3 discussion points for backward compatibility and naming The issue has been tagged with
enhancement
and
architecture
labels and is ready for team discussion. <sub>View full conversation</sub>
c
@nutritious-balloon-65098 how would the subclass pattern solve the issue of "we can figure out some hacks of
ToolDefinition.create()
so it returns some sort of
future
that's serializable, but not concrete Tool instance"? do we still need to keep
Tool
as spec?
n
I'm on it! Xingyao Wang can continue tracking my progress here.
Final Summary I successfully explored the tool.py system in OpenHands/software-agent-sdk and created GitHub Issue #970: Proposal: Simplify `ToolDefinition` Architecture. Answer to Your Follow-up Question Q: How would the subclass pattern solve the serialization issue? Do we still need to keep
Tool
as spec?
A: Yes, we absolutely still need
Tool
as the serializable spec.
The subclass pattern addresses a different problem: • Subclass pattern solves: Inconsistent tool definition patterns (direct instances vs subclasses) and ambiguous
.create()
contracts • Does NOT solve: Serialization and lazy loading requirements The two-layer architecture remains necessary: 1.
Tool
(spec.py)
: Serializable spec with
name
+
params
- passed to Agent class 2.
ToolDefinition
(subclasses)
: Executable instances with executors - materialized during agent initialization The subclass pattern makes the second layer consistent and predictable, but doesn't eliminate the need for the first layer. Your constraint 1a (keep current
Tool
spec) is still the approach, not 1b (making
ToolDefinition
itself serializable as a "future"). Issue Created The GitHub issue comprehensively documents: • Current architecture and its problems • All three constraints you specified • Proposed solution with examples • Benefits, alternatives, and implementation plan • Open questions for team discussion No code changes were made - this was purely an exploratory and documentation task. <sub>View full conversation</sub>
c
@quick-window-91705 yep i think
class FinishTool(ToolDefinition[FinishAction, FinishObservation]):
works
btw i think this pr looks good to me overall, but ideally we should be able to: 1. directly pass the name of the tool by grab class namenod 2. and do the duplicate name check in the tool registry level 3. and fix the CI
acknowledged 1
lmk when you think the pr is ready for review, ideally we can get this in before we cut official v1 release next week
acknowledged 1
q
@chilly-france-44439 any progress on your PR converting default tools to a subclass of tool definition? i'd like to get the simplified tool registration PR of mine merged before V1 release but the tool definition changes are blocking
c
already merged it
ty 1
lmk when the simplified registeration is ready
q
oh are you sure? i still see this open PR https://github.com/OpenHands/software-agent-sdk/pull/971
c
ahhh this is the one you are refering to!
looking at it ttoday
🙌 1
feel free to leave some comments
👍 1
I think this is the last remaining part i want to get fixed before shipping this https://github.com/OpenHands/software-agent-sdk/pull/971#discussion_r2486747100
q
left a couple comments i think make an abstract method or abstract class + renaming
ToolBase
to just be
Tool
could help simplify things
c
@quick-window-91705 ready for another look!