Skip to main content

a3s_ahp/
lib.rs

1//! Agent Harness Protocol (AHP) v2.4
2//!
3//! Universal, transport-agnostic protocol for supervising autonomous AI agents.
4//!
5//! # Overview
6//!
7//! AHP provides a framework-agnostic interface for supervising, controlling, and auditing
8//! AI agents. Unlike traditional monitoring solutions tightly coupled to specific frameworks,
9//! AHP works with any agent system through a standardized JSON-RPC 2.0 protocol.
10//!
11//! # Features
12//!
13//! - **Framework-agnostic** — Works with any agent system
14//! - **Language-neutral** — Harness servers can be written in any language
15//! - **Transport-flexible** — Supports stdio, HTTP, WebSocket, and Unix sockets;
16//!   gRPC is reserved as a feature placeholder
17//! - **Bidirectional** — Agents can query the harness for guidance
18//! - **Secure** — Built-in authentication and encryption support
19//!
20//! # Quick Start
21//!
22//! ```no_run
23//! use a3s_ahp::{AhpClient, Transport, EventType, Decision};
24//!
25//! # async fn example() -> anyhow::Result<()> {
26//! // Create client with stdio transport
27//! let client = AhpClient::new(Transport::Stdio {
28//!     program: "python3".into(),
29//!     args: vec!["harness.py".into()],
30//! }).await?;
31//!
32//! // Send handshake
33//! let handshake = client.handshake(Vec::new()).await?;
34//! println!("Connected to: {}", handshake.harness_info.name);
35//!
36//! // Send pre-action event
37//! let decision = client.send_event_decision(EventType::PreAction, serde_json::json!({
38//!     "action_type": "tool_call",
39//!     "tool_name": "bash",
40//!     "arguments": { "command": "ls -la" }
41//! })).await?;
42//!
43//! match decision {
44//!     Decision::Allow { .. } => println!("Action allowed"),
45//!     Decision::Block { reason, .. } => println!("Action blocked: {}", reason),
46//!     _ => {}
47//! }
48//! # Ok(())
49//! # }
50//! ```
51
52pub mod auth;
53pub mod client;
54pub mod error;
55pub mod protocol;
56pub mod server;
57pub mod transport;
58
59// Re-exports
60pub use auth::{AuthConfig, AuthMethod};
61pub use client::AhpClient;
62pub use error::{AhpError, Result};
63pub use protocol::{
64    AgentInfo, AhpErrorObject, AhpEvent, AhpNotification, AhpRequest, AhpResponse, ArtifactRef,
65    BatchRequest, BatchResponse, ConfirmationDecision, ConfirmationEvent, ConfirmationType,
66    ContextPerceptionDecision, ContextPerceptionEvent, Decision, EventContext, EventType,
67    EvidenceRef, Fact, FileContentSnippet, HandshakeRequest, HandshakeResponse, HarnessConfig,
68    HarnessInfo, HeartbeatEvent, HistoryItem, IdleDecision, IdleEvent, InjectedContext,
69    IntentDetectionDecision, IntentDetectionEvent, MemoryRecallDecision, MemoryRecallEvent,
70    MemorySummary, PerceptionConstraints, PerceptionContext, PerceptionDomain, PerceptionFreshness,
71    PerceptionIntent, PerceptionModality, PerceptionTarget, PerceptionUrgency, PlanningDecision,
72    PlanningEvent, PlanningStrategy, ProjectSummary, QueryRequest, QueryResponse,
73    RateLimitDecision, RateLimitEvent, RateLimitType, ReasoningDecision, ReasoningEvent,
74    ReasoningType, RunLifecycleEvent, RunStatus, SessionStats, SuccessEvent, TargetHints, TaskItem,
75    TaskListEvent, TaskStatus, TimeRange, VerificationCheck, VerificationEvent, VerificationStatus,
76};
77pub use server::AhpServer;
78pub use transport::{Transport, TransportConfig};
79
80/// Protocol version
81pub const PROTOCOL_VERSION: &str = "2.4";
82
83/// Default timeout for blocking requests (milliseconds)
84pub const DEFAULT_TIMEOUT_MS: u64 = 10_000;
85
86/// Default batch size
87pub const DEFAULT_BATCH_SIZE: usize = 100;