ZAP Protocol
Language Bindings

OCaml

ZAP OCaml SDK - Functional binding with Lwt

OCaml Binding

The OCaml binding provides a functional interface with Lwt-based async I/O.

Installation

opam install zap

Quick Start

open Zap
open Lwt.Infix

let () =
  Lwt_main.run begin
    Zap.connect "zap://localhost:9000" >>= fun client ->

    let info = { name = "my-agent"; version = "1.0.0" } in
    Zap.init client info >>= fun server ->
    Lwt_io.printf "Connected to: %s v%s\n" server.name server.version >>= fun () ->

    Zap.list_tools client >>= fun tools ->
    Lwt_list.iter_s (fun tool ->
      Lwt_io.printf "  %s - %s\n" tool.name tool.description
    ) tools >>= fun () ->

    let call = {
      id = "call-1";
      name = "read_file";
      args = {|{"path": "/etc/hosts"}|};
      metadata = [];
    } in
    Zap.call_tool client call >>= fun result ->

    match result.error with
    | Some err -> Lwt_io.eprintf "Error: %s\n" err
    | None -> Lwt_io.printf "Result: %s\n" result.content
  end

Documentation

Full documentation at zap-protocol/zap-ocaml.

Last updated on

On this page