Package com.tnsai.thread
package com.tnsai.thread
Thread-based execution model for TnsAI agents.
This package provides a thread-based execution model that enables:
- Session-scoped conversations with state persistence
- Parent-child thread hierarchies for complex workflows
- Resource quotas and backpressure management
- Pause/resume and crash recovery
- Thread lifecycle management
Key Classes
AgentThread- Represents a single execution threadThreadSpec- Configuration for thread behaviorThreadManager- Manages thread lifecycleThreadState- Thread state enumResourceQuota- Resource limits for threads
Usage Example
// Create a thread manager
ThreadManager manager = new ThreadManager(checkpointer);
// Create a new thread
AgentThread thread = manager.createThread(ThreadSpec.builder()
.maxTokens(100000)
.maxToolCalls(50)
.timeout(Duration.ofMinutes(30))
.build());
// Execute within thread context
String response = thread.execute(agent, "Hello!");
// Pause and resume
thread.pause();
// ... later ...
thread.resume();
// Create child thread for sub-task
AgentThread childThread = thread.createChild(childSpec);
- Since:
- 0.0.2
-
ClassDescriptionRepresents a single execution thread for an agent.Resource limits for an
AgentThread.Events emitted byAgentThreadduring its lifecycle.Exception thrown by thread operations.Exception for invalid state transitions.Exception for quota violations.Exception for recovery failures.Manages the lifecycle ofAgentThreads.Configuration for anAgentThread.Represents the lifecycle state of anAgentThread.Tracks resource usage for anAgentThread.Snapshot for serialization.