liveBook · Manning

Tool

As explained in Digital Twins in Action

An agent tool is a callable function or external resource that an AI agent invokes to obtain information or affect an external system.

An agent tool is a callable function or external resource that lets an AI agent obtain information or interact with an external system. Tools extend a model response into an agent loop: the agent reasons, calls a tool, and uses its result to decide what to do next. section 8.4.3

For home climate control, the agent needs current solar output, an hourly weather forecast, and indoor conditions. Separate tools query the inverter API, Open-Meteo REST API, and home digital twin GraphQL API. Tool documentation describes when to call each function and the structure of its inputs and results. section 8.4.3

Listing 8.10 Tool to query Fronius Symo inverter power data
from strands import tool

@tool  #1
def get_realtime_solar_data(scope: str = "System") -> Dict[str, Any]:
    """  #2
    Fetches real-time solar production metrics from the local Fronius
    inverter.

    Use this tool when you need to know the current solar output (PAC) or
    the total energy produced today (DAY_ENERGY).

    Args:
        scope: The data scope to query. Defaults to "System".

    Returns:
        Dict[str, Any]: A dictionary containing:
            - current_power_w: Current AC power output in Watts.
            - day_energy_wh: Total energy produced today in Watt-hours.
            - timestamp: The time of the reading.
    """
    url = "http://192.168.1.180/solar_api/v1/GetInverterRealtimeData.cgi"  #3

    try:
        response = requests.get(url, params={"Scope": scope}, timeout=5)
        response.raise_for_status()
        data = response.json()

        realtime_data = data.get("Body", {}).get("Data", {})

        pac_value = realtime_data.get("PAC", {}).get("Values", {}).
        get("1", 0)
        day_energy = realtime_data.get("DAY_ENERGY", {}).get("Values",
        {}).get("1", 0)

        return {
            "current_power_w": pac_value,
            "day_energy_wh": day_energy,
            "timestamp": data.get("Head", {}).get("Timestamp"),
            "status": "success",
        }

    except requests.RequestException as e:
        return {
            "status": "error",
            "message": f"Failed to connect to inverter: {str(e)}",
        }

The Python function uses Strands’ @tool decorator to expose an inverter query to the agent. Its docstring identifies the available solar measurements and returned fields. section 8.4.3

How Digital Twins in Action covers it

How deep it goes
Shows a documented Python tool and its API call, then places tool execution within an agent loop.
Examples
Uses an inverter query returning current power, daily energy, and a reading timestamp.
What it assumes
Assumes familiarity with Python functions and API calls while introducing how to expose a function as an agent tool.
What you can do after
Build it from scratch with a Strands @tool-decorated function that documents its inputs and results.
How it connects
Links agent loops with API calls, weather forecasts, GraphQL, and home digital twins.

Also explained in

Compare how 14 books explain tool →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Digital Twins in Action. The section links point to the parts of the book it draws on.