Skip to content

Commit 6bc01f2

Browse files
authored
Refactoring examples so that journey is "clear" (#60)
* hard cuts and refactor * numbering * minor reorder
1 parent 2f69665 commit 6bc01f2

File tree

523 files changed

+91
-3937
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

523 files changed

+91
-3937
lines changed
File renamed without changes.
File renamed without changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import random
2+
from uagents import Agent, Bureau, Context, Model
3+
4+
# Define telemetry model
5+
class Telemetry(Model):
6+
temperature: float
7+
vibration: float
8+
9+
# Define response model
10+
class RepairResponse(Model):
11+
status: str
12+
13+
agent = Agent(name="machinery",
14+
seed="machinery seed phrase 09dkkefneff_93",
15+
port=8000,
16+
endpoint=["http://localhost:8000/submit"])
17+
18+
19+
# Machinery Agent (Sends telemetry data)
20+
@agent.on_interval(period=20.0) # Sends telemetry every 20 seconds
21+
async def send_telemetry(ctx: Context):
22+
telemetry = Telemetry(
23+
temperature=random.uniform(20, 100),
24+
vibration=random.uniform(0, 10)
25+
)
26+
await ctx.send('agent1qvk2ppctpjjj7ev6afdze3raup304pz7sc77sf6fk7h7n4uuexktx3t0der', telemetry)
27+
ctx.logger.info(f"Sent Telemetry: {telemetry}")
28+
29+
@agent.on_message(model=RepairResponse)
30+
async def handle_repair(ctx: Context, sender: str, msg: RepairResponse):
31+
ctx.logger.info(f"Received repair info from {sender}: {msg.dict()}")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import random
2+
from uagents import Agent, Bureau, Context, Model
3+
4+
# Define telemetry model
5+
class Telemetry(Model):
6+
temperature: float
7+
vibration: float
8+
9+
# Define repair request model
10+
class RepairRequest(Model):
11+
issue: str
12+
value: float
13+
14+
agent = Agent(name="monitor",
15+
seed="monitor seed phrase piwefgp99_iwefpie",
16+
port=8001,
17+
endpoint=["http://localhost:8001/submit"])
18+
19+
# Monitor Agent (Applies threshold rules to check anomalies)
20+
@agent.on_message(model=Telemetry)
21+
async def analyze_telemetry(ctx: Context, sender: str, msg: Telemetry):
22+
ctx.logger.info(f"Received telemetry from {sender}: {msg}")
23+
if msg.temperature > 80:
24+
request = RepairRequest(issue="High Temperature", value=msg.temperature)
25+
await ctx.send('agent1qt5k53m7p3qt6kshx46g8jgg4drr8dczrgvkt5xuyl303scclmxuv4556sw', request)
26+
await ctx.send(sender, request) # Notify sender
27+
ctx.logger.info(f"High Temp! Sent repair request: {request} to 'agent1qt5k53m7p3qt6kshx46g8jgg4drr8dczrgvkt5xuyl303scclmxuv4556sw' and {sender}")
28+
elif msg.vibration > 7:
29+
request = RepairRequest(issue="High Vibration", value=msg.vibration)
30+
await ctx.send('agent1qt5k53m7p3qt6kshx46g8jgg4drr8dczrgvkt5xuyl303scclmxuv4556sw', request)
31+
await ctx.send(sender, request) # Notify sender
32+
ctx.logger.info(f"High Vibration! Sent repair request: {request} to 'agent1qt5k53m7p3qt6kshx46g8jgg4drr8dczrgvkt5xuyl303scclmxuv4556sw' and {sender}")
33+
else:
34+
ctx.logger.info("Telemetry Normal")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from uagents import Agent, Bureau, Context, Model
2+
3+
# Define response model
4+
class RepairResponse(Model):
5+
status: str
6+
7+
# Define repair request model
8+
class RepairRequest(Model):
9+
issue: str
10+
value: float
11+
12+
13+
14+
agent = Agent(name="repairer",
15+
seed="repairer seed phrase ouweufweif_838383",
16+
port=8002,
17+
endpoint=["http://localhost:8002/submit"])
18+
19+
# Repairer Agent (Handles repair requests)
20+
@agent.on_message(model=RepairRequest)
21+
async def handle_repair(ctx: Context, sender: str, msg: RepairRequest):
22+
ctx.logger.info(f"Received repair request from {sender}: {msg}")
23+
response = RepairResponse(status=f"Repair initiated for {msg.issue}")
24+
await ctx.send('agent1q0samncsypdkf5tp0kh7r2ep233vt79uerk50jlgxpnt3d5mhcw6ywjastg', response)
25+
ctx.logger.info(f"Sent repair response to 'agent1q0samncsypdkf5tp0kh7r2ep233vt79uerk50jlgxpnt3d5mhcw6ywjastg': {response}")

1-uagents/examples_existing/03-multiple-agents/main.py renamed to 1-uagents/04-bureau/main.py

File renamed without changes.

1-uagents/examples_new_format/agent-core/02-protocols/README.md renamed to 1-uagents/05-protocols/README.md

1-uagents/examples_existing/09-booking-protocol-demo/protocols/__init__.py renamed to 1-uagents/05-protocols/__init__.py

File renamed without changes.

1-uagents/examples_existing/10-cleaning-demo/protocols/__init__.py renamed to 1-uagents/05-protocols/alice/__init__.py

File renamed without changes.

1-uagents/examples_new_format/agent-core/02-protocols/alice/agent.py renamed to 1-uagents/05-protocols/alice/agent.py

File renamed without changes.

0 commit comments

Comments
 (0)