how do I send message using server sdks to the age...
# ask-ai
j
how do I send message using server sdks to the agent in the latest version?
t
Thanks for reaching out, meetakshay99. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd love to help you out! Could you please share a bit more about your situation? • Are you looking to send messages from a server application to an agent who's already active in a room? • What kind of data are you hoping to send? For example, is it text messages, control commands, or maybe some structured data? • Which server SDK are you working with? Is it Node.js, Python, Go, or something else? • Are you aiming for real-time two-way communication, or just one-way messaging? Sources: AI Agents Framework | livekit/livekit_composite | DeepWiki | packages/livekit-server-sdk/src/AgentDispatchClient.ts | Mobile SDKs (Flutter, iOS, Android) | livekit/livekit_composite | DeepWiki | Node.js Agents Architecture | livekit/livekit_composite | DeepWiki | livekit-agents/README.md
j
working with java server sdk, looking from one-way messaging from server to agent, want to send json strings, want to send to agent already present in the room
t
To send one-way JSON messages from a Java server SDK to an agent already present in a LiveKit room, you can use the
sendData
method provided by the Kotlin SDK (which works seamlessly with Java). Here's a simple way to get this set up:
Copy code
// Create RoomServiceClient
RoomServiceClient roomService = RoomServiceClient.createClient(
    "your-livekit-url", 
    "your-api-key", 
    "your-api-secret"
);

// Prepare JSON message
String jsonMessage = "{\"action\": \"update\", \"value\": 123}";
byte[] dataBytes = jsonMessage.getBytes(StandardCharsets.UTF_8);

// Send to specific agent by identity
List<String> destinationIdentities = Arrays.asList("agent-identity");

// Send the data
Call<Void> call = roomService.sendData(
    "room-name",
    dataBytes,
    LivekitModels.DataPacket.Kind.RELIABLE,
    Collections.emptyList(), // destinationSids
    destinationIdentities,   // destinationIdentities
    "custom-topic"          // optional topic
);

// Execute the call
call.execute();
Key Details to Keep in Mind: • Delivery Options: You can choose
RELIABLE
if you want to make sure the message gets through, or
LOSSY
if you prefer faster, real-time updates. • Targeting: Use
destinationIdentities
to direct your message to specific agents by their identity. • Authentication: Just make sure your API credentials include
roomAdmin
permissions to have the right access. If anything feels unclear or you want to explore this further, please don’t hesitate to reach out—I’m here to help! Sources: agent-console/app/api/room/send-data/route.ts | src/main/kotlin/io/livekit/server/RoomServiceClient.kt | Data packets | LiveKit Docs | packages/livekit-server-sdk/src/RoomServiceClient.ts | avatars/hedra/education_avatar/agent.py
j
That does not work
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!