Skip to content

Commit 1329b40

Browse files
Fix quote style: Use single quotes to match project standard
Applied Ruff 0.13.3 formatting to correctly enforce single quote style as specified in .ruff.toml. This matches the coding standard used across all other Python samples in the repository. - Ruff 0.14.4 had a bug ignoring quote-style = "single" setting - Ruff 0.13.3 correctly respects the configuration - All files now use single quotes consistently
1 parent ae59cd8 commit 1329b40

File tree

4 files changed

+186
-160
lines changed

4 files changed

+186
-160
lines changed

samples/python/agents/helloworld_with_ratelimiter/__main__.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from ratelimiter_ext import RateLimitingExtension, TokenBucketLimiter
1515

1616

17-
if __name__ == "__main__":
17+
if __name__ == '__main__':
1818
# Initialize rate limiter for enforcement (always active)
1919
# Token bucket allows burst traffic up to 20 requests (10 * 2.0 multiplier)
2020
# then maintains steady 10 requests per minute
@@ -25,31 +25,31 @@
2525
rate_limit_extension = RateLimitingExtension()
2626
# --8<-- [start:AgentSkill]
2727
skill = AgentSkill(
28-
id="hello_world",
29-
name="Returns hello world",
30-
description="just returns hello world",
31-
tags=["hello world"],
32-
examples=["hi", "hello world"],
28+
id='hello_world',
29+
name='Returns hello world',
30+
description='just returns hello world',
31+
tags=['hello world'],
32+
examples=['hi', 'hello world'],
3333
)
3434
# --8<-- [end:AgentSkill]
3535

3636
extended_skill = AgentSkill(
37-
id="super_hello_world",
38-
name="Returns a SUPER Hello World",
39-
description="A more enthusiastic greeting, only for authenticated users.",
40-
tags=["hello world", "super", "extended"],
41-
examples=["super hi", "give me a super hello"],
37+
id='super_hello_world',
38+
name='Returns a SUPER Hello World',
39+
description='A more enthusiastic greeting, only for authenticated users.',
40+
tags=['hello world', 'super', 'extended'],
41+
examples=['super hi', 'give me a super hello'],
4242
)
4343

4444
# --8<-- [start:AgentCard]
4545
# This will be the public-facing agent card
4646
public_agent_card = AgentCard(
47-
name="Hello World Agent with Rate Limiting",
48-
description="Hello world agent demonstrating A2A rate limiting extension",
49-
url="http://localhost:9999/",
50-
version="1.0.0",
51-
default_input_modes=["text"],
52-
default_output_modes=["text"],
47+
name='Hello World Agent with Rate Limiting',
48+
description='Hello world agent demonstrating A2A rate limiting extension',
49+
url='http://localhost:9999/',
50+
version='1.0.0',
51+
default_input_modes=['text'],
52+
default_output_modes=['text'],
5353
capabilities=AgentCapabilities(streaming=True),
5454
skills=[skill], # Only the basic skill for the public card
5555
supports_authenticated_extended_card=True,
@@ -60,13 +60,13 @@
6060
# It includes the additional 'extended_skill'
6161
specific_extended_agent_card = public_agent_card.model_copy(
6262
update={
63-
"name": "Hello World Agent with Rate Limiting - Extended Edition", # Different name for clarity
64-
"description": "The full-featured rate-limited hello world agent for authenticated users.",
65-
"version": "1.0.1", # Could even be a different version
63+
'name': 'Hello World Agent with Rate Limiting - Extended Edition', # Different name for clarity
64+
'description': 'The full-featured rate-limited hello world agent for authenticated users.',
65+
'version': '1.0.1', # Could even be a different version
6666
# Capabilities and other fields like url, default_input_modes,
6767
# default_output_modes, supports_authenticated_extended_card
6868
# are inherited from public_agent_card unless specified here.
69-
"skills": [
69+
'skills': [
7070
skill,
7171
extended_skill,
7272
], # Both skills for the extended card
@@ -98,4 +98,4 @@
9898
)
9999

100100
# Bind to 0.0.0.0 to allow external connections in containerized environment
101-
uvicorn.run(server.build(), host="0.0.0.0", port=9999) # noqa: S104
101+
uvicorn.run(server.build(), host='0.0.0.0', port=9999) # noqa: S104

samples/python/agents/helloworld_with_ratelimiter/agent_executor.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class HelloWorldAgent:
1010

1111
async def invoke(self) -> str:
1212
"""Invoke the agent to return a greeting."""
13-
return "Hello World"
13+
return 'Hello World'
1414

1515

1616
# --8<-- [end:HelloWorldAgent]
@@ -57,8 +57,8 @@ def _extract_client_key(self, context: RequestContext) -> str:
5757
Returns:
5858
Unique key for rate limiting this client
5959
"""
60-
remote_addr = getattr(context, "remote_addr", "unknown")
61-
return f"ip:{remote_addr}"
60+
remote_addr = getattr(context, 'remote_addr', 'unknown')
61+
return f'ip:{remote_addr}'
6262

6363
# --8<-- [start:HelloWorldAgentExecutor_execute]
6464
async def execute(
@@ -83,13 +83,15 @@ async def execute(
8383

8484
# Step 2: ALWAYS check rate limits (enforcement)
8585
# Rate limit: 10 requests per minute
86-
usage = self.rate_limiter.check_limit(key=client_key, limit=10, window=60)
86+
usage = self.rate_limiter.check_limit(
87+
key=client_key, limit=10, window=60
88+
)
8789

8890
# Step 3: If rate limited, return error
8991
if not usage.allowed:
9092
error_msg = (
91-
f"Rate limit exceeded. {usage.remaining} requests remaining. "
92-
f"Retry after {usage.retry_after:.1f} seconds."
93+
f'Rate limit exceeded. {usage.remaining} requests remaining. '
94+
f'Retry after {usage.retry_after:.1f} seconds.'
9395
)
9496
message = new_agent_text_message(error_msg)
9597

@@ -113,9 +115,11 @@ async def execute(
113115
# --8<-- [end:HelloWorldAgentExecutor_execute]
114116

115117
# --8<-- [start:HelloWorldAgentExecutor_cancel]
116-
async def cancel(self, context: RequestContext, event_queue: EventQueue) -> None:
118+
async def cancel(
119+
self, context: RequestContext, event_queue: EventQueue
120+
) -> None:
117121
"""Cancel the agent execution (not supported)."""
118-
msg = "cancel not supported"
122+
msg = 'cancel not supported'
119123
raise NotImplementedError(msg)
120124

121125
# --8<-- [end:HelloWorldAgentExecutor_cancel]

0 commit comments

Comments
 (0)