diff --git a/docs/docs/agent.md b/docs/docs/agent.md index a888b337..3c87870f 100644 --- a/docs/docs/agent.md +++ b/docs/docs/agent.md @@ -21,7 +21,6 @@ Agent 中主要包括如下属性: | knowledgebase | KnowledgeBase | 知识库,后端支持本地内存(local)和数据库(opensearch、viking、redis、mysql),通常设置为一个能够检索的向量数据库 | | long_term_memory | LongTermMemory | 长期记忆,后端支持本地内存(local)和数据库(opensearch、viking、redis、mysql),通常设置为一个能够检索的向量数据库 | | tracers | list | 追踪器列表,能够定义不同的追踪方式,并在 Agent 执行完毕后将整体 Tracing 信息保存至本地 | -| serve_url | str | Agent 服务主机的 URL,将显示在 Agent Card 中 | 您可以在[火山引擎方舟平台](https://www.volcengine.com/product/ark)选择适合您的大模型。 diff --git a/tests/test_agent.py b/tests/test_agent.py index 45c23347..97a7b82c 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -53,7 +53,6 @@ def test_agent(): knowledgebase=knowledgebase, long_term_memory=long_term_memory, tracers=[tracer], - serve_url="", ) assert agent.model.model == f"{agent.model_provider}/{agent.model_name}" # type: ignore @@ -89,8 +88,6 @@ def test_agent_default_values(): assert agent.long_term_memory is None assert agent.tracers == [] - assert agent.serve_url == "" - @patch.dict("os.environ", {"MODEL_AGENT_API_KEY": "mock_api_key"}) def test_agent_without_knowledgebase(): @@ -208,11 +205,3 @@ def test_agent_custom_name_and_description(): assert agent.name == custom_name assert agent.description == custom_description - - -@patch.dict("os.environ", {"MODEL_AGENT_API_KEY": "mock_api_key"}) -def test_agent_serve_url(): - serve_url = "http://localhost:8080" - agent = Agent(serve_url=serve_url) - - assert agent.serve_url == serve_url diff --git a/tests/test_agent_card.py b/tests/test_agent_card.py deleted file mode 100644 index af39894a..00000000 --- a/tests/test_agent_card.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from veadk import Agent -from veadk.a2a.agent_card import get_agent_card - - -def test_agent_card(): - agent = Agent( - name="test_agent", - description="a veadk test agent", - instruction="a veadk test agent", - model_name="test_model_name", - model_provider="test_model_provider", - model_api_key="test_model_api_key", - model_api_base="test_model_api_base", - serve_url="http://localhost:8000", - ) - - agent_card = get_agent_card(agent, url=agent.serve_url) - - assert agent_card.url == agent.serve_url diff --git a/veadk/agent.py b/veadk/agent.py index 0af9f586..cc7701a3 100644 --- a/veadk/agent.py +++ b/veadk/agent.py @@ -14,11 +14,11 @@ from __future__ import annotations -from typing import Optional +from typing import Optional, Union from google.adk.agents import LlmAgent, RunConfig from google.adk.agents.base_agent import BaseAgent -from google.adk.agents.llm_agent import ToolUnion +from google.adk.agents.llm_agent import InstructionProvider, ToolUnion from google.adk.agents.run_config import StreamingMode from google.adk.models.lite_llm import LiteLlm from google.adk.runners import Runner @@ -57,8 +57,8 @@ class Agent(LlmAgent): description: str = DEFAULT_DESCRIPTION """The description of the agent. This will be helpful in A2A scenario.""" - instruction: str = DEFAULT_INSTRUCTION - """The instruction for the agent, such as principles of function calling.""" + instruction: Union[str, InstructionProvider] = DEFAULT_INSTRUCTION + """The instruction for the agent.""" model_name: str = Field(default_factory=lambda: settings.model.name) """The name of the model for agent running.""" @@ -93,9 +93,6 @@ class Agent(LlmAgent): tracers: list[BaseTracer] = [] """The tracers provided to agent.""" - serve_url: str = "" - """The url of agent serving host. Show in agent card.""" - def model_post_init(self, __context: Any) -> None: super().model_post_init(None) # for sub_agents init diff --git a/veadk/cli/cli_init.py b/veadk/cli/cli_init.py index 82e2366f..7fb858a3 100644 --- a/veadk/cli/cli_init.py +++ b/veadk/cli/cli_init.py @@ -16,8 +16,8 @@ from typing import Any import click -from veadk.version import VERSION +from veadk.version import VERSION warnings.filterwarnings( "ignore", category=UserWarning, module="pydantic._internal._fields" @@ -103,7 +103,7 @@ def init( shutil.rmtree(target_dir_path) settings = _render_prompts() - settings["local_dir_name"] = local_dir_name.replace("-", "_") + settings["local_dir_name"] = local_dir_name if not vefaas_template_type: vefaas_template_type = "template" diff --git a/veadk/integrations/ve_faas/ve_faas.py b/veadk/integrations/ve_faas/ve_faas.py index 7fb80b47..9aebb9fe 100644 --- a/veadk/integrations/ve_faas/ve_faas.py +++ b/veadk/integrations/ve_faas/ve_faas.py @@ -195,16 +195,18 @@ def _release_application(self, app_id: str): time.sleep(10) status, full_response = self._get_application_status(app_id) - assert status == "deploy_success", ( - f"Release application failed. Response: {full_response}" - ) - - cloud_resource = full_response["Result"]["CloudResource"] - cloud_resource = json.loads(cloud_resource) - - url = cloud_resource["framework"]["url"]["system_url"] - - return url + if status == "deploy_success": + cloud_resource = full_response["Result"]["CloudResource"] + cloud_resource = json.loads(cloud_resource) + url = cloud_resource["framework"]["url"]["system_url"] + return url + else: + logger.error(f"Release application failed: {full_response}") + logs = self._get_application_logs(app_id=app_id) + log_text = "" + for log_line in logs: + log_text += log_line.strip() + "\n" + raise Exception(f"Release application failed. Logs:\n{log_text}") def _get_application_status(self, app_id: str): response = ve_request( @@ -707,3 +709,21 @@ def deploy_image( logger.info(f"VeFaaS application {name} with ID {app_id} deployed on {url}.") return url, app_id, function_id + + def _get_application_logs(self, app_id: str) -> list[str]: + response = _ = ve_request( + request_body={"Id": app_id, "Limit": 99999, "RevisionNumber": 1}, + action="GetApplicationRevisionLog", + ak=self.ak, + sk=self.sk, + service="vefaas", + version="2021-03-03", + region="cn-beijing", + host="open.volcengineapi.com", + ) + + try: + logs = response["Result"]["LogLines"] + return logs + except Exception as _: + raise ValueError(f"Get application log failed. Response: {response}")