---
title: "Stream as agent"
method: POST
path: "/api/v1/agent/stream"
tags: ["tasks"]
---

# Stream as agent

`POST /api/v1/agent/stream`

Establishes a server streaming connection that delivers tasks to taskable agents for execution
using Server-Sent Events (SSE).

This method creates a connection from the Tasks API to an agent that streams relevant tasks to the listener agent. The agent receives a stream of tasks that match the entities specified by the tasks' selector criteria.

The stream delivers three types of requests:
- `ExecuteRequest`: Contains a new task for the agent to execute
- `CancelRequest`: Indicates a task should be canceled
- `CompleteRequest`: Indicates a task should be completed

Additionally, heartbeat messages are sent periodically to maintain the connection.

This is recommended method for taskable agents to receive and process tasks in real-time.
Agents should maintain connection to this stream and process incoming tasks according to their capabilities. 

When an agent receives a task, it should update the task status using the `UpdateStatus` endpoint
to provide progress information back to Tasks API.

## Headers

- `Authorization` string, required

## Request body

- AgentStreamRequest — The request to establish a streaming connection using Server-Sent Events (SSE) for receiving Tasks as an agent. This message defines the criteria for which tasks the agent wants to receive, typically specified using the agent's `entityId`. When an agent establishes this connection, the Lattice will stream relevant tasks to that agent to execute, cancel, or complete.
  - `agentSelector` EntityIdsSelector
    - `entityIds` string[] — Receive tasks as an assignee for one or more of the supplied entity ids.
  - `heartbeatIntervalMs` integer — The time interval, in milliseconds, that determines the frequency at which to send heartbeat events. Defaults to 30000 (30 seconds).

## Response `200`

Returns a stream of tasks to the agent as they become available.

## Other responses

- `400` — Bad request
- `401` — Unauthorized to access resource

---

[API](https://skmtc.net/anduril/apis/rest.md) · [All operations](https://skmtc.net/anduril/apis/rest/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/anduril/rest/versions/c2a841b48ac6/schema)
