wooden-umbrella-84098
09/29/2025, 8:12 PMtools field of the agent, so it's weird that it's not a Toolwooden-umbrella-84098
09/29/2025, 8:15 PMclass 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")])wooden-umbrella-84098
09/29/2025, 8:15 PMchilly-france-44439
09/29/2025, 8:16 PMwooden-umbrella-84098
09/29/2025, 8:16 PMchilly-france-44439
09/29/2025, 8:16 PMwooden-umbrella-84098
09/29/2025, 8:16 PMwooden-umbrella-84098
09/29/2025, 8:20 PMclass 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