@restatedev/restate-sdk-clients, which runs in Node and in the browser.
Call the agent
The examples on this page call the following Virtual Object. Itsask handler runs the agent with the conversation of the chat ID, which is the object key:
ask with the chat ID in the path. The response contains the agent’s answer:
- Requests to the same chat ID run one at a time: Restate queues a request until the running
askfinishes. To add input to a running request instead, steer it. - The shared
historyhandler runs immediately, also whileaskruns. It returns the saved messages from indexfromon, andnext, the index to read from next time. To show what the agent does during a run, publish progress events.
Long runs
A run can take minutes, for example while it waits for a human approval. If the HTTP connection breaks during that time, for example because a proxy times out, the run continues in Restate, but the client doesn’t receive the answer. Send such requests with an idempotency key, and attach to them to wait for the answer:{"invocationId": "inv_1gdJBtdVEcM942bjcDmb1c1khoaJe11Hbz", "status": "Accepted"}. Attach with the invocation ID:
Errors
- A retryable error, such as a crash of the service, doesn’t reach the client. Restate retries the invocation, the run continues from its journal, and the client keeps waiting.
- The TypeScript client throws an
HttpCallErrorwith thestatusand the response body inresponseText. - An error with the source
invocationis the final outcome of the invocation. Sending the request again with the same idempotency key returns the same error. Sending it without an idempotency key starts a new run, which adds another turn to the conversation. See Retrying requests. - The conversation keeps a failed turn, with a note on why it failed. See Failed runs.