Class Screens
java.lang.Object
uno.anahata.asi.agi.tool.ToolContext
uno.anahata.asi.agi.tool.AnahataToolkit
uno.anahata.asi.swing.toolkit.Screens
- All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable
A hardware-aware toolkit for capturing high-fidelity screenshots of the host
system's displays and individual application windows.
This toolkit leverages the UICapture
utility to perform native screen scraping. It is primarily used by the ASI to
"see" the user's current workspace or specific application states.
- Author:
- anahata
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a shared rectangular region of the screen. -
Field Summary
FieldsModifier and TypeFieldDescriptionThe list of physical device indexes currently being shared in multimodal turns.private final List<Screens.SharedRegion> The list of rectangular regions currently being shared in multimodal turns.Fields inherited from class AnahataToolkit
childrenProviders, propertyChangeSupportModifier and TypeFieldDescriptionprotected List<ContextProvider> The list of child context providers managed by this toolkit.protected PropertyChangeSupportSupport for firing property change events.Fields inherited from class ToolContext
toolkitModifier and TypeFieldDescriptionprotected JavaObjectToolkitThe toolkit instance that owns this context. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncaptureRegion(int x, int y, int width, int height) Captures a specific region of the primary screen.intGets the total number of items currently being shared (displays plus custom regions).Gets a list of system instruction strings provided by this context provider.voidpopulateMessage(RagMessage ragMessage) Populates the givenRagMessagewith dynamic, just-in-time context parts.Orchestrates a bulk capture of all visible application windows currently managed by the host's window manager.startSharingRegion(int x, int y, int w, int h, String name) Adds a specific rectangular region to the live share.stopSharingRegion(String regionId) Stops sharing a specific region by its ID.takeScreenshot(int deviceIdx) Captures a screenshot of a specific physical display device identified by its index.toggleDeviceSharing(int deviceIdx) Toggles sharing for a specific screen device.Methods inherited from class AnahataToolkit
getChildrenProviders, getDescription, getId, getName, getParentProvider, getPropertyChangeSupport, initialize, isEffectivelyProviding, postActivate, rebindModifier and TypeMethodDescriptionGets the list of immediate child context providers.Gets a detailed description of what this context provider does.getId()Gets the unique identifier for this context provider.getName()Gets the human-readable name of this context provider.Gets the parent context provider in the hierarchy, if any.Gets the PropertyChangeSupport instance for this object.voidPerforms initial setup for a newly created toolkit instance.booleanOverride to also take into consideration theAbstractToolkit.enabledvoidCallback method triggered by the Asi Container once the Agi session has been fully deserialized and associated to the ASI container.voidrebind()Rebinds the toolkit after deserialization.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.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ContextProvider
getAgi, getContextPosition, getFlattenedHierarchy, getFullyQualifiedId, getHeader, getIconId, getInstructionsTokenCount, getRagTokenCount, isProviding, setParentProvider, setProvidingModifier and TypeMethodDescriptiongetAgi()Gets the parent AGI session this context provider is registered under.default ContextPositionGets the designated position of this provider's content in the AI prompt.default List<ContextProvider> getFlattenedHierarchy(boolean providingOnly) Gets a flattened list of this provider and all its descendants in the hierarchy.default StringGets the fully qualified ID of this provider, reflecting its position in the hierarchy.default StringGenerates a machine-readable header string for this context provider, used to identify the source of injected context in the final prompt.default StringGets an optional icon identifier for this provider.default intCalculates the token count for the system instructions provided by this instance using the active model.default intCalculates the token count for the RAG content provided by this instance using the active model.booleanChecks if this context provider is currently active and providing context.default voidsetParentProvider(ContextProvider parent) Sets the parent context provider for this instance.default voidsetProviding(boolean enabled) Sets whether this context provider is enabled.
-
Field Details
-
Constructor Details
-
Screens
public Screens()
-
-
Method Details
-
getSystemInstructions
-
populateMessage
Populates the givenRagMessagewith dynamic, just-in-time context parts. These parts are appended to the end of the user's prompt (RAG).- Parameters:
ragMessage- The message to be augmented with context.
-
toggleDeviceSharing
Toggles sharing for a specific screen device.- Parameters:
deviceIdx- The index of the device.- Returns:
- A status message.
-
startSharingRegion
-
stopSharingRegion
-
takeScreenshot
Captures a screenshot of a specific physical display device identified by its index.The resulting image is automatically added as an attachment to the current tool response, making it immediately available to the model's vision system.
- Parameters:
deviceIdx- The 0-based index of the graphics device (0 is usually the primary display).- Returns:
- A descriptive status message confirming the capture and attachment.
- Throws:
IOException- if the native capture operation fails.Exception
-
screenshotAllWindows
Orchestrates a bulk capture of all visible application windows currently managed by the host's window manager.Each window is captured as a separate image and attached to the tool response. This is particularly useful for multi-window discovery tasks.
- Returns:
- A status message indicating the total number of windows captured.
- Throws:
Exception- if the window enumeration or capture fails.
-
captureRegion
Captures a specific region of the primary screen.- Parameters:
x- X coordinate of the top-left corner.y- Y coordinate of the top-left corner.width- Width of the region.height- Height of the region.- Returns:
- A status message with the file path.
- Throws:
Exception- if the native capture operation fails.

