remoteAgent<State> function

AgentApi<State> remoteAgent<State>({
  1. required String url,
  2. String? getSnapshotUrl,
  3. String? abortUrl,
  4. HeadersResolver? headers,
  5. AgentStateManagement? stateManagement,
  6. SchemanticType<State>? stateSchema,
  7. Client? httpClient,
})

Creates a typed client for talking to a Genkit agent over HTTP.

  • url: Required. The agent endpoint.
  • getSnapshotUrl: Optional. Defaults to '$url/getSnapshot'.
  • abortUrl: Optional. Defaults to '$url/abort'.
  • headers: Optional. Static headers, or a function called per request.
  • stateManagement: Optional. Declares server- vs client-managed state; inferred otherwise.
  • stateSchema: Optional. When provided, chat().state / res.state return parsed State instances (e.g. a schemantic-generated class) instead of the raw JSON map. When omitted, state is a bare view cast over the JSON.
  • httpClient: Optional. Provide to control the HTTP client lifecycle. When supplied, the client stays caller-owned and is not closed by AgentApi.close; when omitted, an internal client is created and closed by AgentApi.close.
final agent = remoteAgent(url: 'http://host/weatherAgent');
final chat = agent.chat();
final res = await chat.send(text: 'Weather in Tokyo?');
print(res.text);
// Release the internally-created HTTP client when done.
await agent.close();

Implementation

AgentApi<State> remoteAgent<State>({
  required String url,
  String? getSnapshotUrl,
  String? abortUrl,
  HeadersResolver? headers,
  AgentStateManagement? stateManagement,
  SchemanticType<State>? stateSchema,
  http.Client? httpClient,
}) => AgentApi<State>(
  _HttpAgentTransport(
    url: url,
    getSnapshotUrl: getSnapshotUrl,
    abortUrl: abortUrl,
    headers: headers,
    stateManagement: stateManagement,
    httpClient: httpClient,
  ),
  stateSchema: stateSchema,
);