Rename proposal: - Tool -> ToolDefinition - Too...
# proj-sdk
w
Rename proposal: • Tool -> ToolDefinition • ToolSpec -> Tool The ToolSpec is what gets passed into the
tools
field of the agent, so it's weird that it's not a Tool
Here's what it looks like with this change
Copy code
class RandomNumberAction(Action):
  minimum: int = Field(description="Min number", default=0)
  maximum: int = Field(description="Max number", default=100)
  
class RandomNumberObservation(Observation):
  result: int = Field(description="The random number")
  def to_llm_content(self):
    return [TextContent(text=str(self.result))]
    
class RandomNumberExecutor(ToolExecutor[RandomNumberAction, RandomNumberObservation]):
  def __call__(self, action: RandomNumberAction) -> RandomNumberObservation:
    result = random.randint(action.minimum, action.maximum)
    return RandomNumberObservation(result=result)

# Tools get registered globally
register_tool("RandomNumber", ToolDefinition(
  name="random_number",
  description="generates a random integer",
  action_type=RandomNumberAction,
  observation_type=RandomNumberObservation,
  executor=RandomNumberExecutor()
))

agent = Agent(llm=llm, tools=[Tool(name="RandomNumber")])
I think this is still a bit over complicated but I don't want to touch tools 😅
c
sounds good nod feel free to send in OH PRs for this
w
I think if I could wave a magic wand, we'd combine ToolDefinition and ToolExecutor
c
(maybe after the breaking change on 😭 )
w
yeah I'm tracking all my syntax change requests
here's my ideal syntax. I think this might be an easy change but you can tell me if I'm wrong
Copy code
class RandomNumberAction(Action):
  minimum: int = Field(description="Min number", default=0)
  maximum: int = Field(description="Max number", default=100)
  
class RandomNumberObservation(Observation):
  result: int = Field(description="The random number")
  def to_llm_content(self):
    return [TextContent(text=str(self.result))]
    
class RandomNumberTool(ToolExecutor[RandomNumberAction, RandomNumberObservation]):
  name="random_number"
  description="generates a random integer"
  def __call__(self, action: RandomNumberAction) -> RandomNumberObservation:
    result = random.randint(action.minimum, action.maximum)
    return RandomNumberObservation(result=result)

# Tools get registered globally
register_tool(RandomNumberTool)

agent = Agent(llm=llm, tools=[RandomNumberTool()])
Major changes: • combines Executor with the ToolDefinition • deduplicates the
name
field with the registered name • register_tool takes in a class, and uses the
name
field as the key • Agent takes in an instance of the tool, but under the hood just grabs its name