kagent-adk 0.6.10__py3-none-any.whl → 0.6.11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of kagent-adk might be problematic. Click here for more details.
- kagent/adk/converters/error_mappings.py +60 -0
- kagent/adk/converters/event_converter.py +6 -3
- {kagent_adk-0.6.10.dist-info → kagent_adk-0.6.11.dist-info}/METADATA +1 -1
- {kagent_adk-0.6.10.dist-info → kagent_adk-0.6.11.dist-info}/RECORD +6 -5
- {kagent_adk-0.6.10.dist-info → kagent_adk-0.6.11.dist-info}/WHEEL +0 -0
- {kagent_adk-0.6.10.dist-info → kagent_adk-0.6.11.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Error code to user-friendly message mappings for ADK events.
|
|
2
|
+
|
|
3
|
+
This module provides mappings from Google GenAI finish reasons to user-friendly
|
|
4
|
+
error messages, excluding STOP which is a normal completion reason.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Dict, Optional
|
|
8
|
+
|
|
9
|
+
from google.genai import types as genai_types
|
|
10
|
+
|
|
11
|
+
# Error code to user-friendly message mappings
|
|
12
|
+
# Based on Google GenAI types.py FinishReason enum (excluding STOP)
|
|
13
|
+
ERROR_CODE_MESSAGES: Dict[str, str] = {
|
|
14
|
+
# Length and token limits
|
|
15
|
+
genai_types.FinishReason.MAX_TOKENS: "Response was truncated due to maximum token limit. Try asking a shorter question or breaking it into parts.",
|
|
16
|
+
# Safety and content filtering
|
|
17
|
+
genai_types.FinishReason.SAFETY: "Response was blocked due to safety concerns. Please rephrase your request to avoid potentially harmful content.",
|
|
18
|
+
genai_types.FinishReason.RECITATION: "Response was blocked due to unauthorized citations. Please rephrase your request.",
|
|
19
|
+
genai_types.FinishReason.BLOCKLIST: "Response was blocked due to restricted terminology. Please rephrase your request using different words.",
|
|
20
|
+
genai_types.FinishReason.PROHIBITED_CONTENT: "Response was blocked due to prohibited content. Please rephrase your request.",
|
|
21
|
+
genai_types.FinishReason.SPII: "Response was blocked due to sensitive personal information concerns. Please avoid including personal details.",
|
|
22
|
+
# Function calling errors
|
|
23
|
+
genai_types.FinishReason.MALFORMED_FUNCTION_CALL: "The agent generated an invalid function call. This may be due to complex input data. Try rephrasing your request or breaking it into simpler steps.",
|
|
24
|
+
# Generic fallback
|
|
25
|
+
genai_types.FinishReason.OTHER: "An unexpected error occurred during processing. Please try again or rephrase your request.",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
# Normal completion reasons that should not be treated as errors
|
|
29
|
+
NORMAL_COMPLETION_REASONS = {
|
|
30
|
+
genai_types.FinishReason.STOP, # Normal completion
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# Default error message when no specific mapping exists
|
|
34
|
+
DEFAULT_ERROR_MESSAGE = "An error occurred during processing"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _get_error_message(error_code: Optional[str]) -> str:
|
|
38
|
+
"""Get a user-friendly error message for the given error code.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
error_code: The error code from the ADK event (e.g., finish_reason)
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
User-friendly error message string
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
# Return mapped message or default
|
|
48
|
+
return ERROR_CODE_MESSAGES.get(error_code, DEFAULT_ERROR_MESSAGE)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _is_normal_completion(error_code: Optional[str]) -> bool:
|
|
52
|
+
"""Check if the error code represents normal completion rather than an error.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
error_code: The error code to check
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
True if this is a normal completion reason, False otherwise
|
|
59
|
+
"""
|
|
60
|
+
return error_code in NORMAL_COMPLETION_REASONS
|
|
@@ -20,6 +20,7 @@ from kagent.core.a2a import (
|
|
|
20
20
|
get_kagent_metadata_key,
|
|
21
21
|
)
|
|
22
22
|
|
|
23
|
+
from .error_mappings import _get_error_message, _is_normal_completion
|
|
23
24
|
from .part_converter import (
|
|
24
25
|
convert_genai_part_to_a2a_part,
|
|
25
26
|
)
|
|
@@ -27,7 +28,6 @@ from .part_converter import (
|
|
|
27
28
|
# Constants
|
|
28
29
|
|
|
29
30
|
ARTIFACT_ID_SEPARATOR = "-"
|
|
30
|
-
DEFAULT_ERROR_MESSAGE = "An error occurred during processing"
|
|
31
31
|
|
|
32
32
|
# Logger
|
|
33
33
|
logger = logging.getLogger("kagent_adk." + __name__)
|
|
@@ -191,13 +191,16 @@ def _create_error_status_event(
|
|
|
191
191
|
Returns:
|
|
192
192
|
A TaskStatusUpdateEvent with FAILED state.
|
|
193
193
|
"""
|
|
194
|
-
error_message = getattr(event, "error_message", None)
|
|
194
|
+
error_message = getattr(event, "error_message", None)
|
|
195
195
|
|
|
196
196
|
# Get context metadata and add error code
|
|
197
197
|
event_metadata = _get_context_metadata(event, invocation_context)
|
|
198
198
|
if event.error_code:
|
|
199
199
|
event_metadata[get_kagent_metadata_key("error_code")] = str(event.error_code)
|
|
200
200
|
|
|
201
|
+
if not error_message:
|
|
202
|
+
error_message = _get_error_message(event.error_code)
|
|
203
|
+
|
|
201
204
|
return TaskStatusUpdateEvent(
|
|
202
205
|
task_id=task_id,
|
|
203
206
|
context_id=context_id,
|
|
@@ -298,7 +301,7 @@ def convert_event_to_a2a_events(
|
|
|
298
301
|
|
|
299
302
|
try:
|
|
300
303
|
# Handle error scenarios
|
|
301
|
-
if event.error_code:
|
|
304
|
+
if event.error_code and not _is_normal_completion(event.error_code):
|
|
302
305
|
error_event = _create_error_status_event(event, invocation_context, task_id, context_id)
|
|
303
306
|
a2a_events.append(error_event)
|
|
304
307
|
|
|
@@ -6,12 +6,13 @@ kagent/adk/_token.py,sha256=OL46m7U5vUTby1WWjVB7Jqzig4TWddzoAmLVLlfSdAg,2515
|
|
|
6
6
|
kagent/adk/cli.py,sha256=Sdw9FXnUmeHfgJhdRDq1zpoNMf6GM7x35ZDz_OkQgJg,2963
|
|
7
7
|
kagent/adk/types.py,sha256=v7VbO0tAPvpjdEgWJroEq64jSCz6D3Q0yPdRM0a7MjM,4260
|
|
8
8
|
kagent/adk/converters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
kagent/adk/converters/
|
|
9
|
+
kagent/adk/converters/error_mappings.py,sha256=1KUJPS8VrcaTv6yUKb5Whg-S2XX8YGJmtTIeZqnqvuw,2769
|
|
10
|
+
kagent/adk/converters/event_converter.py,sha256=WKQRqREB11TbgGp6U_--mmukvJJgew6-VEkrGBqGVA4,10519
|
|
10
11
|
kagent/adk/converters/part_converter.py,sha256=Q9Kbteit8XdL_9Tb8bAtxRxOZQei8Wabszwsl4YMe2c,7507
|
|
11
12
|
kagent/adk/converters/request_converter.py,sha256=iTmTmhlnyRfuYyFi4WmpTSXPz22xjjotbe750j-CvYA,1072
|
|
12
13
|
kagent/adk/models/__init__.py,sha256=mqD0JhS9kT1rMpFNLq5-qnjstpp6lzT9xADaOfjrUKY,78
|
|
13
14
|
kagent/adk/models/_openai.py,sha256=0hQklnXacTHsb5h1gkPqmuoEyJl_ibh5R-FBY-wQ7Ts,16594
|
|
14
|
-
kagent_adk-0.6.
|
|
15
|
-
kagent_adk-0.6.
|
|
16
|
-
kagent_adk-0.6.
|
|
17
|
-
kagent_adk-0.6.
|
|
15
|
+
kagent_adk-0.6.11.dist-info/METADATA,sha256=tgksopEr1rQBB4B6nGmtBeQeNTDG7dwxLpWXEitjTs8,944
|
|
16
|
+
kagent_adk-0.6.11.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
17
|
+
kagent_adk-0.6.11.dist-info/entry_points.txt,sha256=a1Q2Inc9L0dvXWEkwnCdf9cfXdpX5Dl2Q6DhNWNjhxw,50
|
|
18
|
+
kagent_adk-0.6.11.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|