Skip to content

REST Tool Usage ​

examples/17-rest-tool.halo policies

How to define and call REST API tools WHY: Integrate external APIs into your pipeline

Open in the playground →

halo
// ============================================================
// STEP 17: REST Tool Usage
// ============================================================
// LEARN: How to define and call REST API tools
// WHY:  Integrate external APIs into your pipeline
// ============================================================

// Define a REST API tool
tool WeatherAPI : REST("api.openweathermap.org/data/2.5", apiKey: Env.OWM_KEY)

policy NoSensitive : Redact(APIKey) & Redact(Location)

agent Analyst [openai/gpt-4o, temp: 0.3]
  equips WeatherAPI
  requires NoSensitive

pipeline GetWeather(city: String) -> Result:
  city
    // Call REST API with named args
    // GET https://api.openweathermap.org/data/2.5/weather?q={city}&appid={key}
    |> Analyst.fetch(
        tool: WeatherAPI,
        path: "/weather",
        query: "q={{city}}&units=metric"
      )
    |> Analyst.prompt("Summarize the weather data")
    |> System.Print()

// REST tool syntax:
//   tool Name : REST("base.url", apiKey: Env.KEY)
//
// In pipeline:
//   Agent.method(tool: ToolName, path: "/path", query: "key=value")

curl -fsSL https://halolang.com/install.sh | sh