Skip to content

Commit 7f6623a

Browse files
fix: add health protocol to missing agents (#87)
* fix: add health protocol to missing agents * minor fixes
1 parent 07dd6c6 commit 7f6623a

3 files changed

Lines changed: 98 additions & 2 deletions

File tree

6-deployed-agents/chained/blog-creator-agent/agent.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
2-
from uagents import Agent, Context
2+
from enum import Enum
3+
from uagents import Agent, Context, Model
34
from uagents.experimental.chat_agent import ChatAgent
45
from uagents.experimental.quota import QuotaProtocol, RateLimit
56
from models import (
@@ -12,6 +13,7 @@
1213
)
1314

1415
AGENT_SEED = os.getenv("AGENT_SEED", "your-blog-agent-seed")
16+
AGENT_NAME = os.getenv("AGENT_NAME", "Blog Agent")
1517
TOPIC_AGENT_ADDRESS = os.getenv("topic-agent-address")
1618
AI_AGENT_ADDRESS = os.getenv("ai-agent-address")
1719

@@ -87,5 +89,35 @@ async def handle_request(ctx: Context, sender: str, msg: BlogRequest):
8789

8890
agent.include(proto)
8991

92+
93+
# Health Check code
94+
class HealthCheck(Model):
95+
pass
96+
97+
98+
class HealthStatus(str, Enum):
99+
HEALTHY = "healthy"
100+
UNHEALTHY = "unhealthy"
101+
102+
103+
class AgentHealth(Model):
104+
agent_name: str
105+
status: HealthStatus
106+
107+
108+
health_protocol = QuotaProtocol(
109+
storage_reference=agent.storage, name="HealthProtocol", version="0.1.0"
110+
)
111+
112+
113+
@health_protocol.on_message(HealthCheck, replies={AgentHealth})
114+
async def handle_health_check(ctx: Context, sender: str, msg: HealthCheck):
115+
await ctx.send(
116+
sender, AgentHealth(agent_name=AGENT_NAME, status=HealthStatus.HEALTHY)
117+
)
118+
119+
120+
agent.include(health_protocol, publish_manifest=True)
121+
90122
if __name__ == "__main__":
91123
agent.run()

6-deployed-agents/chained/topic-extractor-agent/agent.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from enum import Enum
23
from uagents import Agent, Context, Model
34
from uagents.experimental.chat_agent import ChatAgent
45
from uagents.experimental.quota import QuotaProtocol, RateLimit
@@ -12,6 +13,7 @@
1213
)
1314

1415
AGENT_SEED = os.getenv("AGENT_SEED", "your-topic-agent-seed")
16+
AGENT_NAME = os.getenv("AGENT_NAME", "Topic Agent")
1517
POSTS_AGENT_ADDRESS = os.getenv("posts-agent-address")
1618
OPEN_AI_AGENT_ADDRESS = os.getenv("openai-agent-address")
1719

@@ -81,5 +83,35 @@ async def handle_request(ctx: Context, sender: str, msg: TopicAnalysisRequest):
8183

8284
agent.include(proto)
8385

86+
87+
# Health Check code
88+
class HealthCheck(Model):
89+
pass
90+
91+
92+
class HealthStatus(str, Enum):
93+
HEALTHY = "healthy"
94+
UNHEALTHY = "unhealthy"
95+
96+
97+
class AgentHealth(Model):
98+
agent_name: str
99+
status: HealthStatus
100+
101+
102+
health_protocol = QuotaProtocol(
103+
storage_reference=agent.storage, name="HealthProtocol", version="0.1.0"
104+
)
105+
106+
107+
@health_protocol.on_message(HealthCheck, replies={AgentHealth})
108+
async def handle_health_check(ctx: Context, sender: str, msg: HealthCheck):
109+
await ctx.send(
110+
sender, AgentHealth(agent_name=AGENT_NAME, status=HealthStatus.HEALTHY)
111+
)
112+
113+
114+
agent.include(health_protocol, publish_manifest=True)
115+
84116
if __name__ == "__main__":
85117
agent.run()

6-deployed-agents/utility/post-extractor-agent/agent.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
22
import requests
3+
from enum import Enum
34
from datetime import datetime
45
from uagents import Agent, Context, Model, Protocol
56
from uagents.experimental.chat_agent import ChatAgent
7+
from uagents.experimental.quota import QuotaProtocol, RateLimit
68

79
class RedditPostsRequest(Model):
810
limit: int
@@ -20,6 +22,7 @@ class RedditPostsResponse(Model):
2022

2123

2224
AGENT_SEED = os.getenv("AGENT_SEED", "your-post-agent-seed")
25+
AGENT_NAME = os.getenv("AGENT_NAME", "Post Extractor Agent")
2326
REDDIT_ID = os.getenv("REDDIT_ID")
2427
REDDIT_SECRET = os.getenv("REDDIT_SECRET")
2528
REDDIT_USER = os.getenv("REDDIT_USER")
@@ -76,7 +79,6 @@ async def handle_request(ctx: Context, sender: str, msg: RedditPostsRequest):
7679
title=post_data["title"],
7780
author=post_data["author"],
7881
url=post_data["url"],
79-
created=datetime.fromtimestamp(post_data["created_utc"]).isoformat(),
8082
content=post_data["selftext"] if post_data["selftext"] else "[No text content]",
8183
)
8284

@@ -94,5 +96,35 @@ async def handle_request(ctx: Context, sender: str, msg: RedditPostsRequest):
9496

9597
agent.include(proto)
9698

99+
100+
# Health Check code
101+
class HealthCheck(Model):
102+
pass
103+
104+
105+
class HealthStatus(str, Enum):
106+
HEALTHY = "healthy"
107+
UNHEALTHY = "unhealthy"
108+
109+
110+
class AgentHealth(Model):
111+
agent_name: str
112+
status: HealthStatus
113+
114+
115+
health_protocol = QuotaProtocol(
116+
storage_reference=agent.storage, name="HealthProtocol", version="0.1.0"
117+
)
118+
119+
120+
@health_protocol.on_message(HealthCheck, replies={AgentHealth})
121+
async def handle_health_check(ctx: Context, sender: str, msg: HealthCheck):
122+
await ctx.send(
123+
sender, AgentHealth(agent_name=AGENT_NAME, status=HealthStatus.HEALTHY)
124+
)
125+
126+
127+
agent.include(health_protocol, publish_manifest=True)
128+
97129
if __name__ == "__main__":
98130
agent.run()

0 commit comments

Comments
 (0)