HttpAgent

The HttpAgent extends AbstractAgent to provide HTTP-based connectivity to remote AI agents. It handles the request/response cycle and transforms the HTTP event stream into standard Agent Wire Protocol events.

import { HttpAgent } from "@agentwire/client"

Configuration

When creating an HTTP agent, you need to provide an HttpAgentConfig object:

interface HttpAgentConfig extends AgentConfig {
  url: string // Endpoint URL for the agent service
  headers?: Record<string, string> // Optional HTTP headers
}

Creating an HttpAgent

const agent = new HttpAgent({
  url: "https://api.example.com/v1/agent",
  headers: {
    Authorization: "Bearer your-api-key",
  },
})

Methods

runAgent()

Executes the agent by making an HTTP request to the configured endpoint. Returns an observable event stream.

runAgent(parameters?: RunHttpAgentConfig): Observable<RuntimeProtocolEvent>

Parameters

interface RunHttpAgentConfig extends RunAgentParameters {
  abortController?: AbortController // For canceling the HTTP request
}

abortRun()

Cancels the current HTTP request using the AbortController.

abortRun(): void

Protected Methods

requestInit()

Configures the HTTP request. Override this method to customize how requests are made.

protected requestInit(input: RunAgentInput): RequestInit

Default implementation:

{
  method: "POST",
  headers: {
    ...this.headers,
    "Content-Type": "application/json",
    Accept: "text/event-stream",
  },
  body: JSON.stringify(input),
  signal: this.abortController.signal,
}

run()

Implements the abstract run() method from AbstractAgent using HTTP requests.

protected run(input: RunAgentInput): RunAgent

Properties

  • url: The endpoint URL for the agent service
  • headers: HTTP headers to include with requests
  • abortController: AbortController instance for request cancellation