Skip to content

Commit 7e0241b

Browse files
authored
Merge pull request #15 from volcengine/sytle/pre-commit-ruff-reformat
style: ruff/pre-commit reformat code style
2 parents 905aef5 + 6c9432c commit 7e0241b

File tree

102 files changed

+7720
-5064
lines changed

Some content is hidden

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

102 files changed

+7720
-5064
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ repos:
77
- id: ruff-check
88
types_or: [ python, pyi ]
99
args: [ --fix ]
10+
exclude: ^agentkit/toolkit/resources/samples/
1011
# Run the formatter.
1112
- id: ruff-format
1213
types_or: [ python, pyi ]
14+
exclude: ^agentkit/toolkit/resources/samples/
1315
- repo: https://github.com/gitleaks/gitleaks
1416
rev: v8.24.2
1517
hooks:
16-
- id: gitleaks
18+
- id: gitleaks

agentkit/apps/a2a_app/telemetry.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
logger = logging.getLogger("agentkit." + __name__)
4848

49+
4950
class Telemetry:
5051
def __init__(self):
5152
self.tracer = get_tracer("agentkit.a2a_app")
@@ -57,7 +58,6 @@ def __init__(self):
5758
explicit_bucket_boundaries_advisory=_GEN_AI_CLIENT_OPERATION_DURATION_BUCKETS,
5859
)
5960

