HttpAgent
com.agui.community.client.HttpAgent is an Agent backed by a remote AG-UI endpoint. When a subscriber subscribes, it:
- Serializes the
RunAgentInputto JSON. - Sends a
POSTto the endpoint withContent-Type: application/jsonandAccept: text/event-stream. - Reads the SSE response line by line and deserializes each
data:payload into anEvent. - Publishes the events in order, then completes when the response ends.
Constructors
Reading an SSE response blocks a thread for the whole run. By default,
HttpAgent uses an unbounded cached thread pool so that many concurrent runs cannot starve a shared bounded pool such as ForkJoinPool.commonPool(). If you supply your own executor, make sure it has enough threads for your concurrency. On Java 21+, a virtual-thread executor is a good fit:
Runs and subscriptions
run(input) itself sends nothing. Each subscribe call on the returned publisher starts a separate HTTP request, so if you subscribe twice the agent runs twice. Events are delivered through a SubmissionPublisher, which respects the subscriber’s request(n) demand.
Errors
These failures are delivered to the subscriber’sonError:
A failure inside the agent is not reported this way. Once the server has started streaming, an agent failure arrives as a normal
RunErrorEvent and the stream then completes, so handle RunErrorEvent in onNext.
Authentication and headers
HttpAgent sends a fixed set of request headers and has no option for adding more, such as an Authorization: Bearer token. Your options are:
- For HTTP Basic or proxy authentication, configure an
Authenticatoron theHttpClientyou pass in. - Put the endpoint behind a gateway that adds credentials.
- Implement your own
Agentthat builds the request itself.HttpAgentis a small class, and its source is a good starting point.
SSE parsing
The internal parser follows the SSE format. It joins multi-linedata: fields with \n, ignores comment lines (:), and ignores the event, id and retry fields. If the stream ends without a final blank line, it still dispatches the last pending event.