Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions samples/template-project-for-vefaas/README.md
Original file line number Diff line number Diff line change
@@ -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: ...
```
10 changes: 10 additions & 0 deletions samples/template-project-for-vefaas/config.yaml.example
Original file line number Diff line number Diff line change
@@ -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:
44 changes: 44 additions & 0 deletions samples/template-project-for-vefaas/deploy.py
Original file line number Diff line number Diff line change
@@ -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())
30 changes: 30 additions & 0 deletions samples/template-project-for-vefaas/src/app.py
Original file line number Diff line number Diff line change
@@ -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,
)
58 changes: 58 additions & 0 deletions samples/template-project-for-vefaas/src/config.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions samples/template-project-for-vefaas/src/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
git+https://github.com/volcengine/veadk-python.git
uvicorn[standard]
fastapi
42 changes: 42 additions & 0 deletions samples/template-project-for-vefaas/src/run.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions tests/test_runtime_data_collecting.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,3 @@ async def test_runtime_data_collecting():
assert len(data["eval_cases"]) == 1

os.remove(dump_path)
os.remove(dump_path)
os.remove(dump_path)
Loading