Class DesktopToolContext
java.lang.Object
uno.anahata.asi.agi.tool.ToolContext
uno.anahata.asi.swing.toolkit.DesktopToolContext
- Direct Known Subclasses:
DesktopAgiTool
An advanced execution context that bridges the gap between background tool execution
and the Swing Event Dispatch Thread (EDT) or the JavaFX Application Thread.
This class provides the critical infrastructure for Context Propagation.
Since the AI toolchain relies on ThreadLocal state for logging and
attachments, moving execution to the EDT would normally break these links.
DesktopToolContext solves this by capturing the state and re-applying it
within the EDT task scope.
- Author:
- anahata
-
Field Summary
Fields inherited from class ToolContext
toolkitModifier and TypeFieldDescriptionprotected JavaObjectToolkitThe toolkit instance that owns this context. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConvenience method to get the AgiPanel for this Agi from the java tool.voidExecutes a task on the EDT in a non-blocking manner while maintaining full context awareness.voidrunInEdtAndWait(Runnable runnable) Executes a task on the EDT and blocks the current thread until the task is complete, maintaining full context awareness throughout.Methods inherited from class ToolContext
addAttachment, addAttachment, addAttachment, addAttachment, error, error, error, getAgi, getApplicationMap, getAsiContainer, getAsiContainerMap, getCall, getExecutorService, getModelId, getModelMessage, getResourceManager, getResponse, getSessionMap, getThreadSafeLogger, getTool, getToolContext, getToolkit, getToolManager, getTurnMap, isToolExecution, log, peekResponse, runAsyncModifier and TypeMethodDescriptionvoidaddAttachment(byte[] data, String mimeType) Attaches a binary blob to the current tool's response.voidaddAttachment(byte[] data, String mimeType, Path sourcePath) Attaches a binary blob to the current tool's response with source file path traceability.voidaddAttachment(File file) Convenience method to attach a file to the current tool's response.voidaddAttachment(Path path) Convenience method to attach a file from a Path to the current tool's response.voidAdds an error message to the current tool's response.voidAdds an error message and exception stack trace to the current tool's response.voidAdds an exceptions stack trace to the current tool's response.getAgi()Convenience method to get the parent agi container for the current execution.Gets a static, application-scoped map for sharing objects across all containers in the current JVM.Gets the current ASI container hosting this Agi container is running.Gets a map for sharing objects across all sessions within the current ASI container.getCall()Convenience method to get the current tool call that initiated this execution.Convenience method to get the executor service for the current agi session.The id of model that is executing the tool.The id of model that is executing the tool.Convenience method to get the application's ResourceManager.Gets the current tool response from the thread-local context.Gets a shared map for storing state across turns within the current agi session.Gets a thread-safe logging consumer that automatically propagates the current tool execution context whenever a message is logged.getTool()Convenience method to get the metadata for the tool currently being executed.Returns a thread-safe snapshot of this context.<T> TgetToolkit(Class<T> toolkitClass) Retrieves the singleton instance of a registered toolkit class.Convenience method to get the application's global ToolManager.Gets a shared map for storing state across turns within the current agi session.booleanChecks if the current thread or this context instance is associated with an active tool execution.voidAdds a standard log message to the current tool's response.protected JavaMethodToolResponseInternal helper to retrieve the response if it exists, without throwing an exception.voidExecutes a task asynchronously in the session's executor service, automatically propagating the current tool execution context to the background thread.
-
Constructor Details
-
DesktopToolContext
public DesktopToolContext()
-
-
Method Details
-
getAgiPanel
@Internal(value="Gets the Swing AgiPanel for this Agi", requiresCapturedToolContext=false) public AgiPanel getAgiPanel()Convenience method to get the AgiPanel for this Agi from the java tool.- Returns:
- the AgiPanel for the current Agi.
-
runInEdt
@Internal(value="Executes a task on the Swing EDT with automatic context propagation", requiresCapturedToolContext=false) public void runInEdt(Runnable runnable) Executes a task on the EDT in a non-blocking manner while maintaining full context awareness.This is the preferred way for tools to perform UI updates without freezing the AI execution thread.
- Parameters:
runnable- The UI-bound task to execute.
-
runInEdtAndWait
@Internal(value="Executes a task on the Swing EDT blocking until complete with automatic context propagation", requiresCapturedToolContext=false) public void runInEdtAndWait(Runnable runnable) throws InterruptedException, InvocationTargetException Executes a task on the EDT and blocks the current thread until the task is complete, maintaining full context awareness throughout.Use this method when subsequent tool logic depends on the UI having reached a specific state (e.g., waiting for a dialog to close or a component to render).
- Parameters:
runnable- The UI-bound task to execute.- Throws:
InterruptedException- if the background thread is interrupted during wait.InvocationTargetException- if the EDT task throws an unhandled exception.
-

