Skip to content

Commit 88216ab

Browse files
authored
Merge branch 'main' into dependabot/npm_and_yarn/mui/material-7.3.2
2 parents c02355b + e676761 commit 88216ab

File tree

5 files changed

+139
-29
lines changed

5 files changed

+139
-29
lines changed

docs/ai-interfaces/ai-agents/interact-with-ai-agents.md

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,37 @@ curl 'https://api.port.io/v1/agent/<AGENT_IDENTIFIER>/invoke?stream=true' \\
143143
--data-raw '{"prompt":"What is my next task?"}'
144144
```
145145

146+
**Processing Quota Information:**
147+
148+
When processing the streaming response, you'll receive quota usage information in the final `done` event. Here's a JavaScript example of how to handle this:
149+
150+
```javascript showLineNumbers
151+
const eventSource = new EventSource(apiUrl);
152+
153+
eventSource.addEventListener('done', (event) => {
154+
const data = JSON.parse(event.data);
155+
156+
if (data.quotaUsage) {
157+
const { remainingRequests, remainingTokens, remainingTimeMs } = data.quotaUsage;
158+
159+
// Check if quota is running low
160+
if (remainingRequests < 10 || remainingTokens < 10000) {
161+
console.warn('Quota running low, consider rate limiting');
162+
// Implement rate limiting logic
163+
}
164+
165+
// Schedule next request after quota reset if needed
166+
if (remainingRequests === 0) {
167+
setTimeout(() => {
168+
// Safe to make next request
169+
}, remainingTimeMs);
170+
}
171+
}
172+
173+
eventSource.close();
174+
});
175+
```
176+
146177
**Using MCP Server Backend Mode via API:**
147178

148179
You can override the agent's default backend mode by adding the `use_mcp` parameter:
@@ -182,7 +213,13 @@ event: execution
182213
data: Your final answer from the agent.
183214
184215
event: done
185-
data: {}
216+
data: {
217+
"maxRequests": 200,
218+
"remainingRequests": 193,
219+
"maxTokens": 200000,
220+
"remainingTokens": 179910,
221+
"remainingTimeMs": 903
222+
}
186223
```
187224

188225
**Possible Event Types:**
@@ -242,11 +279,30 @@ The final textual answer or a chunk of the answer from the agent for the user. F
242279
<details>
243280
<summary><b><code>done</code> (Click to expand)</b></summary>
244281

245-
Signals that the agent has finished processing and the response stream is complete.
282+
Signals that the agent has finished processing and the response stream is complete. This event also includes quota usage information for managing your API limits.
246283

247-
```json
248-
{}
284+
```json showLineNumbers
285+
{
286+
"quotaUsage": {
287+
"maxRequests": 200,
288+
"remainingRequests": 193,
289+
"maxTokens": 200000,
290+
"remainingTokens": 179910,
291+
"remainingTimeMs": 903
292+
}
293+
}
249294
```
295+
296+
**Quota Usage Fields:**
297+
- `maxRequests`: Maximum number of requests allowed in the current rolling window
298+
- `remainingRequests`: Number of requests remaining in the current window
299+
- `maxTokens`: Maximum number of tokens allowed in the current rolling window
300+
- `remainingTokens`: Number of tokens remaining in the current window
301+
- `remainingTimeMs`: Time in milliseconds until the rolling window resets
302+
303+
:::tip Managing quota usage
304+
Use the quota information in the `done` event to implement client-side rate limiting and avoid hitting API limits. When `remainingRequests` or `remainingTokens` are low, consider adding delays between requests or queuing them for later execution.
305+
:::
250306
</details>
251307

252308
</TabItem>
@@ -344,6 +400,8 @@ Port applies limits to AI agent interactions to ensure fair usage across all cus
344400
- **Query limit**: ~40 queries per hour.
345401
- **Token usage limit**: 800,000 tokens per hour.
346402

403+
You can view your quota limits are available in the API response.
404+
347405
:::caution Usage limits
348406
Usage limits may change without prior notice. Once a limit is reached, you will need to wait until it resets.
349407
If you attempt to interact with an agent after reaching a limit, you will receive an error message indicating that the limit has been exceeded.
@@ -448,6 +506,17 @@ Ensure that:
448506
The AI invocation entity contains the `feedback` property where you can mark is as `Negative` or `Positive`. We're working on adding a more convenient way to rate conversation from Slack and from the UI.
449507
</details>
450508

509+
<details>
510+
<summary><b>What are the usage limits and how can I know them? (Click to expand)</b></summary>
511+
512+
Port applies the following limits to AI agent interactions:
513+
- **Query limit**: ~40 queries per hour
514+
- **Token usage limit**: 800,000 tokens per hour
515+
516+
You can monitor your current usage in the final `done` event showing your remaining requests, tokens, and reset time.
517+
518+
</details>
519+
451520
<details>
452521
<summary><b>How is my data with AI agents handled? (Click to expand)</b></summary>
453522

0 commit comments

Comments
 (0)