Skip to content

Local Automation & Web Fetching ​

examples/38-local-automation.halo

How to build autonomous computer agents WHY: Agents are useless without real world capabilities. Halo natively supports bash execution and web parsing.

Open in the playground →

halo
// ============================================================
// STEP 38: Local Automation & Web Fetching
// ============================================================
// LEARN: How to build autonomous computer agents
// WHY:   Agents are useless without real world capabilities.
//        Halo natively supports bash execution and web parsing.
// ============================================================

// 1. Define the real local tools
tool Reader : Browser(mode: "fetch")
tool Shell  : Bash()

// 2. Equip the tools to an agent
agent Assistant [openai/gpt-4o, temp: 0.1]
  equips Reader, Shell

// 3. Define the pipeline
pipeline SummarizeWebsite(url: String) -> Result:
  url
    // 1. The Browser tool fetches the raw HTML, automatically strips out 
    //    script tags and CSS, and returns clean readable text.
    |> Reader.execute()

    // 2. The LLM reads the scraped website and summarizes it
    |> Assistant.prompt("Summarize the following website content in one sentence.")
    
    // 3. We pass the summary into a real bash script to write it to disk!
    |> Shell.execute(command: "echo {{context.current}} > .website_summary.txt")
    
    // 4. Verify it wrote correctly
    |> Shell.execute(command: "cat .website_summary.txt")
    |> System.Print()

// ============================================================
// HOW IT WORKS UNDER THE HOOD:
// 1. The BrowserTool uses native Fetch to hit the URL.
// 2. The BashTool uses `Bun.spawn` to securely execute commands 
//    on your local machine and captures stdout/stderr.
// 3. Halo fills in variables like `{{context.current}}` before running the
//    command, shell-quoting each value so text from a web page or a model
//    can't run as a command. Don't wrap {{...}} in your own quotes.
// ============================================================

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