11import os
22import requests
3+ from enum import Enum
34from datetime import datetime
45from uagents import Agent , Context , Model , Protocol
56from uagents .experimental .chat_agent import ChatAgent
7+ from uagents .experimental .quota import QuotaProtocol , RateLimit
68
79class RedditPostsRequest (Model ):
810 limit : int
@@ -20,6 +22,7 @@ class RedditPostsResponse(Model):
2022
2123
2224AGENT_SEED = os .getenv ("AGENT_SEED" , "your-post-agent-seed" )
25+ AGENT_NAME = os .getenv ("AGENT_NAME" , "Post Extractor Agent" )
2326REDDIT_ID = os .getenv ("REDDIT_ID" )
2427REDDIT_SECRET = os .getenv ("REDDIT_SECRET" )
2528REDDIT_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
9597agent .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+
97129if __name__ == "__main__" :
98130 agent .run ()
0 commit comments