Skip to content

Commit ffb8566

Browse files
salmanapSalman Paracha
andauthored
updating the network agent to work agin (#425)
Co-authored-by: Salman Paracha <salmanparacha@MacBook-Pro-261.local>
1 parent e8dc7f1 commit ffb8566

File tree

4 files changed

+47
-45
lines changed

4 files changed

+47
-45
lines changed

demos/samples_python/network_switch_operator_agent/arch_config.yaml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ llm_providers:
1111
- name: OpenAI
1212
provider_interface: openai
1313
access_key: $OPENAI_API_KEY
14-
model: gpt-3.5-turbo
14+
model: gpt-4o
1515
default: true
1616

1717
# default system prompt used by all prompt targets
@@ -26,25 +26,26 @@ prompt_targets:
2626
path: /agent/device_summary
2727
http_method: POST
2828
parameters:
29-
- name: device_ids
30-
type: list
31-
description: A list of device identifiers (IDs) to retrieve statistics for.
29+
- name: device_id
30+
type: str
31+
description: A device identifier to retrieve statistics for.
3232
required: true # device_ids are required to get device statistics
3333
- name: days
3434
type: int
3535
description: The number of days for which to gather device statistics.
36-
default: "7"
37-
- name: reboot_devices
38-
description: Reboot a list of devices
36+
default: 7
37+
- name: reboot_device
38+
description: Reboot a device
3939
endpoint:
4040
name: app_server
4141
path: /agent/device_reboot
4242
http_method: POST
4343
parameters:
44-
- name: device_ids
45-
type: list
46-
description: A list of device identifiers (IDs).
44+
- name: device_id
45+
type: str
46+
description: the device identifier
4747
required: true
48+
system_prompt: You will get a status JSON object. Simply summarize it
4849

4950
# Arch creates a round-robin load balancing between different endpoints, managed via the cluster subsystem.
5051
endpoints:
@@ -55,3 +56,8 @@ endpoints:
5556
endpoint: host.docker.internal:18083
5657
# max time to wait for a connection to be established
5758
connect_timeout: 0.005s
59+
60+
61+
tracing:
62+
random_sampling: 100
63+
trace_arch_internal: true

demos/samples_python/network_switch_operator_agent/docker-compose.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ services:
1818
- "host.docker.internal:host-gateway"
1919
volumes:
2020
- ./arch_config.yaml:/app/arch_config.yaml
21+
22+
jaeger:
23+
build:
24+
context: ../../shared/jaeger
25+
ports:
26+
- "16686:16686"
27+
- "4317:4317"
28+
- "4318:4318"

demos/samples_python/network_switch_operator_agent/main.py

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313

1414
# Define the request model
1515
class DeviceSummaryRequest(BaseModel):
16-
device_ids: List[int]
16+
device_id: str
1717
time_range: Optional[int] = Field(
1818
default=7, description="Time range in days, defaults to 7"
1919
)
2020

2121

2222
# Define the response model
2323
class DeviceStatistics(BaseModel):
24-
device_id: int
24+
device_id: str
2525
time_range: str
2626
data: str
2727

@@ -33,7 +33,7 @@ class DeviceSummaryResponse(BaseModel):
3333

3434

3535
class DeviceRebootRequest(BaseModel):
36-
device_ids: List[int]
36+
device_id: str
3737

3838

3939
# Response model for the device reboot
@@ -49,24 +49,21 @@ def reboot_network_device(request_data: DeviceRebootRequest):
4949
"""
5050

5151
# Access data from the Pydantic model
52-
device_ids = request_data.device_ids
52+
device_id = request_data.device_id
5353

54-
# Validate 'device_ids'
54+
# Validate 'device_id'
5555
# (This is already validated by Pydantic, but additional logic can be added if needed)
56-
if not device_ids:
57-
raise HTTPException(
58-
status_code=400, detail="'device_ids' parameter is required"
59-
)
56+
if not device_id:
57+
raise HTTPException(status_code=400, detail="'device_id' parameter is required")
6058

6159
# Simulate reboot operation and return the response
6260
statistics = []
63-
for device_id in device_ids:
64-
# Placeholder for actual data retrieval or device reboot logic
65-
stats = {"data": f"Device {device_id} has been successfully rebooted."}
66-
statistics.append(stats)
61+
# Placeholder for actual data retrieval or device reboot logic
62+
stats = {"data": f"Device {device_id} has been successfully rebooted."}
63+
statistics.append(stats)
6764

6865
# Return the response with a summary
69-
return CoverageResponse(status="success", summary={"device_ids": device_ids})
66+
return CoverageResponse(status="success", summary={"device_id": device_id})
7067

7168

7269
# Post method for device summary
@@ -76,28 +73,20 @@ def get_device_summary(request: DeviceSummaryRequest):
7673
Endpoint to retrieve device statistics based on device IDs and an optional time range.
7774
"""
7875

79-
# Extract 'device_ids' and 'time_range' from the request
80-
device_ids = request.device_ids
76+
# Extract 'device_id' and 'time_range' from the request
77+
device_id = request.device_id
8178
time_range = request.time_range
8279

8380
# Simulate retrieving statistics for the given device IDs and time range
8481
statistics = []
85-
minutes = 1
86-
for device_id in device_ids:
87-
stats = {
88-
"device_id": device_id,
89-
"time_range": f"Last {time_range} days",
90-
"data": f"""Device {device_id} over the last {time_range} days experienced {minutes}
91-
minutes of downtime.""",
92-
}
93-
minutes += 1
94-
statistics.append(DeviceStatistics(**stats))
95-
96-
return DeviceSummaryResponse(statistics=statistics)
82+
minutes = 4
83+
stats = {
84+
"device_id": device_id,
85+
"time_range": f"Last {time_range} days",
86+
"data": f"""Device {device_id} over the last {time_range} days experienced {minutes}
87+
minutes of downtime.""",
88+
}
9789

90+
statistics.append(DeviceStatistics(**stats))
9891

99-
CHAT_COMPLETION_ENDPOINT = os.getenv("CHAT_COMPLETION_ENDPOINT")
100-
client = OpenAI(
101-
api_key="--",
102-
base_url=CHAT_COMPLETION_ENDPOINT,
103-
)
92+
return DeviceSummaryResponse(statistics=statistics)

demos/samples_python/network_switch_operator_agent/run_demo.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ start_demo() {
2222
echo "Starting Arch with arch_config.yaml..."
2323
archgw up arch_config.yaml
2424

25-
# Step 4: Start Network Agent
25+
# Step 4: Start developer services
2626
echo "Starting Network Agent using Docker Compose..."
27-
cd build
2827
docker compose up -d # Run in detached mode
2928
}
3029

0 commit comments

Comments
 (0)