Package com.tnsai.thread
Class ResourceQuota
java.lang.Object
com.tnsai.thread.ResourceQuota
Resource limits for an
AgentThread.
Defines constraints for:
- Token usage (input + output)
- Tool/function call count
- Execution time
- Memory usage
- Child thread count
Example:
ResourceQuota quota = ResourceQuota.builder()
.maxTokens(100_000)
.maxToolCalls(50)
.maxDuration(Duration.ofMinutes(30))
.maxChildThreads(5)
.build();
- Since:
- 0.0.2
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault: 10 child threadsstatic final DurationDefault: 1 hourstatic final longDefault: 100MB memorystatic final longDefault: 100K tokensstatic final intDefault: 100 tool calls -
Method Summary
Modifier and TypeMethodDescriptionstatic ResourceQuota.Builderbuilder()static ResourceQuotadefaults()Create with default limits.booleanintintlonglongintinthashCode()booleanisDurationExceeded(Duration elapsed) Check if duration limit is exceeded.booleanisTokenLimitExceeded(long usedTokens) Check if token limit is exceeded.booleanisToolCallLimitExceeded(int usedToolCalls) Check if tool call limit is exceeded.static ResourceQuotaminimal()Create a minimal quota for testing.longremainingTokens(long usedTokens) Calculate remaining tokens.intremainingToolCalls(int usedToolCalls) Calculate remaining tool calls.toString()static ResourceQuotaCreate with unlimited resources (use carefully).
-
Field Details
-
DEFAULT_MAX_TOKENS
public static final long DEFAULT_MAX_TOKENSDefault: 100K tokens- See Also:
-
DEFAULT_MAX_TOOL_CALLS
public static final int DEFAULT_MAX_TOOL_CALLSDefault: 100 tool calls- See Also:
-
DEFAULT_MAX_DURATION
Default: 1 hour -
DEFAULT_MAX_CHILD_THREADS
public static final int DEFAULT_MAX_CHILD_THREADSDefault: 10 child threads- See Also:
-
DEFAULT_MAX_MEMORY_BYTES
public static final long DEFAULT_MAX_MEMORY_BYTESDefault: 100MB memory- See Also:
-
-
Method Details
-
defaults
Create with default limits. -
unlimited
Create with unlimited resources (use carefully). -
minimal
Create a minimal quota for testing. -
builder
-
getMaxTokens
public long getMaxTokens() -
getMaxToolCalls
public int getMaxToolCalls() -
getMaxDuration
-
getMaxChildThreads
public int getMaxChildThreads() -
getMaxMemoryBytes
public long getMaxMemoryBytes() -
getMaxConcurrentTools
public int getMaxConcurrentTools() -
isTokenLimitExceeded
public boolean isTokenLimitExceeded(long usedTokens) Check if token limit is exceeded. -
isToolCallLimitExceeded
public boolean isToolCallLimitExceeded(int usedToolCalls) Check if tool call limit is exceeded. -
isDurationExceeded
Check if duration limit is exceeded. -
remainingTokens
public long remainingTokens(long usedTokens) Calculate remaining tokens. -
remainingToolCalls
public int remainingToolCalls(int usedToolCalls) Calculate remaining tool calls. -
equals
-
hashCode
public int hashCode() -
toString
-