OpenHands Tools - Runtime tools for AI agents

1.16.1 · active · verified Sat Apr 11

OpenHands Tools is a Python SDK providing runtime components and utilities for building AI agents, including core agent definitions, tools, and conversation management. As of version 1.16.1, it focuses on enabling robust and extensible agent development. The library maintains an active release cadence, with frequent minor updates and significant feature additions in its 1.x releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a custom tool and create a basic `Agent` that is configured with this tool. In a full OpenHands runtime, the agent's `run` method would interact with an LLM to dynamically select and execute tools based on the given task.

import os
from openhands.core.agent import Agent
from openhands.core.tools.tool import Tool
from typing import List, Dict, Any

# Define a simple tool function
def get_current_weather(location: str) -> str:
    """Get the current weather in a given location."""
    # In a real scenario, this would make an API call to a weather service
    return f"The weather in {location} is sunny with 25 degrees Celsius."

# Create a Tool instance from the function
weather_tool = Tool(
    name="get_current_weather",
    description="Get the current weather in a given location",
    func=get_current_weather,
    args_schema={
        "location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"}
    },
)

# Define a simple Agent that could potentially use this tool
# In a real scenario, this agent would be instantiated with an LLM
# and have more complex logic to interpret tasks and call tools.
class MySimpleAgent(Agent):
    def __init__(self):
        super().__init__(
            name="SimpleWeatherAgent",
            description="An agent that can tell the weather.",
            tools=[weather_tool]
        )
    
    # The 'run' method would typically interact with an LLM and orchestrate tool usage.
    # For this quickstart, we'll just demonstrate its structure.
    def run(self, task: str, *args, **kwargs):
        print(f"Agent '{self.name}' received task: '{task}'")
        print(f"Agent's available tools: {[tool.name for tool in self.tools]}")
        if "weather" in task.lower():
            print("Agent could call 'get_current_weather' if prompted by LLM for weather in a location.")
        return "Agent is ready to process tasks with its tools."

# Instantiate and demonstrate the agent
agent = MySimpleAgent()
print(agent.run("What's the weather like in New York?"))

view raw JSON →