From 0c63d813dc4b8c3d496e1de159d2c9ed8a52cb18 Mon Sep 17 00:00:00 2001 From: chiguyong Date: Mon, 15 Jun 2026 08:30:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20code=20review=20P0/P1=20fixes=20?= =?UTF-8?q?=E2=80=94=20history=20param=20bug,=20llm=20dict=20access,=20WS?= =?UTF-8?q?=20ping?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix P0: _build_history_messages(conv.id, message_text) passed string as limit param causing TypeError at runtime — removed erroneous second arg - Fix P0: llm.py /llm/models used attribute access on dict (model_config.max_tokens) causing AttributeError — changed to dict.get() access - Fix P1: Portal WS ignored ping messages — added pong response handler - Fix: composition.py f-string without placeholders --- src/agentkit/server/routes/llm.py | 6 +++--- src/agentkit/server/routes/portal.py | 6 +++++- src/agentkit/tools/composition.py | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/agentkit/server/routes/llm.py b/src/agentkit/server/routes/llm.py index 8bed918..faab1e8 100644 --- a/src/agentkit/server/routes/llm.py +++ b/src/agentkit/server/routes/llm.py @@ -30,9 +30,9 @@ async def list_models(req: Request): "id": f"{provider_name}/{model_name}", "provider": provider_name, "model": model_name, - "max_tokens": model_config.max_tokens, - "cost_per_1k_input": model_config.cost_per_1k_input, - "cost_per_1k_output": model_config.cost_per_1k_output, + "max_tokens": model_config.get("max_tokens"), + "cost_per_1k_input": model_config.get("cost_per_1k_input"), + "cost_per_1k_output": model_config.get("cost_per_1k_output"), }) aliases = config.model_aliases if config.model_aliases else {} diff --git a/src/agentkit/server/routes/portal.py b/src/agentkit/server/routes/portal.py index d2918e3..a852725 100644 --- a/src/agentkit/server/routes/portal.py +++ b/src/agentkit/server/routes/portal.py @@ -571,6 +571,10 @@ async def portal_websocket(websocket: WebSocket): await websocket.send_json({"type": "result", "data": {"status": "cancelled"}}) return + if msg_type == "ping": + await websocket.send_json({"type": "pong"}) + continue + if msg_type != "chat": continue @@ -683,7 +687,7 @@ async def portal_websocket(websocket: WebSocket): ) chat_messages.append({"role": "user", "content": message_text}) # Inject conversation history for context continuity - history_msgs = _build_history_messages(conv.id, message_text) + history_msgs = _build_history_messages(conv.id) for hm in history_msgs: chat_messages.insert(-1, hm) response = await llm_gateway.chat( diff --git a/src/agentkit/tools/composition.py b/src/agentkit/tools/composition.py index 4610265..a0a9e10 100644 --- a/src/agentkit/tools/composition.py +++ b/src/agentkit/tools/composition.py @@ -223,7 +223,7 @@ class DynamicSelector(Tool): prompt = ( f"Given the following input:\n{json.dumps(kwargs, ensure_ascii=False)}\n\n" f"Available tools:\n" + "\n".join(tool_descriptions) + "\n\n" - f"Which tool number should be used? Reply with just the number." + "Which tool number should be used? Reply with just the number." ) try: