Overview
This guide demonstrates how to create an interactive dashboard for managing and monitoring distributed AI agents using Panel, a powerful Python library for creating web applications.
import panel as pn
import param
import holoviews as hv
import numpy as np
from datetime import datetime
import queue
import pika
import json
pn.extension('tabulator', 'ace')
Implementation
1. Agent Deployment Tab
class AgentDeploymentTab(param.Parameterized):
agent_name = param.String(default="agent-1")
agent_instances = param.Integer(default=1, bounds=(1, 10))
agent_prompt = param.String(default="You are a helpful assistant.")
deployment_location = param.ObjectSelector(default="local",
objects=["local", "aws", "gcp", "azure"])
def deploy_agent(self, event):
# Implementation for agent deployment
return f"Deployed {self.agent_instances} instances of {self.agent_name}"
def create_view(self):
deploy_button = pn.widgets.Button(name='Deploy Agent', button_type='primary')
deploy_button.on_click(self.deploy_agent)
return pn.Column(
pn.widgets.TextInput.from_param(self.param.agent_name),
pn.widgets.IntSlider.from_param(self.param.agent_instances),
pn.widgets.TextAreaInput.from_param(self.param.agent_prompt,
height=150),
pn.widgets.Select.from_param(self.param.deployment_location),
deploy_button,
sizing_mode='stretch_width'
)
2. Network Monitoring Tab
class NetworkMonitorTab(param.Parameterized):
def create_network_graph(self):
# Sample network visualization
nodes = hv.Nodes([('A', 0), ('B', 1), ('C', 2)])
edges = hv.Edges([('A', 'B'), ('B', 'C'), ('C', 'A')])
graph = nodes * edges
return graph.opts(
opts.Nodes(size=20, padding=0.1),
opts.Edges(line_width=2)
)
def create_communication_log(self):
return pn.widgets.Tabulator(
{
'Timestamp': [],
'From': [],
'To': [],
'Message': []
},
height=300
)
def create_view(self):
return pn.Column(
pn.Row(
self.create_network_graph(),
self.create_communication_log()
),
sizing_mode='stretch_width'
)
3. RabbitMQ Monitoring Tab
class RabbitMQMonitorTab(param.Parameterized):
def create_queue_metrics(self):
queue_stats = pn.indicators.Trend(
name='Messages in Queue',
value=0,
plot_type='line',
width=300
)
return queue_stats
def create_agent_metrics(self):
return pn.GridStack(
pn.indicators.Number(name='Active Agents', value=0),
pn.indicators.Number(name='Messages Processed', value=0),
pn.indicators.Number(name='Average Response Time', value=0),
ncols=3
)
def create_view(self):
return pn.Column(
self.create_agent_metrics(),
self.create_queue_metrics(),
sizing_mode='stretch_width'
)
4. Chat Interface
class ChatInterface(param.Parameterized):
message = param.String(default="")
def send_message(self, event):
# Implementation for sending message to agents
pass
def create_view(self):
chat_history = pn.widgets.TextAreaInput(
value="",
disabled=True,
height=200
)
input_field = pn.widgets.TextInput.from_param(
self.param.message,
placeholder="Type your message here..."
)
send_button = pn.widgets.Button(
name='Send',
button_type='primary'
)
send_button.on_click(self.send_message)
return pn.Column(
chat_history,
pn.Row(input_field, send_button),
sizing_mode='stretch_width'
)
Main Dashboard Assembly
def create_dashboard():
# Initialize components
deployment_tab = AgentDeploymentTab()
network_tab = NetworkMonitorTab()
rabbitmq_tab = RabbitMQMonitorTab()
chat = ChatInterface()
# Create main layout
dashboard = pn.Column(
pn.Tabs(
('Agent Deployment', deployment_tab.create_view()),
('Network Monitor', network_tab.create_view()),
('RabbitMQ Monitor', rabbitmq_tab.create_view())
),
pn.Card(
chat.create_view(),
title='Chat Interface',
collapsed=False
),
sizing_mode='stretch_width'
)
return dashboard
# Launch the dashboard
dashboard = create_dashboard()
dashboard.servable()
Running the Dashboard
To run the dashboard:
panel serve dashboard.py --show
This implementation provides:
- Agent deployment interface with configuration options
- Network visualization and communication logs
- RabbitMQ monitoring with real-time metrics
- Interactive chat interface
Required dependencies:
- panel
- param
- holoviews
- numpy
- pika (for RabbitMQ integration)
The dashboard can be extended by:
- Adding real-time data updates using periodic callbacks
- Implementing WebSocket connections for live agent communication
- Adding authentication and user management
- Integrating with monitoring tools like Prometheus
- Adding more detailed agent configuration options