Package com.tnsai.exceptions
Class TaskCompleteException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.tnsai.exceptions.TnsAIException
com.tnsai.exceptions.TaskCompleteException
- All Implemented Interfaces:
Serializable
Signals that a task has been completed and the agent loop should terminate.
This is a control flow exception, not an error. It's thrown by completion signal actions to indicate successful task termination.
Usage
@ActionSpec(type = ActionType.LOCAL)
@CompletionSignal
public void markComplete(String summary) {
// Do any final cleanup
saveResults();
// Signal completion
throw new TaskCompleteException(summary);
}
// With result data
throw TaskCompleteException.withResult("Task done", Map.of(
"filesCreated", 5,
"testsRun", 42
));
Handling in Agent Loop
try {
agent.run(task);
} catch (TaskCompleteException e) {
System.out.println("Task completed: " + e.getSummary());
System.out.println("Result: " + e.getResult());
System.out.println("Success: " + e.isSuccess());
}
Comparison with CompletionCriteria
| Feature | TaskCompleteException | CompletionCriteria |
|---|---|---|
| Control | LLM decides when done | External criteria |
| Timing | Explicit action call | Checked after each turn |
| Use case | Task signals completion | Max iterations, output patterns |
- Author:
- TnsAI Team
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTaskCompleteException(String summary) Creates a completion exception with just a summary.TaskCompleteException(String summary, Object result) Creates a completion exception with summary and result.Creates a completion exception with all parameters. -
Method Summary
Modifier and TypeMethodDescriptionstatic TaskCompleteExceptionCreates a failed completion.Gets the metadata map.getMetadataValue(String key) Gets a specific metadata value.Gets the result data.<T> TgetResultAs(Class<T> type) Gets the result as a specific type.Gets the completion summary.booleanChecks if result is present.booleanChecks if completion was successful.toString()static TaskCompleteExceptionwithMetadata(String summary, Map<String, Object> metadata) Creates a completion with metadata.static TaskCompleteExceptionwithResult(String summary, Object result) Creates a successful completion with result.Methods inherited from class com.tnsai.exceptions.TnsAIException
getContext, getErrorCode, getMaxRetryAttempts, getMessage, getSuggestedRetryDelayMs, getThrownAt, isRetryable, wrapMethods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
Constructor Details
-
TaskCompleteException
Creates a completion exception with just a summary.- Parameters:
summary- brief description of completion
-
TaskCompleteException
Creates a completion exception with summary and result.- Parameters:
summary- brief description of completionresult- the result data
-
TaskCompleteException
public TaskCompleteException(String summary, Object result, boolean success, Map<String, Object> metadata) Creates a completion exception with all parameters.- Parameters:
summary- brief description of completionresult- the result datasuccess- whether completion was successfulmetadata- additional metadata
-
-
Method Details
-
withResult
Creates a successful completion with result.- Parameters:
summary- completion summaryresult- the result data- Returns:
- completion exception
-
failed
Creates a failed completion.- Parameters:
summary- failure summaryreason- the failure reason- Returns:
- completion exception
-
withMetadata
Creates a completion with metadata.- Parameters:
summary- completion summarymetadata- additional metadata- Returns:
- completion exception
-
getSummary
Gets the completion summary.- Returns:
- brief description of completion
-
getResult
Gets the result data.- Returns:
- result object or null
-
getResultAs
Gets the result as a specific type.- Type Parameters:
T- expected type- Parameters:
type- the class of expected type- Returns:
- typed result or null
-
isSuccess
public boolean isSuccess()Checks if completion was successful.- Returns:
- true if successful
-
getMetadata
Gets the metadata map.- Returns:
- immutable metadata map
-
getMetadataValue
Gets a specific metadata value.- Parameters:
key- the metadata key- Returns:
- value or null
-
hasResult
public boolean hasResult()Checks if result is present.- Returns:
- true if result is not null
-
toString
-