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
11 changes: 0 additions & 11 deletions tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,6 @@ def test_agent_with_tracers():
assert tracer2 in agent.tracers


@patch.dict(
"os.environ",
{"MODEL_AGENT_NAME": "env_model_name", "MODEL_AGENT_API_KEY": "mock_api_key"},
clear=True,
)
def test_agent_environment_variables():
agent = Agent()
print(agent)
assert agent.model_name == "env_model_name"


@patch.dict("os.environ", {"MODEL_AGENT_API_KEY": "mock_api_key"})
def test_agent_custom_name_and_description():
custom_name = "CustomAgent"
Expand Down
169 changes: 0 additions & 169 deletions tests/test_tos.py

This file was deleted.

23 changes: 5 additions & 18 deletions veadk/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@
from pydantic import ConfigDict, Field
from typing_extensions import Any

from veadk.config import getenv
from veadk.config import settings
from veadk.consts import (
DEFAULT_AGENT_NAME,
DEFAULT_MODEL_AGENT_API_BASE,
DEFAULT_MODEL_AGENT_NAME,
DEFAULT_MODEL_AGENT_PROVIDER,
DEFAULT_MODEL_EXTRA_CONFIG,
)
from veadk.evaluation import EvalSetRecorder
Expand Down Expand Up @@ -63,26 +60,16 @@ class Agent(LlmAgent):
instruction: str = DEFAULT_INSTRUCTION
"""The instruction for the agent, such as principles of function calling."""

model_name: str = Field(
default_factory=lambda: getenv("MODEL_AGENT_NAME", DEFAULT_MODEL_AGENT_NAME)
)
model_name: str = Field(default_factory=lambda: settings.model.name)
"""The name of the model for agent running."""

model_provider: str = Field(
default_factory=lambda: getenv(
"MODEL_AGENT_PROVIDER", DEFAULT_MODEL_AGENT_PROVIDER
)
)
model_provider: str = Field(default_factory=lambda: settings.model.provider)
"""The provider of the model for agent running."""

model_api_base: str = Field(
default_factory=lambda: getenv(
"MODEL_AGENT_API_BASE", DEFAULT_MODEL_AGENT_API_BASE
)
)
model_api_base: str = Field(default_factory=lambda: settings.model.api_base)
"""The api base of the model for agent running."""

model_api_key: str = Field(default_factory=lambda: getenv("MODEL_AGENT_API_KEY"))
model_api_key: str = Field(default_factory=lambda: settings.model.api_key)
"""The api key of the model for agent running."""

model_extra_config: dict = Field(default_factory=dict)
Expand Down
13 changes: 13 additions & 0 deletions veadk/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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.
22 changes: 22 additions & 0 deletions veadk/auth/base_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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.


class BaseAuth:
def __init__(self) -> None: ...

def _fetch_token(self) -> str | dict: ...

@property
def token(self) -> str | dict: ...
13 changes: 13 additions & 0 deletions veadk/auth/veauth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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.
65 changes: 65 additions & 0 deletions veadk/auth/veauth/apmplus_veauth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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 typing_extensions import override

from veadk.auth.veauth.base_veauth import BaseVeAuth
from veadk.utils.logger import get_logger
from veadk.utils.volcengine_sign import ve_request

logger = get_logger(__name__)


class APMPlusVeAuth(BaseVeAuth):
def __init__(
self,
access_key: str = os.getenv("VOLCENGINE_ACCESS_KEY", ""),
secret_key: str = os.getenv("VOLCENGINE_SECRET_KEY", ""),
region: str = "cn-beijing",
) -> None:
super().__init__(access_key, secret_key)

self.region = region

self._token: str = ""

@override
def _fetch_token(self) -> None:
logger.info("Fetching APMPlus token...")

res = ve_request(
request_body={},
action="GetAppKey",
ak=self.access_key,
sk=self.secret_key,
service="apmplus_server",
version="2024-07-30",
region=self.region,
host="open.volcengineapi.com",
# APMPlus frontend required
header={"X-Apmplus-Region": self.region.replace("-", "_")},
)
try:
self._token = res["data"]["app_key"]
except KeyError:
raise ValueError(f"Failed to get APMPlus token: {res}")

@property
def token(self) -> str:
if self._token:
return self._token
self._fetch_token()
return self._token
Loading