mirror of
https://github.com/zap-proto/dev.git
synced 2026-10-30 15:05:18 +00:00
Folds rich SDK content out of hanzoai/docs into zap-proto/dev (canonical brand). Per-SDK pages: typescript, go, python, rust, cpp, c, java, csharp, ocaml, haskell, erlang. Each carries install, quick-start, client API, gateway, error handling, server impl, and testing. Top-level /sdks/ adds the matrix of all 33 zap-proto repos (core SDKs, community SDKs, wire encoders, editor plugins, tools, protocols over ZAP, spec/research).
80 lines
1.7 KiB
Plaintext
80 lines
1.7 KiB
Plaintext
---
|
|
title: Erlang
|
|
description: ZAP Erlang SDK - OTP-compatible binding
|
|
---
|
|
|
|
# Erlang Binding
|
|
|
|
The Erlang binding provides OTP-compatible processes for ZAP communication.
|
|
|
|
## Installation
|
|
|
|
Add to `rebar.config`:
|
|
|
|
```erlang
|
|
{deps, [
|
|
{zap, {git, "https://github.com/zap-proto/spec-erl.git", {tag, "0.1.0"}}}
|
|
]}.
|
|
```
|
|
|
|
## Quick Start
|
|
|
|
```erlang
|
|
-module(my_agent).
|
|
-export([start/0]).
|
|
|
|
start() ->
|
|
{ok, Client} = zap:connect("zap://localhost:9000"),
|
|
|
|
{ok, Server} = zap:init(Client, #{
|
|
name => <<"my-agent">>,
|
|
version => <<"1.0.0">>
|
|
}),
|
|
io:format("Connected to: ~s v~s~n", [
|
|
maps:get(name, Server),
|
|
maps:get(version, Server)
|
|
]),
|
|
|
|
{ok, Tools} = zap:list_tools(Client),
|
|
lists:foreach(fun(Tool) ->
|
|
io:format(" ~s - ~s~n", [
|
|
maps:get(name, Tool),
|
|
maps:get(description, Tool)
|
|
])
|
|
end, Tools),
|
|
|
|
{ok, Result} = zap:call_tool(Client, #{
|
|
id => <<"call-1">>,
|
|
name => <<"read_file">>,
|
|
args => <<"{\"path\": \"/etc/hosts\"}">>
|
|
}),
|
|
|
|
case maps:get(error, Result, undefined) of
|
|
undefined ->
|
|
io:format("Result: ~s~n", [maps:get(content, Result)]);
|
|
Error ->
|
|
io:format("Error: ~s~n", [Error])
|
|
end,
|
|
|
|
zap:close(Client).
|
|
```
|
|
|
|
## OTP Integration
|
|
|
|
```erlang
|
|
-module(zap_agent).
|
|
-behaviour(gen_server).
|
|
|
|
init([Url]) ->
|
|
{ok, Client} = zap:connect(Url),
|
|
{ok, #{client => Client}}.
|
|
|
|
handle_call({call_tool, Call}, _From, #{client := Client} = State) ->
|
|
Result = zap:call_tool(Client, Call),
|
|
{reply, Result, State}.
|
|
```
|
|
|
|
## Documentation
|
|
|
|
Full documentation at [zap-proto/spec-erl](https://github.com/zap-proto/spec-erl).
|