60-
6161
def trace_a2a_agent(
6262
self,
6363
func: Callable,
@@ -69,7 +69,9 @@ def trace_a2a_agent(
6969
"""Get current span and set required attributes."""
7070
trace_id = span.get_span_context().trace_id
7171
span_id = span.get_span_context().span_id
72-
logger.debug(f"Set attributes for span with trace_id={trace_id}, span_id={span_id}")
72+
logger.debug(
73+
f"Set attributes for span with trace_id={trace_id}, span_id={span_id}"
74+
)
7375

7476
# ===============================
7577
# Set attributes for current span
@@ -87,12 +89,18 @@ def trace_a2a_agent(
8789
if user_id:
8890
span.set_attribute(key="gen_ai.user.id", value=user_id)
8991

90-
span.set_attribute(key="gen_ai.input", value=safe_serialize_to_json_string(request.message.parts))
92+
span.set_attribute(
93+
key="gen_ai.input",
94+
value=safe_serialize_to_json_string(request.message.parts),
95+
)
9196

9297
span.set_attribute(key="gen_ai.span.kind", value="a2a_agent")
9398
span.set_attribute(key="gen_ai.operation.name", value="invoke_agent")
9499
span.set_attribute(key="gen_ai.operation.type", value="a2a_agent")
95-
attributes={"gen_ai_operation_name": "invoke_agent", "gen_ai_operation_type": "a2a_agent"}
100+
attributes = {
101+
"gen_ai_operation_name": "invoke_agent",
102+
"gen_ai_operation_type": "a2a_agent",
103+
}
96104

97105
if exception:
98106
self.handle_exception(span, exception)
@@ -116,4 +124,3 @@ def handle_exception(span: trace.Span, exception: Exception) -> None:
116124

117125

118126
telemetry = Telemetry()
119-

agentkit/apps/mcp_app/telemetry.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
logger = logging.getLogger("agentkit." + __name__)
4646

47+
4748
class Telemetry:
4849
def __init__(self):
4950
self.tracer = get_tracer("agentkit.mcp_app")
@@ -56,20 +57,22 @@ def __init__(self):
5657
)
5758

5859
def trace_tool(
59-
self,
60-
func: Callable,
61-
span: Span,
62-
args: dict,
63-
func_result: any,
64-
operation_type: str,
65-
exception: Exception,
60+
self,
61+
func: Callable,
62+
span: Span,
63+
args: dict,
64+
func_result: any,
65+
operation_type: str,
66+
exception: Exception,
6667
) -> None:
6768
"""Get current span and set required attributes."""
6869

6970
trace_id = span.get_span_context().trace_id
7071
span_id = span.get_span_context().span_id
7172

72-
logger.debug(f"Set attributes for span with trace_id={trace_id}, span_id={span_id}")
73+
logger.debug(
74+
f"Set attributes for span with trace_id={trace_id}, span_id={span_id}"
75+
)
7376

7477
# ===============================
7578
# Set attributes for current span
@@ -79,14 +82,19 @@ def trace_tool(
7982

8083
span.set_attribute(key="gen_ai.func_name", value=func.__name__)
8184

82-
span.set_attribute(key="gen_ai.input", value=safe_serialize_to_json_string(args))
85+
span.set_attribute(
86+
key="gen_ai.input", value=safe_serialize_to_json_string(args)
87+
)
8388
safe_result = safe_serialize_to_json_string(func_result)
8489
span.set_attribute(key="gen_ai.output", value=safe_result)
8590

8691
span.set_attribute(key="gen_ai.span.kind", value="tool")
8792
span.set_attribute(key="gen_ai.operation.name", value="tool")
8893
span.set_attribute(key="gen_ai.operation.type", value=operation_type)
89-
attributes = {"gen_ai_operation_name": "tool", "gen_ai_operation_type": operation_type}
94+
attributes = {
95+
"gen_ai_operation_name": "tool",
96+
"gen_ai_operation_type": operation_type,
97+
}
9098

9199
if exception:
92100
self.handle_exception(span, exception)
@@ -110,4 +118,3 @@ def handle_exception(span: trace.Span, exception: Exception) -> None:
110118

111119

112120
telemetry = Telemetry()
113-

agentkit/apps/simple_app/simple_app_handlers.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,10 @@ async def handle(self, request: Request) -> Response | StreamingResponse:
7373

7474
logger.info("Returning non-streaming response")
7575
safe_json_string = safe_serialize_to_json_string(result)
76-
telemetry.trace_agent_finish(
77-
safe_json_string, None
78-
)
76+
telemetry.trace_agent_finish(safe_json_string, None)
7977
except Exception as e:
8078
logger.error("Invoke handler function failed: %s", e)
81-
telemetry.trace_agent_finish(
82-
"", e
83-
)
79+
telemetry.trace_agent_finish("", e)
8480
raise e
8581

8682
return Response(safe_json_string, media_type="application/json")
@@ -160,9 +156,7 @@ def _sync_stream_with_error_handling(self, generator):
160156
finally:
161157
# finish trace span and record metrics
162158
result = safe_serialize_to_json_string(last_value)
163-
telemetry.trace_agent_finish(
164-
result, exception
165-
)
159+
telemetry.trace_agent_finish(result, exception)
166160

167161
async def _stream_with_error_handling(self, generator):
168162
"""Wrap async generator to handle errors and convert to SSE format."""
@@ -184,9 +178,7 @@ async def _stream_with_error_handling(self, generator):
184178
finally:
185179
# finish trace span and record metrics
186180
result = safe_serialize_to_json_string(last_value)
187-
telemetry.trace_agent_finish(
188-
result, exception
189-
)
181+
telemetry.trace_agent_finish(result, exception)
190182

191183

192184
class PingHandler(BaseHandler):

agentkit/apps/simple_app/telemetry.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def trace_agent(
9292
trace_id = span.get_span_context().trace_id
9393
span_id = span.get_span_context().span_id
9494

95-
logger.debug(f"Set attributes for span with trace_id={trace_id}, span_id={span_id}")
95+
logger.debug(
96+
f"Set attributes for span with trace_id={trace_id}, span_id={span_id}"
97+
)
9698

9799
# ===============================
98100
# Set attributes for current span
@@ -112,7 +114,9 @@ def trace_agent(
112114
if user_id:
113115
span.set_attribute(key="gen_ai.user.id", value=user_id)
114116

115-
span.set_attribute(key="gen_ai.input", value=safe_serialize_to_json_string(payload))
117+
span.set_attribute(
118+
key="gen_ai.input", value=safe_serialize_to_json_string(payload)
119+
)
116120

117121
span.set_attribute(key="gen_ai.span.kind", value="workflow")
118122
span.set_attribute(key="gen_ai.operation.name", value="invoke_agent")
@@ -128,7 +132,10 @@ def trace_agent_finish(
128132

129133
if span and span.is_recording():
130134
span.set_attribute(key="gen_ai.output", value=func_result)
131-
attributes={"gen_ai_operation_name": "invoke_agent", "gen_ai_operation_type": "agent"}
135+
attributes = {
136+
"gen_ai_operation_name": "invoke_agent",
137+
"gen_ai_operation_type": "agent",
138+
}
132139
if exception:
133140
self.handle_exception(span, exception)
134141
attributes["error_type"] = exception.__class__.__name__

agentkit/client/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
from agentkit.client.base_iam_client import BaseIAMClient
2424

2525
__all__ = [
26-
'BaseServiceClient',
27-
'BaseAgentkitClient',
28-
'BaseIAMClient',
29-
'ApiConfig',
26+
"BaseServiceClient",
27+
"BaseAgentkitClient",
28+
"BaseIAMClient",
29+
"ApiConfig",
3030
]

agentkit/client/base_agentkit_client.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@
2727
class BaseAgentkitClient(BaseServiceClient):
2828
"""
2929
Base client for all AgentKit services.
30-
30+
3131
This class provides:
3232
1. Common credential initialization
3333
2. Unified API invocation logic with error handling
3434
3. Automatic ApiInfo generation with flexible configuration
35-
35+
3636
Subclasses should override API_ACTIONS with either:
3737
- Simple dict mapping: {"ActionName": "ActionName"}
3838
- Detailed ApiConfig: {"ActionName": ApiConfig(action="ActionName", method="GET", path="/custom")}
3939
"""
40-
40+
4141
# Subclasses should override this with their API action configurations
4242
API_ACTIONS: Dict[str, Union[str, ApiConfig]] = {}
43-
43+
4444
def __init__(
4545
self,
4646
access_key: str = "",
@@ -52,7 +52,7 @@ def __init__(
5252
) -> None:
5353
"""
5454
Initialize the AgentKit client.
55-
55+
5656
Args:
5757
access_key: Volcengine access key
5858
secret_key: Volcengine secret key
@@ -66,27 +66,27 @@ def __init__(
6666
region=region,
6767
session_token=session_token,
6868
service_name=service_name,
69-
credential_env_prefix='AGENTKIT',
69+
credential_env_prefix="AGENTKIT",
7070
header=header,
7171
)
72-
72+
7373
def _get_service_config(self) -> Dict[str, str]:
7474
"""
7575
Get AgentKit service configuration.
76-
76+
7777
Returns:
7878
Dictionary with host, api_version, and service
7979
"""
8080
host, api_version, service = get_volc_agentkit_host_info()
8181
gc = get_global_config()
82-
scheme = gc.agentkit_schema or 'https'
82+
scheme = gc.agentkit_schema or "https"
8383
return {
84-
'host': gc.agentkit_host or host,
85-
'api_version': api_version,
86-
'service': service,
87-
'scheme': scheme,
84+
"host": gc.agentkit_host or host,
85+
"api_version": api_version,
86+
"service": service,
87+
"scheme": scheme,
8888
}
89-
89+
9090
def _get(self, api_action: str, params: Dict[str, Any] = None) -> str:
9191
"""Legacy method for GET requests."""
9292
try:

agentkit/client/base_iam_client.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@
2626
class BaseIAMClient(BaseServiceClient):
2727
"""
2828
Base client for IAM services.
29-
29+
3030
This class provides the same interface as BaseAgentkitClient but for IAM services:
3131
1. Common credential initialization
3232
2. Unified API invocation logic with error handling
3333
3. Automatic ApiInfo generation with flexible configuration
34-
34+
3535
Subclasses should override API_ACTIONS with either:
3636
- Simple dict mapping: {"ActionName": "ActionName"}
3737
- Detailed ApiConfig: {"ActionName": ApiConfig(action="ActionName", method="GET", path="/custom")}
3838
"""
39-
39+
4040
# Subclasses should override this with their API action configurations
4141
API_ACTIONS: Dict[str, Union[str, ApiConfig]] = {}
42-
42+
4343
# IAM service specific configuration
4444
IAM_API_VERSION = "2018-01-01"
4545
IAM_SERVICE_CODE = "iam"
4646
IAM_HOST = "open.volcengineapi.com"
47-
47+
4848
def __init__(
4949
self,
5050
access_key: str = "",
@@ -55,7 +55,7 @@ def __init__(
5555
) -> None:
5656
"""
5757
Initialize the IAM client.
58-
58+
5959
Args:
6060
access_key: Volcengine access key
6161
secret_key: Volcengine secret key
@@ -69,22 +69,22 @@ def __init__(
6969
region=region,
7070
session_token=session_token,
7171
service_name=service_name,
72-
credential_env_prefix='IAM',
72+
credential_env_prefix="IAM",
7373
)
74-
74+
7575
def _get_service_config(self) -> Dict[str, str]:
7676
"""
7777
Get IAM service configuration.
78-
78+
7979
Returns:
8080
Dictionary with host, api_version, and service
8181
"""
8282
gc = get_global_config()
83-
scheme = gc.iam_schema or 'https'
83+
scheme = gc.iam_schema or "https"
8484
host = gc.iam_host or self.IAM_HOST
8585
return {
86-
'host': host,
87-
'api_version': self.IAM_API_VERSION,
88-
'service': self.IAM_SERVICE_CODE,
89-
'scheme': scheme,
86+
"host": host,
87+
"api_version": self.IAM_API_VERSION,
88+
"service": self.IAM_SERVICE_CODE,
89+
"scheme": scheme,
9090
}

0 commit comments

Comments
 (0)