Class Radio
- All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable
This toolkit maintains its own playback state and hardware routing, allowing for independent audio management within an AGI session. It features a custom JLayer bridge to route MP3 streams to selected hardware.
- Author:
- anahata
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classA specialized JLayer-to-JavaSound bridge that routes streams to a specificAudioDevice. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringThe URL of the currently playing station.private Future<?> The future representing the active background playback task.private javazoom.jl.player.PlayerThe active JLayer player instance.private booleanWhether the radio is currently playing.private AudioDeviceThe selected output device for radio playback.The curated list of radio stations.Fields inherited from class AnahataToolkit
childrenProviders, propertyChangeSupportFields inherited from class ToolContext
toolkit -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidPerforms initial setup for a newly created toolkit instance.private voidSelects the system's default audio output line and binds it to this toolkit.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.selectOutputDevice(String deviceId) Selects the output device for the radio.voidsetSelectedOutputDevice(AudioDevice device) Sets the selected output device and fires a property change event.Starts playing a radio station.stop()Stops the radio.Methods inherited from class AnahataToolkit
getChildrenProviders, getDescription, getId, getName, getParentProvider, getPropertyChangeSupport, isEffectivelyProviding, rebindMethods inherited from class ToolContext
addAttachment, addAttachment, addAttachment, error, error, getAgi, getApplicationMap, getAsiContainer, getAsiContainerMap, getCall, getExecutorService, getModelId, getModelMessage, getResourceManager, getResponse, getSessionMap, getThreadSafeLogger, getTool, getToolContext, getToolkit, getToolManager, getTurnMap, isToolExecution, log, peekResponse, runAsyncMethods 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, getSystemInstructions, isProviding, setParentProvider, setProviding
-
Field Details
-
STATIONS
-
currentStationUrl
The URL of the currently playing station. -
playing
private boolean playingWhether the radio is currently playing. -
selectedOutputDevice
The selected output device for radio playback. -
player
private transient javazoom.jl.player.Player playerThe active JLayer player instance.Marked as
transientbecause the native audio stream and decoder state cannot be serialized across sessions. -
playbackTask
The future representing the active background playback task.Marked as
transientas the thread state is not persistent. Used to monitor and cancel the stream during stop/restart cycles.
-
-
Constructor Details
-
Radio
public Radio()
-
-
Method Details
-
initialize
public void initialize()Performs initial setup for a newly created toolkit instance.This method is called exactly once by the
ToolManagerafter the toolkit has been instantiated and registered. It provides a clean hook for toolkits to perform one-time initialization logic that requires the tool environment to be fully configured, such as scanning for project instructions or registering default resources.Implementation details: Initializes the default hardware routing and selects a random radio station from the curated list to provide immediate ambient audio upon first activation.
- Overrides:
initializein classAnahataToolkit
-
postActivate
public void postActivate()Callback method triggered by the Asi Container once the Agi session has been fully deserialized and associated to the ASI container.Implementation details: Resumes the audio stream by submitting a new playback task to the executor service. This cannot be done in
rebind()as the Agi executor might not be ready.- Overrides:
postActivatein classAnahataToolkit
-
initOutputLineFromDefault
private void initOutputLineFromDefault()Selects the system's default audio output line and binds it to this toolkit. This ensures that audio is routed to the user's preferred device unless explicitly overridden. -
setSelectedOutputDevice
Sets the selected output device and fires a property change event.- Parameters:
device- The device to select.
-
populateMessage
Populates the givenRagMessagewith dynamic, just-in-time context parts. These parts are appended to the end of the user's prompt (RAG).Implementation details: Injects the current playback status, the active station metadata, and the full list of available curated streams into the RAG message for model awareness.
- Parameters:
ragMessage- The message to be augmented with context.- Throws:
Exception- if an error occurs during context generation.
-
start
-
stop
-
selectOutputDevice
-

