From 12d93a1212c437a627ff23eb68b1602a7cf5a60d Mon Sep 17 00:00:00 2001 From: James Riehl Date: Tue, 22 Apr 2025 12:38:23 +0100 Subject: [PATCH 1/2] fix: access control lists --- .../.avctl/config.toml | 0 .../.secrets.template | 0 .../README.md | 0 .../agent.py | 6 +- .../ai.py | 0 .../chat_proto.py | 0 .../pyproject.toml | 0 .../google-gemini-agent/agent.py | 9 ++- .../knowledge-base/openai-agent/agent.py | 6 +- .../utility/post-extractor-agent/agent.py | 67 ++----------------- 10 files changed, 21 insertions(+), 67 deletions(-) rename 6-deployed-agents/knowledge-base/{claude.ai-agent => claude-ai-agent}/.avctl/config.toml (100%) rename 6-deployed-agents/knowledge-base/{claude.ai-agent => claude-ai-agent}/.secrets.template (100%) rename 6-deployed-agents/knowledge-base/{claude.ai-agent => claude-ai-agent}/README.md (100%) rename 6-deployed-agents/knowledge-base/{claude.ai-agent => claude-ai-agent}/agent.py (98%) rename 6-deployed-agents/knowledge-base/{claude.ai-agent => claude-ai-agent}/ai.py (100%) rename 6-deployed-agents/knowledge-base/{claude.ai-agent => claude-ai-agent}/chat_proto.py (100%) rename 6-deployed-agents/knowledge-base/{claude.ai-agent => claude-ai-agent}/pyproject.toml (100%) diff --git a/6-deployed-agents/knowledge-base/claude.ai-agent/.avctl/config.toml b/6-deployed-agents/knowledge-base/claude-ai-agent/.avctl/config.toml similarity index 100% rename from 6-deployed-agents/knowledge-base/claude.ai-agent/.avctl/config.toml rename to 6-deployed-agents/knowledge-base/claude-ai-agent/.avctl/config.toml diff --git a/6-deployed-agents/knowledge-base/claude.ai-agent/.secrets.template b/6-deployed-agents/knowledge-base/claude-ai-agent/.secrets.template similarity index 100% rename from 6-deployed-agents/knowledge-base/claude.ai-agent/.secrets.template rename to 6-deployed-agents/knowledge-base/claude-ai-agent/.secrets.template diff --git a/6-deployed-agents/knowledge-base/claude.ai-agent/README.md b/6-deployed-agents/knowledge-base/claude-ai-agent/README.md similarity index 100% rename from 6-deployed-agents/knowledge-base/claude.ai-agent/README.md rename to 6-deployed-agents/knowledge-base/claude-ai-agent/README.md diff --git a/6-deployed-agents/knowledge-base/claude.ai-agent/agent.py b/6-deployed-agents/knowledge-base/claude-ai-agent/agent.py similarity index 98% rename from 6-deployed-agents/knowledge-base/claude.ai-agent/agent.py rename to 6-deployed-agents/knowledge-base/claude-ai-agent/agent.py index 6cc03ea..0de9c48 100644 --- a/6-deployed-agents/knowledge-base/claude.ai-agent/agent.py +++ b/6-deployed-agents/knowledge-base/claude-ai-agent/agent.py @@ -49,14 +49,16 @@ class StructuredOutputResponse(Model): storage_reference=agent.storage, name="LLM-Text-Response", version="0.1.0", - default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6, acl=acl), + default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6), + default_acl=acl, ) struct_proto = QuotaProtocol( storage_reference=agent.storage, name="LLM-Structured-Response", version="0.1.0", - default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6, acl=acl), + default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6), + default_acl=acl, ) diff --git a/6-deployed-agents/knowledge-base/claude.ai-agent/ai.py b/6-deployed-agents/knowledge-base/claude-ai-agent/ai.py similarity index 100% rename from 6-deployed-agents/knowledge-base/claude.ai-agent/ai.py rename to 6-deployed-agents/knowledge-base/claude-ai-agent/ai.py diff --git a/6-deployed-agents/knowledge-base/claude.ai-agent/chat_proto.py b/6-deployed-agents/knowledge-base/claude-ai-agent/chat_proto.py similarity index 100% rename from 6-deployed-agents/knowledge-base/claude.ai-agent/chat_proto.py rename to 6-deployed-agents/knowledge-base/claude-ai-agent/chat_proto.py diff --git a/6-deployed-agents/knowledge-base/claude.ai-agent/pyproject.toml b/6-deployed-agents/knowledge-base/claude-ai-agent/pyproject.toml similarity index 100% rename from 6-deployed-agents/knowledge-base/claude.ai-agent/pyproject.toml rename to 6-deployed-agents/knowledge-base/claude-ai-agent/pyproject.toml diff --git a/6-deployed-agents/knowledge-base/google-gemini-agent/agent.py b/6-deployed-agents/knowledge-base/google-gemini-agent/agent.py index 1530a37..84ea1b4 100644 --- a/6-deployed-agents/knowledge-base/google-gemini-agent/agent.py +++ b/6-deployed-agents/knowledge-base/google-gemini-agent/agent.py @@ -56,21 +56,24 @@ class StructuredOutputResponse(Model): storage_reference=agent.storage, name="LLM-Text-Response", version="0.1.0", - default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6), acl=acl, + default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6), + default_acl=acl, ) code_proto = QuotaProtocol( storage_reference=agent.storage, name="LLM-Code-Generator", version="0.1.0", - default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6), acl=acl, + default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6), + default_acl=acl, ) struct_proto = QuotaProtocol( storage_reference=agent.storage, name="LLM-Structured-Response", version="0.1.0", - default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6), acl=acl, + default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6), + default_acl=acl, ) diff --git a/6-deployed-agents/knowledge-base/openai-agent/agent.py b/6-deployed-agents/knowledge-base/openai-agent/agent.py index 9300e00..b4b8339 100644 --- a/6-deployed-agents/knowledge-base/openai-agent/agent.py +++ b/6-deployed-agents/knowledge-base/openai-agent/agent.py @@ -48,14 +48,16 @@ class StructuredOutputResponse(Model): storage_reference=agent.storage, name="LLM-Context-Response", version="0.1.0", - default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6, acl=acl), + default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6), + default_acl=acl, ) struct_proto = QuotaProtocol( storage_reference=agent.storage, name="LLM-Structured-Response", version="0.1.0", - default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6, acl=acl), + default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6), + default_acl=acl, ) diff --git a/6-deployed-agents/utility/post-extractor-agent/agent.py b/6-deployed-agents/utility/post-extractor-agent/agent.py index 0ec800b..430f7b4 100644 --- a/6-deployed-agents/utility/post-extractor-agent/agent.py +++ b/6-deployed-agents/utility/post-extractor-agent/agent.py @@ -1,9 +1,7 @@ import os import requests from datetime import datetime -from enum import Enum from uagents import Agent, Context, Model, Protocol -from uagents.experimental.quota import QuotaProtocol, RateLimit class RedditPostsRequest(Model): limit: int @@ -20,27 +18,22 @@ class RedditPostsResponse(Model): posts: list[RedditPost] -AGENT_NAME = "Post Extractor Agent" AGENT_SEED = os.getenv("AGENT_SEED", "your-post-agent-seed") -REDDIT_ID = os.getenv("REDDIT_ID_KEY") -REDDIT_SECRET = os.getenv("REDDIT_SECRET_KEY") -REDDIT_USER = os.getenv("REDDIT_USER_KEY") +REDDIT_ID = os.getenv("REDDIT_ID") +REDDIT_SECRET = os.getenv("REDDIT_SECRET") +REDDIT_USER = os.getenv("REDDIT_USER") PORT = 8000 agent = Agent( - name=AGENT_NAME, + name="Post Extractor Agent", seed=AGENT_SEED, port=PORT, endpoint=f"http://localhost:{PORT}/submit", ) -proto = QuotaProtocol( - storage_reference=agent.storage, - name="Post-Extractor", - version="0.1.0", - default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6), -) +proto = Protocol(name="Post-Extractor", version="0.1.0") + auth = requests.auth.HTTPBasicAuth(REDDIT_ID, REDDIT_SECRET) data = { @@ -100,51 +93,5 @@ async def handle_request(ctx: Context, sender: str, msg: RedditPostsRequest): agent.include(proto) -### Health check related code -def agent_is_healthy() -> bool: - """ - Implement the actual health check logic here. - - For example, check if the agent can connect to a third party API, - check if the agent has enough resources, etc. - """ - condition = True # TODO: logic here - return bool(condition) - - -class HealthCheck(Model): - pass - - -class HealthStatus(str, Enum): - HEALTHY = "healthy" - UNHEALTHY = "unhealthy" - - -class AgentHealth(Model): - agent_name: str - status: HealthStatus - - -health_protocol = QuotaProtocol( - storage_reference=agent.storage, name="HealthProtocol", version="0.1.0" -) - - -@health_protocol.on_message(HealthCheck, replies={AgentHealth}) -async def handle_health_check(ctx: Context, sender: str, msg: HealthCheck): - status = HealthStatus.UNHEALTHY - try: - if agent_is_healthy(): - status = HealthStatus.HEALTHY - except Exception as err: - ctx.logger.error(err) - finally: - await ctx.send(sender, AgentHealth(agent_name=AGENT_NAME, status=status)) - - -agent.include(health_protocol, publish_manifest=True) - - if __name__ == "__main__": - agent.run() + agent.run() \ No newline at end of file From 09eb912dfac072851769f814d7d993e99ab70c31 Mon Sep 17 00:00:00 2001 From: James Riehl Date: Tue, 22 Apr 2025 12:40:55 +0100 Subject: [PATCH 2/2] chore: revert post extractor changes --- .../utility/post-extractor-agent/agent.py | 67 +++++++++++++++++-- 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/6-deployed-agents/utility/post-extractor-agent/agent.py b/6-deployed-agents/utility/post-extractor-agent/agent.py index 430f7b4..0ec800b 100644 --- a/6-deployed-agents/utility/post-extractor-agent/agent.py +++ b/6-deployed-agents/utility/post-extractor-agent/agent.py @@ -1,7 +1,9 @@ import os import requests from datetime import datetime +from enum import Enum from uagents import Agent, Context, Model, Protocol +from uagents.experimental.quota import QuotaProtocol, RateLimit class RedditPostsRequest(Model): limit: int @@ -18,22 +20,27 @@ class RedditPostsResponse(Model): posts: list[RedditPost] +AGENT_NAME = "Post Extractor Agent" AGENT_SEED = os.getenv("AGENT_SEED", "your-post-agent-seed") -REDDIT_ID = os.getenv("REDDIT_ID") -REDDIT_SECRET = os.getenv("REDDIT_SECRET") -REDDIT_USER = os.getenv("REDDIT_USER") +REDDIT_ID = os.getenv("REDDIT_ID_KEY") +REDDIT_SECRET = os.getenv("REDDIT_SECRET_KEY") +REDDIT_USER = os.getenv("REDDIT_USER_KEY") PORT = 8000 agent = Agent( - name="Post Extractor Agent", + name=AGENT_NAME, seed=AGENT_SEED, port=PORT, endpoint=f"http://localhost:{PORT}/submit", ) -proto = Protocol(name="Post-Extractor", version="0.1.0") - +proto = QuotaProtocol( + storage_reference=agent.storage, + name="Post-Extractor", + version="0.1.0", + default_rate_limit=RateLimit(window_size_minutes=60, max_requests=6), +) auth = requests.auth.HTTPBasicAuth(REDDIT_ID, REDDIT_SECRET) data = { @@ -93,5 +100,51 @@ async def handle_request(ctx: Context, sender: str, msg: RedditPostsRequest): agent.include(proto) +### Health check related code +def agent_is_healthy() -> bool: + """ + Implement the actual health check logic here. + + For example, check if the agent can connect to a third party API, + check if the agent has enough resources, etc. + """ + condition = True # TODO: logic here + return bool(condition) + + +class HealthCheck(Model): + pass + + +class HealthStatus(str, Enum): + HEALTHY = "healthy" + UNHEALTHY = "unhealthy" + + +class AgentHealth(Model): + agent_name: str + status: HealthStatus + + +health_protocol = QuotaProtocol( + storage_reference=agent.storage, name="HealthProtocol", version="0.1.0" +) + + +@health_protocol.on_message(HealthCheck, replies={AgentHealth}) +async def handle_health_check(ctx: Context, sender: str, msg: HealthCheck): + status = HealthStatus.UNHEALTHY + try: + if agent_is_healthy(): + status = HealthStatus.HEALTHY + except Exception as err: + ctx.logger.error(err) + finally: + await ctx.send(sender, AgentHealth(agent_name=AGENT_NAME, status=status)) + + +agent.include(health_protocol, publish_manifest=True) + + if __name__ == "__main__": - agent.run() \ No newline at end of file + agent.run()