showcase/shell-docs/src/content/ag-ui/sdk/js/client/http-agent.mdx
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 User Interaction Protocol events.
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
}
const agent = new HttpAgent({
url: "https://api.example.com/v1/agent",
headers: {
Authorization: "Bearer your-api-key",
},
});
Executes the agent by making an HTTP request to the configured endpoint.
runAgent(parameters?: RunAgentParameters, subscriber?: AgentSubscriber): Promise<RunAgentResult>
The parameters argument follows the standard RunAgentParameters interface.
The optional subscriber parameter allows you to provide an
AgentSubscriber for handling events during this
specific run.
interface RunAgentResult {
result: any; // The final result returned by the agent
newMessages: Message[]; // New messages added during this run
}
Adds an AgentSubscriber to handle events across multiple agent runs.
subscribe(subscriber: AgentSubscriber): { unsubscribe: () => void }
Returns an object with an unsubscribe() method to remove the subscriber when
no longer needed.
Cancels the current HTTP request using the AbortController.
abortRun(): void
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,
}
Implements the abstract run() method from AbstractAgent using HTTP requests.
run(input: RunAgentInput): RunAgent
url: The endpoint URL for the agent serviceheaders: HTTP headers to include with requestsabortController: AbortController instance for request cancellation