From 968a990a172e3c52b1d8262ffcb682667d1c9ce9 Mon Sep 17 00:00:00 2001 From: "fangyaozheng@bytedance.com" Date: Mon, 4 Aug 2025 13:26:34 +0800 Subject: [PATCH 1/3] feat: add remote agent --- docs/docs/agent.md | 29 ++++++++++++++++++++++++++++- veadk/a2a/remote_ve_agent.py | 21 +++++++++++++++++++++ veadk/runner.py | 18 ++++++++---------- 3 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 veadk/a2a/remote_ve_agent.py diff --git a/docs/docs/agent.md b/docs/docs/agent.md index 70b9d5e1..ae0b064f 100644 --- a/docs/docs/agent.md +++ b/docs/docs/agent.md @@ -15,6 +15,28 @@ Agent中主要包括如下属性: | knowledgebase | Vector database | 知识库,后端通常为一个向量数据库(Vector database),能够检索 | | tracers | list | 追踪器列表,能够定义不同的追踪方式,并在Agent执行完毕后对整体Tracing信息保存至本地 | +## A2A智能体 + +当你的智能体部署到云上后,可以在本地被初始化为一个Remote Agent,也就是能够通过A2A协议来访问的智能体,初始化方法如下: + +```python +remote_agent = RemoteVeAgent( + name="a2a_agent", + url="..." # <--- url from cloud platform +) + +short_term_memory = ShortTermMemory() +runner = Runner( + agent=remote_agent, + short_term_memory=short_term_memory + ) + +res = await runner.run( + messages="...", + session_id="sample_session" + ) +``` + ## 运行 在生产环境中,我们推荐您使用`Runner`来进行多租户服务: @@ -29,6 +51,11 @@ USER_ID = "" SESSION_ID = "" agent = Agent() -runner = Runner(agent=agent, short_term_memory=ShortTermMemory()) + +runner = Runner( + agent=agent, + short_term_memory=ShortTermMemory() + ) + response = await runner.run(messages=prompt, session_id=session_id) ``` diff --git a/veadk/a2a/remote_ve_agent.py b/veadk/a2a/remote_ve_agent.py new file mode 100644 index 00000000..1be9d347 --- /dev/null +++ b/veadk/a2a/remote_ve_agent.py @@ -0,0 +1,21 @@ +import json + +import requests +from a2a.types import AgentCard +from google.adk.agents.remote_a2a_agent import RemoteA2aAgent + +AGENT_CARD_WELL_KNOWN_PATH = "/.well-known/agent-card.json" + + +class RemoteVeAgent(RemoteA2aAgent): + def __init__(self, name: str, url: str): + agent_card_dict = requests.get(url + AGENT_CARD_WELL_KNOWN_PATH).json() + agent_card_dict["url"] = url + + agent_card_json_str = json.dumps(agent_card_dict, ensure_ascii=False, indent=2) + + agent_card_object = AgentCard.model_validate_json(str(agent_card_json_str)) + + super().__init__( + name=name, description="weather reporter", agent_card=agent_card_object + ) diff --git a/veadk/runner.py b/veadk/runner.py index cf1f1612..f0d6db50 100644 --- a/veadk/runner.py +++ b/veadk/runner.py @@ -19,6 +19,7 @@ from google.genai import types from google.genai.types import Blob +from veadk.a2a.remote_ve_agent import RemoteVeAgent from veadk.agent import Agent from veadk.evaluation import EvalSetRecorder from veadk.memory.short_term_memory import ShortTermMemory @@ -41,7 +42,7 @@ class Runner: def __init__( self, - agent: Agent, + agent: Agent | RemoteVeAgent, short_term_memory: ShortTermMemory, app_name: str = "veadk_default_app", user_id: str = "veadk_default_user", @@ -56,7 +57,10 @@ def __init__( self.short_term_memory = short_term_memory self.session_service = short_term_memory.session_service - self.long_term_memory = self.agent.long_term_memory + if isinstance(self.agent, Agent): + self.long_term_memory = self.agent.long_term_memory + else: + self.long_term_memory = None # maintain a in-memory runner for fast inference self.runner = ADKRunner( @@ -67,13 +71,6 @@ def __init__( ) def _convert_messages(self, messages) -> list: - # RunnerMessage = Union[ - # str, # single turn text-based prompt - # list[str], # multiple turn text-based prompt - # dict, # single turn prompt with media - # list[dict], # multiple turn prompt with media - # list[dict | str], # multiple turn prompt with media and text-based prompt - # ] if isinstance(messages, str): messages = [types.Content(role="user", parts=[types.Part(text=messages)])] elif isinstance(messages, MediaMessage): @@ -159,7 +156,8 @@ async def run( final_output = await self._run(session_id, message, stream) # try to save tracing file - self.save_tracing_file(session_id) + if isinstance(self.agent, Agent): + self.save_tracing_file(session_id) return final_output From 19be5fa18ce7e9a7ae250b0318ab27be4428c77f Mon Sep 17 00:00:00 2001 From: "fangyaozheng@bytedance.com" Date: Mon, 4 Aug 2025 13:48:24 +0800 Subject: [PATCH 2/3] feat: add veadk init command in CLI --- veadk/cli/services/vefaas/template/README.md | 37 ++++++++++++ .../vefaas/template/config.yaml.example | 10 ++++ veadk/cli/services/vefaas/template/deploy.py | 44 ++++++++++++++ veadk/cli/services/vefaas/template/src/app.py | 30 ++++++++++ .../services/vefaas/template/src/config.py | 58 +++++++++++++++++++ .../vefaas/template/src/requirements.txt | 3 + veadk/cli/services/vefaas/template/src/run.sh | 42 ++++++++++++++ 7 files changed, 224 insertions(+) create mode 100644 veadk/cli/services/vefaas/template/README.md create mode 100644 veadk/cli/services/vefaas/template/config.yaml.example create mode 100644 veadk/cli/services/vefaas/template/deploy.py create mode 100644 veadk/cli/services/vefaas/template/src/app.py create mode 100644 veadk/cli/services/vefaas/template/src/config.py create mode 100644 veadk/cli/services/vefaas/template/src/requirements.txt create mode 100755 veadk/cli/services/vefaas/template/src/run.sh diff --git a/veadk/cli/services/vefaas/template/README.md b/veadk/cli/services/vefaas/template/README.md new file mode 100644 index 00000000..f31d5000 --- /dev/null +++ b/veadk/cli/services/vefaas/template/README.md @@ -0,0 +1,37 @@ +# Template project for Vefaas + +This is a template project for Vefaas. You can use it as a starting point for your own project. + +We implement an minimal agent to report weather in terms of the given city. + +## Structure + +| File | Illustration | +| - | - | +| `src/app.py` | The entrypoint of VeFaaS server. | +| `src/run.sh` | The launch script of VeFaaS server. | +| `src/requirements.txt` | Dependencies of your project. `VeADK`, `FastAPI`, and `uvicorn` must be included. | +| `src/config.py` | The agent and memory definitions. **You may edit this file.** | +| `config.yaml.example` | Envs for your project (e.g., `api_key`, `token`, ...). **You may edit this file.** | +| `deploy.py` | Local script for deployment. | + +You must export your agent and short-term memory in `src/config.py`. + +## Deploy + +We recommand you deploy this project by the `cloud` module of VeADK. + +```bash +python deploy.py +``` + +You may see output like this: + +```bash +Successfully deployed on: + +https://....volceapi.com +Message ID: ... +Response from ...: The weather in Beijing is sunny, with a temperature of 25°C. +App ID: ... +``` diff --git a/veadk/cli/services/vefaas/template/config.yaml.example b/veadk/cli/services/vefaas/template/config.yaml.example new file mode 100644 index 00000000..95dad4d8 --- /dev/null +++ b/veadk/cli/services/vefaas/template/config.yaml.example @@ -0,0 +1,10 @@ +model: + agent: + provider: openai + name: doubao-1-5-pro-256k-250115 + api_base: https://ark.cn-beijing.volces.com/api/v3/ + api_key: + +volcengine: + access_key: + secret_key: \ No newline at end of file diff --git a/veadk/cli/services/vefaas/template/deploy.py b/veadk/cli/services/vefaas/template/deploy.py new file mode 100644 index 00000000..ca05676a --- /dev/null +++ b/veadk/cli/services/vefaas/template/deploy.py @@ -0,0 +1,44 @@ +# 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. + +import asyncio +from pathlib import Path + +from veadk.cloud.cloud_agent_engine import CloudAgentEngine + +SESSION_ID = "cloud_app_test_session" +USER_ID = "cloud_app_test_user" + + +async def main(): + engine = CloudAgentEngine() + cloud_app = engine.deploy( + path=str(Path(__file__).parent / "src"), + name="weather-reporter", + # gateway_name="", # <--- your gateway instance name if you have + ) + + response_message = await cloud_app.message_send( + "How is the weather like in Beijing?", SESSION_ID, USER_ID + ) + + print(f"Message ID: {response_message.messageId}") + + print(f"Response from {cloud_app.endpoint}: {response_message.parts[0].root.text}") + + print(f"App ID: {cloud_app.app_id}") + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/veadk/cli/services/vefaas/template/src/app.py b/veadk/cli/services/vefaas/template/src/app.py new file mode 100644 index 00000000..c805b21e --- /dev/null +++ b/veadk/cli/services/vefaas/template/src/app.py @@ -0,0 +1,30 @@ +# 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. + +import os + +from config import AGENT, APP_NAME, SHORT_TERM_MEMORY, TRACERS + +from veadk.a2a.ve_a2a_server import init_app + +SERVER_HOST = os.getenv("SERVER_HOST") + +AGENT.tracers = TRACERS + +app = init_app( + server_url=SERVER_HOST, + app_name=APP_NAME, + agent=AGENT, + short_term_memory=SHORT_TERM_MEMORY, +) diff --git a/veadk/cli/services/vefaas/template/src/config.py b/veadk/cli/services/vefaas/template/src/config.py new file mode 100644 index 00000000..1349d20a --- /dev/null +++ b/veadk/cli/services/vefaas/template/src/config.py @@ -0,0 +1,58 @@ +# 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. + +import os + +from veadk import Agent +from veadk.memory.short_term_memory import ShortTermMemory +from veadk.tools.demo_tools import get_city_weather +from veadk.tracing.base_tracer import BaseTracer +from veadk.tracing.telemetry.opentelemetry_tracer import OpentelemetryTracer + +# ============= +# Generated by VeADK, do not edit!!! +# ============= +TRACERS: list[BaseTracer] = [] + +exporters = [] +if os.getenv("VEADK_TRACER_APMPLUS") == "true": + from veadk.tracing.telemetry.exporters.apmplus_exporter import APMPlusExporter + + exporters.append(APMPlusExporter()) + +if os.getenv("VEADK_TRACER_COZELOOP") == "true": + from veadk.tracing.telemetry.exporters.cozeloop_exporter import CozeloopExporter + + exporters.append(CozeloopExporter()) + +if os.getenv("VEADK_TRACER_TLS") == "true": + from veadk.tracing.telemetry.exporters.tls_exporter import TLSExporter + + exporters.append(TLSExporter()) + +TRACERS.append(OpentelemetryTracer(exporters=exporters)) + +# ============= +# Required [you can edit here] +# ============= +APP_NAME: str = "weather-reporter" # <--- export your app name +AGENT: Agent = Agent(tools=[get_city_weather]) # <--- export your agent +SHORT_TERM_MEMORY: ShortTermMemory = ( + ShortTermMemory() +) # <--- export your short term memory + +# ============= +# Optional +# ============= +# Other global variables diff --git a/veadk/cli/services/vefaas/template/src/requirements.txt b/veadk/cli/services/vefaas/template/src/requirements.txt new file mode 100644 index 00000000..aaca93f9 --- /dev/null +++ b/veadk/cli/services/vefaas/template/src/requirements.txt @@ -0,0 +1,3 @@ +git+https://github.com/volcengine/veadk-python.git +uvicorn[standard] +fastapi \ No newline at end of file diff --git a/veadk/cli/services/vefaas/template/src/run.sh b/veadk/cli/services/vefaas/template/src/run.sh new file mode 100755 index 00000000..95b6a57d --- /dev/null +++ b/veadk/cli/services/vefaas/template/src/run.sh @@ -0,0 +1,42 @@ +#!/bin/bash +set -ex +cd `dirname $0` + +# A special check for CLI users (run.sh should be located at the 'root' dir) +if [ -d "output" ]; then + cd ./output/ +fi + +# Default values for host and port +HOST="0.0.0.0" +PORT=${_FAAS_RUNTIME_PORT:-8000} +TIMEOUT=${_FAAS_FUNC_TIMEOUT} + +export SERVER_HOST=$HOST +export SERVER_PORT=$PORT + +export PYTHONPATH=$PYTHONPATH:./site-packages +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + --port) + PORT="$2" + shift 2 + ;; + --host) + HOST="$2" + shift 2 + ;; + *) + shift + ;; + esac +done + +# in case of uvicorn and fastapi not installed in user's requirements.txt +python3 -m pip install uvicorn[standard] + +python3 -m pip install fastapi + +# running +exec python3 -m uvicorn app:app --host $HOST --port $PORT --timeout-graceful-shutdown $TIMEOUT From 6577ecc9778d155ef47dbd9bf051698037dcd847 Mon Sep 17 00:00:00 2001 From: "fangyaozheng@bytedance.com" Date: Mon, 4 Aug 2025 14:18:50 +0800 Subject: [PATCH 3/3] fix: fix typos --- README.md | 2 +- samples/template-project-for-vefaas/README.md | 37 ------------ .../config.yaml.example | 10 ---- samples/template-project-for-vefaas/deploy.py | 44 -------------- .../template-project-for-vefaas/src/app.py | 30 ---------- .../template-project-for-vefaas/src/config.py | 58 ------------------- .../src/requirements.txt | 3 - .../template-project-for-vefaas/src/run.sh | 42 -------------- veadk/a2a/remote_ve_agent.py | 4 +- veadk/cli/main.py | 28 +++++++++ veadk/cli/services/vefaas/template/README.md | 2 +- 11 files changed, 31 insertions(+), 229 deletions(-) delete mode 100644 samples/template-project-for-vefaas/README.md delete mode 100644 samples/template-project-for-vefaas/config.yaml.example delete mode 100644 samples/template-project-for-vefaas/deploy.py delete mode 100644 samples/template-project-for-vefaas/src/app.py delete mode 100644 samples/template-project-for-vefaas/src/config.py delete mode 100644 samples/template-project-for-vefaas/src/requirements.txt delete mode 100755 samples/template-project-for-vefaas/src/run.sh diff --git a/README.md b/README.md index 849ae9f5..a095a671 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ print(res) VeADK provides several useful command line tools for faster deployment and optimization, such as: -- `veadk deploy`: deploy your project to Volcengine VeFaaS platform +- `veadk deploy`: deploy your project to Volcengine VeFaaS platform (you can use `veadk init` to init a demo project first) - `veadk prompt`: otpimize the system prompt of your agent by PromptPilot ## Contribution diff --git a/samples/template-project-for-vefaas/README.md b/samples/template-project-for-vefaas/README.md deleted file mode 100644 index f31d5000..00000000 --- a/samples/template-project-for-vefaas/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# Template project for Vefaas - -This is a template project for Vefaas. You can use it as a starting point for your own project. - -We implement an minimal agent to report weather in terms of the given city. - -## Structure - -| File | Illustration | -| - | - | -| `src/app.py` | The entrypoint of VeFaaS server. | -| `src/run.sh` | The launch script of VeFaaS server. | -| `src/requirements.txt` | Dependencies of your project. `VeADK`, `FastAPI`, and `uvicorn` must be included. | -| `src/config.py` | The agent and memory definitions. **You may edit this file.** | -| `config.yaml.example` | Envs for your project (e.g., `api_key`, `token`, ...). **You may edit this file.** | -| `deploy.py` | Local script for deployment. | - -You must export your agent and short-term memory in `src/config.py`. - -## Deploy - -We recommand you deploy this project by the `cloud` module of VeADK. - -```bash -python deploy.py -``` - -You may see output like this: - -```bash -Successfully deployed on: - -https://....volceapi.com -Message ID: ... -Response from ...: The weather in Beijing is sunny, with a temperature of 25°C. -App ID: ... -``` diff --git a/samples/template-project-for-vefaas/config.yaml.example b/samples/template-project-for-vefaas/config.yaml.example deleted file mode 100644 index 95dad4d8..00000000 --- a/samples/template-project-for-vefaas/config.yaml.example +++ /dev/null @@ -1,10 +0,0 @@ -model: - agent: - provider: openai - name: doubao-1-5-pro-256k-250115 - api_base: https://ark.cn-beijing.volces.com/api/v3/ - api_key: - -volcengine: - access_key: - secret_key: \ No newline at end of file diff --git a/samples/template-project-for-vefaas/deploy.py b/samples/template-project-for-vefaas/deploy.py deleted file mode 100644 index ca05676a..00000000 --- a/samples/template-project-for-vefaas/deploy.py +++ /dev/null @@ -1,44 +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. - -import asyncio -from pathlib import Path - -from veadk.cloud.cloud_agent_engine import CloudAgentEngine - -SESSION_ID = "cloud_app_test_session" -USER_ID = "cloud_app_test_user" - - -async def main(): - engine = CloudAgentEngine() - cloud_app = engine.deploy( - path=str(Path(__file__).parent / "src"), - name="weather-reporter", - # gateway_name="", # <--- your gateway instance name if you have - ) - - response_message = await cloud_app.message_send( - "How is the weather like in Beijing?", SESSION_ID, USER_ID - ) - - print(f"Message ID: {response_message.messageId}") - - print(f"Response from {cloud_app.endpoint}: {response_message.parts[0].root.text}") - - print(f"App ID: {cloud_app.app_id}") - - -if __name__ == "__main__": - asyncio.run(main()) diff --git a/samples/template-project-for-vefaas/src/app.py b/samples/template-project-for-vefaas/src/app.py deleted file mode 100644 index c805b21e..00000000 --- a/samples/template-project-for-vefaas/src/app.py +++ /dev/null @@ -1,30 +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. - -import os - -from config import AGENT, APP_NAME, SHORT_TERM_MEMORY, TRACERS - -from veadk.a2a.ve_a2a_server import init_app - -SERVER_HOST = os.getenv("SERVER_HOST") - -AGENT.tracers = TRACERS - -app = init_app( - server_url=SERVER_HOST, - app_name=APP_NAME, - agent=AGENT, - short_term_memory=SHORT_TERM_MEMORY, -) diff --git a/samples/template-project-for-vefaas/src/config.py b/samples/template-project-for-vefaas/src/config.py deleted file mode 100644 index 1349d20a..00000000 --- a/samples/template-project-for-vefaas/src/config.py +++ /dev/null @@ -1,58 +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. - -import os - -from veadk import Agent -from veadk.memory.short_term_memory import ShortTermMemory -from veadk.tools.demo_tools import get_city_weather -from veadk.tracing.base_tracer import BaseTracer -from veadk.tracing.telemetry.opentelemetry_tracer import OpentelemetryTracer - -# ============= -# Generated by VeADK, do not edit!!! -# ============= -TRACERS: list[BaseTracer] = [] - -exporters = [] -if os.getenv("VEADK_TRACER_APMPLUS") == "true": - from veadk.tracing.telemetry.exporters.apmplus_exporter import APMPlusExporter - - exporters.append(APMPlusExporter()) - -if os.getenv("VEADK_TRACER_COZELOOP") == "true": - from veadk.tracing.telemetry.exporters.cozeloop_exporter import CozeloopExporter - - exporters.append(CozeloopExporter()) - -if os.getenv("VEADK_TRACER_TLS") == "true": - from veadk.tracing.telemetry.exporters.tls_exporter import TLSExporter - - exporters.append(TLSExporter()) - -TRACERS.append(OpentelemetryTracer(exporters=exporters)) - -# ============= -# Required [you can edit here] -# ============= -APP_NAME: str = "weather-reporter" # <--- export your app name -AGENT: Agent = Agent(tools=[get_city_weather]) # <--- export your agent -SHORT_TERM_MEMORY: ShortTermMemory = ( - ShortTermMemory() -) # <--- export your short term memory - -# ============= -# Optional -# ============= -# Other global variables diff --git a/samples/template-project-for-vefaas/src/requirements.txt b/samples/template-project-for-vefaas/src/requirements.txt deleted file mode 100644 index aaca93f9..00000000 --- a/samples/template-project-for-vefaas/src/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -git+https://github.com/volcengine/veadk-python.git -uvicorn[standard] -fastapi \ No newline at end of file diff --git a/samples/template-project-for-vefaas/src/run.sh b/samples/template-project-for-vefaas/src/run.sh deleted file mode 100755 index 95b6a57d..00000000 --- a/samples/template-project-for-vefaas/src/run.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -set -ex -cd `dirname $0` - -# A special check for CLI users (run.sh should be located at the 'root' dir) -if [ -d "output" ]; then - cd ./output/ -fi - -# Default values for host and port -HOST="0.0.0.0" -PORT=${_FAAS_RUNTIME_PORT:-8000} -TIMEOUT=${_FAAS_FUNC_TIMEOUT} - -export SERVER_HOST=$HOST -export SERVER_PORT=$PORT - -export PYTHONPATH=$PYTHONPATH:./site-packages -# Parse arguments -while [[ $# -gt 0 ]]; do - case $1 in - --port) - PORT="$2" - shift 2 - ;; - --host) - HOST="$2" - shift 2 - ;; - *) - shift - ;; - esac -done - -# in case of uvicorn and fastapi not installed in user's requirements.txt -python3 -m pip install uvicorn[standard] - -python3 -m pip install fastapi - -# running -exec python3 -m uvicorn app:app --host $HOST --port $PORT --timeout-graceful-shutdown $TIMEOUT diff --git a/veadk/a2a/remote_ve_agent.py b/veadk/a2a/remote_ve_agent.py index 1be9d347..299b8ad5 100644 --- a/veadk/a2a/remote_ve_agent.py +++ b/veadk/a2a/remote_ve_agent.py @@ -16,6 +16,4 @@ def __init__(self, name: str, url: str): agent_card_object = AgentCard.model_validate_json(str(agent_card_json_str)) - super().__init__( - name=name, description="weather reporter", agent_card=agent_card_object - ) + super().__init__(name=name, agent_card=agent_card_object) diff --git a/veadk/cli/main.py b/veadk/cli/main.py index 13f72799..ad357309 100644 --- a/veadk/cli/main.py +++ b/veadk/cli/main.py @@ -16,6 +16,7 @@ import importlib.util import os +import shutil import sys from pathlib import Path @@ -30,6 +31,33 @@ app = typer.Typer(name="vego") +@app.command() +def init(): + """Init a veadk project that can be deployed to Volcengine VeFaaS.""" + from rich.prompt import Confirm, Prompt + + cwd = Path.cwd() + template_dir = Path(__file__).parent.resolve() / "services" / "vefaas" / "template" + + name = Prompt.ask("Project name", default="veadk-cloud-agent") + + target_dir = cwd / name + + if target_dir.exists(): + response = Confirm.ask( + f"Target directory '{target_dir}' already exists, do you want to overwrite it?: " + ) + if not response: + print("Operation cancelled.") + return + else: + shutil.rmtree(target_dir) # 删除旧目录 + print(f"Deleted existing directory: {target_dir}") + + shutil.copytree(template_dir, target_dir) + print(f"Created new project: {name}") + + # @app.command() # def web( # path: str = typer.Option(".", "--path", help="Agent project path"), diff --git a/veadk/cli/services/vefaas/template/README.md b/veadk/cli/services/vefaas/template/README.md index f31d5000..9ef8d572 100644 --- a/veadk/cli/services/vefaas/template/README.md +++ b/veadk/cli/services/vefaas/template/README.md @@ -19,7 +19,7 @@ You must export your agent and short-term memory in `src/config.py`. ## Deploy -We recommand you deploy this project by the `cloud` module of VeADK. +We recommend you deploy this project by the `cloud` module of VeADK. ```bash python deploy.py