#agent #protocols #json-rpc #tokio

ahp

Agent Host Protocol SDK — transport-agnostic client, reducers, and JSON-RPC plumbing

9 releases (breaking)

new 0.7.0 Aug 7, 2026
0.6.0 Jul 20, 2026
0.5.2 Jul 9, 2026
0.5.0 Jun 26, 2026
0.1.0 Apr 27, 2026

#101 in Asynchronous

Download history 2968/week @ 2026-04-25 5467/week @ 2026-05-02 7458/week @ 2026-05-09 8095/week @ 2026-05-16 7478/week @ 2026-05-23 6214/week @ 2026-05-30 6735/week @ 2026-06-06 22128/week @ 2026-06-13 13015/week @ 2026-06-20 10272/week @ 2026-06-27 10010/week @ 2026-07-04 8843/week @ 2026-07-11 7189/week @ 2026-07-18 8198/week @ 2026-07-25 8496/week @ 2026-08-01

34,883 downloads per month
Used in ahp-ws

MIT license

665KB
9K SLoC

ahp

Async Rust client for the Agent Host Protocol (AHP).

crates.io docs.rs

Transport-agnostic SDK that builds on ahp-types. Bring your own transport — WebSocket, stdio, TCP, or an in-memory channel pair for tests.

Features

  • Client — async JSON-RPC client with action subscription, write-ahead dispatch, and background I/O task
  • reducers — pure state reducers; apply StateActions to RootState / SessionState / terminal state
  • Transport — pluggable trait for any framed message stream

Usage

[dependencies]
ahp = "0.1"
ahp-ws = "0.1"   # or bring your own transport
tokio = { version = "1", features = ["full"] }
use ahp::{Client, ClientConfig, SubscriptionEvent};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let transport = ahp_ws::WebSocketTransport::connect("ws://localhost:12345").await?;
    let client = Client::connect(transport, ClientConfig::default()).await?;

    client.initialize("my-client".into(), vec![ahp_types::PROTOCOL_VERSION.to_string()], vec![ahp_types::ROOT_RESOURCE_URI.to_string()]).await?;

    let mut sub = client.attach_subscription(ahp_types::ROOT_RESOURCE_URI).await;
    while let Some(SubscriptionEvent::Action(a)) = sub.recv().await {
        println!("seq={} action={:?}", a.server_seq, a.action);
    }

    client.shutdown().await;
    Ok(())
}

Custom transport

Implement ahp::Transport for any framed byte stream:

use ahp::{Transport, TransportError, TransportMessage};
use std::future::Future;

struct MyTransport { /* ... */ }

impl Transport for MyTransport {
    fn send(&mut self, msg: TransportMessage)
        -> impl Future<Output = Result<(), TransportError>> + Send
    { async { todo!() } }

    fn recv(&mut self)
        -> impl Future<Output = Result<Option<TransportMessage>, TransportError>> + Send
    { async { todo!() } }
}

See tests/client_roundtrip.rs for a complete in-memory example.

See also

Dependencies

~7–11MB
~120K SLoC