Repository navigation
feat(agent): add run limits for spend, steps, and duration #9329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import { | |
| isConversationHistoryNotice, | ||
| } from '@/providers/conversation-metadata' | ||
| import { getConversationModelLimits } from '@/providers/conversation-model' | ||
| import { applyRunLimits, RunLimitError } from '@/providers/run-limits' | ||
| import { assertRunWithinUsageLimit, RunUsageLimitError } from '@/providers/run-usage-limit' | ||
| import { isAbortError } from '@/providers/streaming-tool-loop-shared' | ||
| import type { Message, ProviderRequest } from '@/providers/types' | ||
|
|
@@ -117,13 +118,15 @@ function contextError(message: string): Error { | |
|
|
||
| /** | ||
| * Provider wrappers must preserve the permanent failures this module raises, context faults and | ||
| * the run's usage-limit stop, so fallback cannot restart them and the stop keeps its billed cost. | ||
| * the run's usage-limit and run-limit stops, so fallback cannot restart them and a stop keeps its | ||
| * billed cost. | ||
| */ | ||
| export function isConversationContextError(error: unknown): boolean { | ||
| export function isPermanentGenerationError(error: unknown): boolean { | ||
| return ( | ||
| error instanceof AgentContextLimitError || | ||
| error instanceof AgentContextProtocolError || | ||
| error instanceof RunUsageLimitError | ||
| error instanceof RunUsageLimitError || | ||
| error instanceof RunLimitError | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -288,10 +291,11 @@ function nativeSummaryMessage(summary: Message, protocol: ConversationProtocol): | |
| export async function prepareConversationGeneration<T>( | ||
| request: ProviderRequest, | ||
| protocol: ConversationProtocol, | ||
| payload: T | ||
| requestedPayload: T | ||
| ): Promise<T> { | ||
| const runtime = getConversationRequestContext(request) | ||
| await assertRunWithinUsageLimit(runtime) | ||
| const payload = applyRunLimits(runtime, request, protocol, requestedPayload) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||
| if (!runtime?.agentConversation) return payload | ||
| request.abortSignal?.throwIfAborted() | ||
| if (!isRecordLike(payload)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Auto-model routing charges are added to
agent.costafter the run-limit budget is enforced, somaxRunCostcan be exceeded without stopping the agent. IncludeautoRouting.billableRoutingCostin the same run budget.Prompt for AI agents