Skip to content

Commit 97c7222

Browse files
authored
fix: fixed some stability and experience issues, added retry and Unicode support (#33)
2 parents 8595216 + c66fe6f commit 97c7222

File tree

10 files changed

+49
-17
lines changed

10 files changed

+49
-17
lines changed

agentkit/apps/agent_server_app/agent_server_app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ async def _invoke_compat(request: Request):
104104
)
105105
session_id = (
106106
headers.get("session_id")
107-
or headers.get("x-session-id")
108-
or "agentkit_sample_session"
107+
or ""
109108
)
110109

111110
# Determine app_name from loader

agentkit/apps/agent_server_app/middleware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ async def __call__(self, scope, receive, send):
4343
}
4444

4545
# Currently unable to retrieve user_id and session_id from headers; keep logic for future use
46-
user_id = headers.get("user_id") or headers.get("x-user-id") or ""
47-
session_id = headers.get("session_id") or headers.get("x-session-id") or ""
46+
user_id = headers.get("user_id")
47+
session_id = headers.get("session_id")
4848
headers["user_id"] = user_id
4949
headers["session_id"] = session_id
5050
telemetry.trace_agent_server(

agentkit/apps/agent_server_app/telemetry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def trace_agent_server(
7272
value=safe_serialize_to_json_string(headers),
7373
)
7474

75-
session_id = headers.get("session_id") or headers.get("x-session-id") or ""
75+
session_id = headers.get("session_id")
7676
if session_id:
7777
span.set_attribute(key="gen_ai.session.id", value=session_id)
78-
user_id = headers.get("user_id") or headers.get("x-user-id") or ""
78+
user_id = headers.get("user_id")
7979
if user_id:
8080
span.set_attribute(key="gen_ai.user.id", value=user_id)
8181

agentkit/toolkit/builders/ve_pipeline.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
from agentkit.toolkit.models import BuildResult, ImageInfo
3333
from agentkit.toolkit.reporter import Reporter
3434
from agentkit.toolkit.errors import ErrorCode
35-
from agentkit.utils.misc import generate_random_id, calculate_nonlinear_progress
35+
from agentkit.utils.misc import (
36+
generate_random_id,
37+
calculate_nonlinear_progress,
38+
retry,
39+
)
3640
from agentkit.toolkit.volcengine.services import CRServiceConfig
3741
from .base import Builder
3842

@@ -1303,11 +1307,12 @@ def download_and_show_logs(run_id: str):
13031307

13041308
while True:
13051309
try:
1306-
# Get pipeline run status
1307-
status = cp_client.get_pipeline_run_status(
1308-
workspace_id=workspace_id,
1309-
pipeline_id=pipeline_id,
1310-
run_id=run_id,
1310+
status = retry(
1311+
lambda: cp_client.get_pipeline_run_status(
1312+
workspace_id=workspace_id,
1313+
pipeline_id=pipeline_id,
1314+
run_id=run_id,
1315+
)
13111316
)
13121317

13131318
# Update progress description

agentkit/toolkit/config/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,13 @@ def _save_config(self):
297297
"""Save configuration file"""
298298
os.makedirs(self.config_path.parent, exist_ok=True)
299299
with open(self.config_path, "w", encoding="utf-8") as f:
300-
yaml.dump(self._data, f, default_flow_style=False, sort_keys=False)
300+
yaml.dump(
301+
self._data,
302+
f,
303+
default_flow_style=False,
304+
sort_keys=False,
305+
allow_unicode=True,
306+
)
301307

302308
def get_common_config(self) -> CommonConfig:
303309
"""Get common configuration"""

agentkit/toolkit/runners/ve_agentkit.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
generate_apikey_name,
4040
generate_client_token,
4141
calculate_nonlinear_progress,
42+
retry,
4243
)
4344
from agentkit.sdk.runtime.client import AgentkitRuntimeClient
4445
from agentkit.toolkit.volcengine.iam import VeIAM
@@ -834,8 +835,10 @@ def _wait_for_runtime_status_multiple(
834835
# Use reporter.long_task() for progress tracking
835836
with self.reporter.long_task(task_description, total=total_time) as task:
836837
while True:
837-
runtime = self.agentkit_runtime_client.get_runtime(
838-
runtime_types.GetRuntimeRequest(runtime_id=runtime_id)
838+
runtime = retry(
839+
lambda: self.agentkit_runtime_client.get_runtime(
840+
runtime_types.GetRuntimeRequest(runtime_id=runtime_id)
841+
)
839842
)
840843

841844
# Check if target status reached

agentkit/toolkit/utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616

1717
from .agent_parser import AgentParser
1818

19+
1920
__all__ = ["AgentParser"]

agentkit/utils/misc.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
import math
1616
import string
1717
import random
18+
import time
19+
from typing import Callable, TypeVar
20+
21+
T = TypeVar("T")
1822

1923

2024
def generate_random_id(length=8):
@@ -102,3 +106,17 @@ def calculate_nonlinear_progress(
102106
"""
103107
progress = max_time * (1 - math.exp(-elapsed / expected_time))
104108
return min(progress, max_time * max_ratio)
109+
110+
111+
def retry(
112+
func: Callable[[], T],
113+
retries: int = 3,
114+
delay: float = 1.0,
115+
) -> T:
116+
for attempt in range(retries):
117+
try:
118+
return func()
119+
except Exception: # noqa: BLE001
120+
if attempt == retries - 1:
121+
raise
122+
time.sleep(delay)

agentkit/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
VERSION = "0.2.0"
15+
VERSION = "0.2.1"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "agentkit-sdk-python"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
description = "Python SDK for transforming any AI agent into a production-ready application. Framework-agnostic primitives for runtime, memory, authentication, and tools with volcengine-managed infrastructure."
55
readme = "README.md"
66
requires-python = ">=3.10"

0 commit comments

Comments
 (0)