You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 798798f
Browse filesBrowse the repository at this point in the historyBrowse files
Actions wait up to ten minutes, and a timed-out wait leaves the run going. A prompt sent during a run queues as a follow-up. See the <ahref="https://github.com/rivet-dev/agents/blob/main/packages/pi/src/actions.ts"target="_blank"rel="noopener noreferrer">source</a> for every action.
149
+
Actions wait up to ten minutes, and a timed-out wait leaves the run going. A prompt sent during a run queues as a follow-up. `submit` takes the same options as `prompt` and returns `{ submissionId }` at once. Pair it with `onAnswer` to deliver the answer. See the <ahref="https://github.com/rivet-dev/agents/blob/main/packages/pi/src/actions.ts"target="_blank"rel="noopener noreferrer">source</a> for every action.
150
+
151
+
## Deliver answers
152
+
153
+
`onAnswer` runs in the agent Actor for every final answer, with the Actor's context. Use it to send answers somewhere, such as a chat app or a text message, without a client waiting on `prompt`:
- It gets `{ conversationId, text, message }`. Responses that only call tools aren't final answers, so they don't call it.
158
+
- It runs inside the run, so an answer that finishes after a crash or restart is still delivered. If the Actor stops while `onAnswer` is running, it can run again for the same answer.
159
+
- A throw goes to `onReport` and leaves the answer in the conversation.
160
+
- It runs in conversations that use the default extensions. A conversation that selects its extensions by name doesn't get it.
161
+
162
+
See [Personal Agent over SMS](/guides/personal-agent) for a complete example.
150
163
151
164
## Stream a conversation
152
165
@@ -211,6 +224,7 @@ The `pi()` function accepts every [`actor()`](/actors/docs/actor-configuration)
211
224
|`sandbox`| Where `CodingTools` run. Without one, files live in the Actor's database. See [Sandboxes](/agents/docs/sandboxes). |
212
225
|`documents`| Documents clients may read. |
213
226
|`settings`| Pi Durable settings, such as `retry` and `compaction`. |
227
+
|`onAnswer`| Runs for every final answer. See [Deliver answers](#deliver-answers). |
214
228
215
229
Other options, such as `thinkingLevel` and `env`, pass through to Pi Durable. By default, `actionTimeout` is ten minutes and `sleepGracePeriod` is 15 minutes. A `ConversationBusy` error reaches clients as a `UserError`, and other Pi Durable errors as internal errors.
<ExampleLinkBarhref="https://github.com/rivet-dev/agents/tree/main/examples/docs/sign-in-with-chatgpt"label="Prefer to read code? See the full example on GitHub."/>
<svgviewBox="0 0 700 430"role="img"aria-label="The user calls start on the chatgptLogin Actor, which returns a sign-in URL. The user signs in at OpenAI and chooses Continue. OpenAI redirects the browser to a 127.0.0.1 URL. The user passes that URL to finish. The chatgptLogin Actor exchanges the code with OpenAI for tokens and saves the login to the user's credentials Actor."style="width:100%;min-width:600px;max-width:700px;height:auto;display:block;margin:2.5rem auto;font-family:system-ui,sans-serif">
0 commit comments