-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path02_multi-agent_demo.py
More file actions
145 lines (112 loc) · 3.98 KB
/
Copy path02_multi-agent_demo.py
File metadata and controls
145 lines (112 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import streamlit as st
import asyncio
import nest_asyncio
from dotenv import load_dotenv
from agents import Agent, Runner, trace
nest_asyncio.apply()
load_dotenv(override=True)
# -------------------------------
# Streamlit Page Config
# -------------------------------
st.set_page_config(
page_title="Network Topic Explainer",
page_icon="🤖",
layout="wide"
)
st.title("🤖 Agentic Network Topic Explainer")
st.caption("Prompt Architect(Generates Prompt for the Content) → Network Expert(Generates Config Content)")
st.divider()
# -------------------------------
# Agent Definitions
# -------------------------------
prompt_architect_instruction = """
You are a Prompt Architect for network education.
Your task:
- The user gives a NETWORKING CONCEPT (example: VLAN)
- You must generate a CLEAR, STRUCTURED instruction
that another agent can use to generate content.
- Instruct to make short and concise markdown responses.
- make sure you are replacing <concept> with the NETWORKING CONCEPT
STRICT RULES:
- Do NOT generate the actual explanation or configs
- Only generate instructions / prompt text
- Stay strictly within computer networking topics
The output MUST include the following sections:
1. What is <concept>
2. Advantages of <concept>
3. Configuration Example 1 (Cisco CLI)
4. Configuration Example 2 (Cisco CLI)
5. Verification / Show Commands
Write the output as a FINAL PROMPT that can be directly
passed to another agent.
"""
net_expert_instruction = """
You are a senior network engineer.
You will be given a **networking topic name**.
Your expertise is STRICTLY LIMITED to:
- Computer networking concepts
- Switching and routing technologies
- VLANs and Layer 2 fundamentals
- Cisco IOS configuration and verification commands
Response Requirements:
- Generate the response ONLY in **Markdown format**
- Keep explanations technically accurate and concise
HARD RULE:
- If the given topic is NOT related to networking,
respond ONLY with:
"I don't know. I can only answer questions about computer networking."
"""
prompt_architect_agent = Agent(
name="Prompt Architect Agent",
instructions=prompt_architect_instruction,
model="gpt-5-nano",
)
network_expert_agent = Agent(
name="Network Expert Agent",
instructions=net_expert_instruction,
model="gpt-5-nano",
)
# -------------------------------
# User Input
# -------------------------------
concept = st.text_input(
"🔹 Enter a Networking Concept",
placeholder="Example: VLAN, OSPF, BGP"
)
run_button = st.button("🚀 Generate Content", use_container_width=True)
if run_button and concept:
col1, col2 = st.columns(2)
# ---------- Agent 1 UI ----------
with col1:
st.subheader("🧩 Agent-01: Prompt Architect ➡️")
agent1_status = st.empty()
agent1_output_box = st.empty()
# ---------- Agent 2 UI ----------
with col2:
st.subheader("📘 Agent-02: Network Expert")
agent2_status = st.empty()
agent2_output_box = st.empty()
async def run_agents():
with trace("Networking Tech Explainer - St"):
# ---- Agent 1 ----
agent1_status.info("⏳ Prompt Architect Agent running...")
agent1_result = await Runner.run(
prompt_architect_agent,
input=concept
)
agent1_status.success("✅ Prompt Architect Agent completed")
agent1_output_box.code(
agent1_result.final_output,
language="markdown"
)
# ---- Agent 2 ----
agent2_status.info("⏳ Network Expert Agent running...")
agent2_result = await Runner.run(
network_expert_agent,
input=agent1_result.final_output
)
agent2_status.success("✅ Network Expert completed")
agent2_output_box.markdown(agent2_result.final_output)
asyncio.run(run_agents())
elif run_button:
st.warning("⚠️ Please enter a networking concept.")