Skip to content

Commit 49eef84

Browse files
committed
cleaning
1 parent 29dd790 commit 49eef84

2 files changed

Lines changed: 49 additions & 19 deletions

File tree

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
# 36 - Vanilla Agent Dashboard Widgets
1+
# 40 - Vanilla Agent Dashboard Widgets
22

3-
This example demonstrates a simple agent that receives the full list of widgets present on the current dashboard and passes that context directly to the LLM. The model decides which widget(s) to use and issues a function call accordingly.
3+
This example demonstrates a simple agent that lists all widgets available on the current dashboard, showing their metadata and parameters in a structured format.
44

55
Key behaviors:
66

77
- Exposes `agents.json` with `widget-dashboard-search` enabled so the Workspace sends dashboard widget metadata (as `widgets.secondary`, etc.).
8-
- If the user has selected primary widgets, the agent immediately issues a function call to fetch data for them.
9-
- Otherwise, the agent does not select widgets heuristically. It appends the full dashboard widget list to the prompt and instructs the LLM to respond with a `get_widget_data` JSON function call when needed.
10-
- Falls back to a plain LLM reply if no data is needed.
8+
- Lists all widgets from both explicit context (primary) and dashboard context (secondary).
9+
- Shows detailed widget information including:
10+
- Widget metadata (name, description, ID, category, UUID)
11+
- Parameters table with type, default, current values, options, and descriptions
12+
- Organizes dashboard widgets by tabs for better visibility.
13+
- Does NOT automatically fetch widget data - focuses purely on widget discovery and listing.
1114

1215
## Run locally
1316

@@ -18,4 +21,4 @@ Key behaviors:
1821

1922
## Test
2023

21-
- From this directory: `poetry run pytest tests`
24+
- From this directory: `poetry run pytest tests`

40-vanilla-agent-dashboard-widgets/tests/test_agent.py

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_agents_json_has_dashboard_search_feature_enabled():
3232
assert agent["features"]["widget-dashboard-search"] is True
3333

3434

35-
def test_query_recognizes_dashboard_widgets_from_secondary():
35+
def test_query_lists_dashboard_widgets_from_secondary():
3636
test_payload_path = (
3737
Path(__file__).parent.parent.parent
3838
/ "testing"
@@ -43,17 +43,19 @@ def test_query_recognizes_dashboard_widgets_from_secondary():
4343

4444
# Simulate no explicit primary selection
4545
payload["widgets"]["primary"] = []
46-
# Ask to list widgets instead of retrieving; ensures non-LLM path is exercised
46+
# Ask to list widgets
4747
payload["messages"][0]["content"] = "What widgets are available in the dashboard?"
4848

4949
response = test_client.post("/v1/query", json=payload)
5050
assert response.status_code == 200
5151

52-
# We expect a regular message listing dashboard widgets (secondary only)
52+
# We expect a message listing dashboard widgets (secondary only)
5353
CopilotResponse(response.text).has_any("copilotMessage", "Company News")
54+
# Should show dashboard context header
55+
CopilotResponse(response.text).has_any("copilotMessage", "Dashboard Context")
5456

5557

56-
def test_query_respects_primary_selection_and_calls_get_widget_data():
58+
def test_query_lists_primary_widgets_when_selected():
5759
# Use same payload but keep primary set
5860
test_payload_path = (
5961
Path(__file__).parent.parent.parent
@@ -66,25 +68,50 @@ def test_query_respects_primary_selection_and_calls_get_widget_data():
6668
response = test_client.post("/v1/query", json=payload)
6769
assert response.status_code == 200
6870

69-
# We expect a function call – let the UI handle the actual retrieval
70-
CopilotResponse(response.text).has_any(
71-
"copilotFunctionCall", {"function": "get_widget_data"}
72-
)
71+
# We expect a message listing widgets including primary context
72+
CopilotResponse(response.text).has_any("copilotMessage", "Explicit Context")
73+
# Should also show dashboard context if available
74+
CopilotResponse(response.text).has_any("copilotMessage", "Dashboard Context")
7375

7476

75-
def test_query_lists_dashboard_widgets():
76-
# Ask to list widgets and expect a direct message with names
77+
def test_query_shows_widget_metadata_and_parameters():
7778
test_payload_path = (
7879
Path(__file__).parent.parent.parent
7980
/ "testing"
8081
/ "test_payloads"
8182
/ "retrieve_widget_from_dashboard.json"
8283
)
8384
payload = json.load(open(test_payload_path))
84-
payload["widgets"]["primary"] = []
85-
payload["messages"][0]["content"] = "What widgets are available in the dashboard?"
85+
payload["messages"][0]["content"] = "Show me widget details"
8686

8787
response = test_client.post("/v1/query", json=payload)
8888
assert response.status_code == 200
8989

90-
CopilotResponse(response.text).has_any("copilotMessage", "Company News")
90+
# Should show widget metadata fields
91+
CopilotResponse(response.text).has_any("copilotMessage", "Description")
92+
CopilotResponse(response.text).has_any("copilotMessage", "UUID")
93+
# Should show parameters table
94+
CopilotResponse(response.text).has_any("copilotMessage", "Parameters")
95+
96+
97+
def test_query_does_not_fetch_widget_data():
98+
"""Test that the agent only lists widgets and does not fetch data"""
99+
test_payload_path = (
100+
Path(__file__).parent.parent.parent
101+
/ "testing"
102+
/ "test_payloads"
103+
/ "retrieve_widget_from_dashboard.json"
104+
)
105+
payload = json.load(open(test_payload_path))
106+
payload["messages"][0]["content"] = "Hello"
107+
108+
response = test_client.post("/v1/query", json=payload)
109+
assert response.status_code == 200
110+
111+
# Should NOT have any function calls for get_widget_data
112+
response_text = response.text
113+
assert "get_widget_data" not in response_text
114+
assert "copilotFunctionCall" not in response_text
115+
116+
# Should only have messages listing widgets
117+
CopilotResponse(response.text).has_any("copilotMessage")

0 commit comments

Comments
 (0)