Class SwingJava
java.lang.Object
uno.anahata.asi.agi.tool.ToolContext
uno.anahata.asi.agi.tool.AnahataToolkit
uno.anahata.asi.toolkit.java.Java
uno.anahata.asi.swing.toolkit.SwingJava
- All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable
- Direct Known Subclasses:
NbJava
An extension of the
Java toolkit that provides Swing-specific
execution utilities, such as EDT synchronization with context propagation.
This toolkit ensures that code running on the Event Dispatch Thread (EDT) can still access the tool execution context (logs, errors, attachments) by capturing and re-applying the thread-local state.
- Author:
- anahata
-
Field Summary
Fields inherited from class Java
classpathPrinter, defaultCompilerClasspath, parentFirstClassessModifier and TypeFieldDescriptionprotected VeryPrettyClassPathPrinterThe transient printer used to generate token-optimized classpath manifests.The base compiler and classloader classpath.A set of infrastructure classes that MUST always be loaded by the parent classloader (the ASI engine) to preserve static state and ThreadLocal context.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
ConstructorsConstructorDescriptionConstructs a new instance of the toolkit and adds SwingAgiTool to the list of parentFirstClassess. -
Method Summary
Modifier and TypeMethodDescriptionprotected Class<? extends ToolContext> The class the model should extend when generating Agi tools.Gets a list of system instruction strings provided by this context provider.Methods inherited from class Java
appendMethods, compile, compileAndExecute, createClassPathPrinter, findClassFallbackBytes, getClasspathPrinter, getDefaultClasspath, getPrettyPrintedDefaultClasspath, getSystemProperties, initialize, populateMessage, postActivate, registerParentFirstClass, setDefaultClasspathModifier and TypeMethodDescriptionprotected voidappendMethods(StringBuilder sb, Class<?> clazz) Appends the signatures of all declared methods of a class to a StringBuilder, filtering out standard Object methods and internal lambda/abstract cruft.Compiles Java source code into a Class object using the system's Java compiler.compileAndExecute(String sourceCode, String extraClassPath, String[] compilerOptions) Compiles and executes a Java class named 'Anahata' on the application's JVM.protected VeryPrettyClassPathPrinterFactory method to create the specialized classpath printer.protected byte[]findClassFallbackBytes(String name) A hook for subclasses to provide class bytes if the standard loading flow fails.protected final VeryPrettyClassPathPrinterGets the lazily-initialized classpath printer.Gets the current default classpath used for compilation and class loading.Returns a token-efficient, pretty-printed version of the default classpath.Generates a token-efficient, hierarchical representation of all JVM system properties (excluding the classpath itself).voidPerforms initial setup for a newly created toolkit instance.voidpopulateMessage(RagMessage ragMessage) Populates the givenRagMessagewith dynamic, just-in-time context parts.voidCallback method triggered by the Asi Container once the Agi session has been fully deserialized and associated to the ASI container.final voidRegisters a class and all its superclasses and interfaces to be loaded by the parent classloader.voidsetDefaultClasspath(String defaultCompilerClasspath) Sets the default classpath for the compiler and classloader.Methods inherited from class AnahataToolkit
getChildrenProviders, getDescription, getId, getName, getParentProvider, getPropertyChangeSupport, isEffectivelyProviding, 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.booleanOverride to also take into consideration theAbstractToolkit.enabledvoidrebind()Rebinds the toolkit after deserialization.Methods inherited from class ToolContext
addAttachment, addAttachment, addAttachment, 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(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.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.
-
Constructor Details
-
SwingJava
public SwingJava()Constructs a new instance of the toolkit and adds SwingAgiTool to the list of parentFirstClassess.
-
-
Method Details
-
getSystemInstructions
Gets a list of system instruction strings provided by this context provider. These are typically prepended to the conversation as high-level guidance.Injects Swing-specific execution helpers into the system instructions, enabling the model to use
runInEdtandrunInEdtAndWaitfor safe UI interactions.- Specified by:
getSystemInstructionsin interfaceContextProvider- Overrides:
getSystemInstructionsin classJava- Returns:
- A list of system instruction strings.
- Throws:
Exception- if an error occurs during instruction generation.
-
getConcreteClassModelShouldExtend
The class the model should extend when generating Agi tools.In this base implementation, it returns
OnTheFlyAgiTool, which provides the necessary context anchors (log, error, etc.) for the script.Configures the code generator to produce classes extending
SwingAgiTool, which provides the necessary plumbing for EDT-aware context propagation.- Overrides:
getConcreteClassModelShouldExtendin classJava- Returns:
- the base AgiTool class.
-

