Skip to main content

Before you start

  • The agent is deployed and exposed, which is the default.
  • Your service has a service credential, and the agent lists it in callers: see Access.
1

Get a token

Your service exchanges its client id and secret for a token at the token URL:
The token lasts an hour. Reuse it until shortly before it expires, then get another.
2

Start a session

The agent answers 202 at once and works on the message in the background. The body holds the session id, and deliveryId for the message:
3

Read the reply

The session’s stream sends one JSON line per change while the agent works. A line {at, facts} holds the events one change produced, in its facts array; a line {progress} holds one piece of streamed text. This prints the finished reply:
The events you’ll use:A turn.settled with outcome "failed" says why in error.code and error.message, such as MODEL_CALL_FAILED when the model provider refuses the agent’s key. One with "cancelled" was stopped. Other events and fields can appear as eve adds them: skip the ones you don’t use.The stream starts from the session’s first line every time you open it, so it replays earlier replies too. To read only what’s new, pass how many facts and progress lines you’ve already read: /stream?startIndex=16. Don’t count the {"$eve": ...} lines, such as heartbeats. The stream stays open after turn.settled, and closes after a minute with {"$eve":"stream.lease-ended"}: open it again from your count to keep reading. Add follow=0 to get the lines so far and close at once.
4

Send the next message

It answers 202 like the first message. Read the reply from the same stream, with startIndex past what you’ve already read.

Call it from TypeScript

eve’s client does the same steps for you, reads the stream, and gets a new token when the old one expires. Install eve at the version in the agent’s package.json, such as npm install eve@1.0.0. The example reads the credential from the same variables as the curl steps, and the agent’s URL from ACME_AGENT_URL:
agent.ts
ask.ts
result() waits for the reply and returns it as reply, with status "completed", "failed" (and an error), "cancelled" or "awaiting-input".

Long-running work

A reply can take hours. Instead of holding the stream open, store the session id and check back later:
follow=0 returns the events so far and closes. The reply is ready once they include turn.settled. To read only what’s new since your last check, add startIndex with the number of facts and progress lines you’ve already read. Without it, an earlier turn’s turn.settled matches too.

Stop a reply

The agent stops the turn it’s working on, and the stream sends turn.settled with outcome "cancelled". The session takes the next message as usual.

Call on behalf of your users

Let your service forward users, as in Access. Then send the user as forwardedPrincipal with every message, the first and each one after:
From TypeScript, use fetch for these calls, since eve’s client doesn’t send forwardedPrincipal:
forward.ts
Read the reply from the session’s stream, as above. principalId is the user’s id in your service. principalType must be user, and the tenant attribute must be the agent’s organization. Inside the agent, the caller is now that user, with an eve:forwarded-by attribute naming your service.

Troubleshooting

Last modified on November 16, 2026