Skip to content

Commit 1bf797c

Browse files
committed
fix test
1 parent ac1e40b commit 1bf797c

7 files changed

Lines changed: 29 additions & 35 deletions

File tree

.gitleaks.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ description = "Empty environment variables with KEY pattern"
7373
regex = '''os\.environ\[".*?KEY"\]\s*=\s*".+"'''
7474

7575
[allowlist]
76-
paths = ["requirements.txt"]
76+
paths = ["requirements.txt", "tests"]

tests/test_agent.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
1516
from unittest.mock import Mock, patch
1617

1718
from google.adk.agents.llm_agent import LlmAgent
@@ -33,11 +34,10 @@
3334

3435

3536
def test_agent():
36-
knowledgebase = KnowledgeBase(
37-
index="test_index",
38-
backend="local",
39-
backend_config={"embedding_config": {"api_key": "test"}},
40-
)
37+
os.environ["MODEL_EMBEDDING_API_KEY"] = "mocked_api_key"
38+
39+
knowledgebase = KnowledgeBase(index="test_index", backend="local")
40+
4141
long_term_memory = LongTermMemory(backend="local")
4242
tracer = OpentelemetryTracer()
4343

@@ -69,8 +69,6 @@ def test_agent():
6969

7070
assert agent.knowledgebase == knowledgebase
7171
assert agent.knowledgebase.backend == "local" # type: ignore
72-
assert load_knowledgebase_tool.knowledgebase == agent.knowledgebase
73-
assert load_knowledgebase_tool.load_knowledgebase_tool in agent.tools
7472

7573
assert agent.long_term_memory.backend == "local" # type: ignore
7674
assert load_memory in agent.tools

tests/test_knowledgebase.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
1516

1617
import pytest
1718

@@ -21,11 +22,9 @@
2122

2223
@pytest.mark.asyncio
2324
async def test_knowledgebase():
25+
os.environ["MODEL_EMBEDDING_API_KEY"] = "mocked_api_key"
26+
2427
app_name = "kb_test_app"
25-
kb = KnowledgeBase(
26-
backend="local",
27-
app_name=app_name,
28-
backend_config={"embedding_config": {"api_key": "test"}},
29-
)
28+
kb = KnowledgeBase(backend="local", app_name=app_name)
3029

3130
assert isinstance(kb._backend, InMemoryKnowledgeBackend)

tests/test_long_term_memory.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,20 @@
1313
# limitations under the License.
1414

1515

16+
import os
17+
1618
import pytest
1719
from google.adk.tools import load_memory
1820

1921
from veadk.agent import Agent
2022
from veadk.memory.long_term_memory import LongTermMemory
2123

22-
app_name = "test_ltm"
23-
user_id = "test_user"
24-
2524

2625
@pytest.mark.asyncio
2726
async def test_long_term_memory():
28-
long_term_memory = LongTermMemory(
29-
backend="local",
30-
# app_name=app_name,
31-
# user_id=user_id,
32-
)
27+
os.environ["MODEL_EMBEDDING_API_KEY"] = "mocked_api_key"
28+
long_term_memory = LongTermMemory(backend="local")
29+
3330
agent = Agent(
3431
name="all_name",
3532
model_name="test_model_name",
@@ -43,7 +40,8 @@ async def test_long_term_memory():
4340

4441
assert load_memory in agent.tools, "load_memory tool not found in agent tools"
4542

46-
assert not agent.long_term_memory._backend
43+
assert agent.long_term_memory
44+
assert agent.long_term_memory._backend
4745

4846
# assert agent.long_term_memory._backend.index == build_long_term_memory_index(
4947
# app_name, user_id

tests/test_runner.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
16+
1517
from google.genai import types
1618

1719
from veadk.agent import Agent
1820
from veadk.memory.long_term_memory import LongTermMemory
1921
from veadk.memory.short_term_memory import ShortTermMemory
20-
from veadk.runner import Runner
21-
2222

2323
# Import the standalone function instead of accessing as class method
24-
from veadk.runner import _convert_messages
24+
from veadk.runner import Runner, _convert_messages
2525

2626

2727
def _test_convert_messages(runner):
@@ -67,6 +67,8 @@ def _test_convert_messages(runner):
6767

6868
def test_runner():
6969
"""Test Runner class initialization and core properties"""
70+
os.environ["MODEL_EMBEDDING_API_KEY"] = "mocked_api_key"
71+
7072
short_term_memory = ShortTermMemory()
7173
long_term_memory = LongTermMemory(backend="local")
7274
agent = Agent(

veadk/knowledgebase/knowledgebase.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class KnowledgeBase(BaseModel):
7171
Default is `local`."""
7272

7373
backend_config: dict = Field(default_factory=dict)
74-
"""Configuration for the backend"""
74+
"""Deprecated. Configuration for the backend"""
7575

7676
top_k: int = 10
7777
"""Number of top similar documents to retrieve during search"""
@@ -96,9 +96,7 @@ def model_post_init(self, __context: Any) -> None:
9696
logger.info(
9797
f"Initializing knowledgebase: backend={self.backend} index={self.index} top_k={self.top_k}"
9898
)
99-
self._backend = _get_backend_cls(self.backend)(
100-
index=self.index, **self.backend_config if self.backend_config else {}
101-
)
99+
self._backend = _get_backend_cls(self.backend)(index=self.index)
102100
logger.info(
103101
f"Initialized knowledgebase with backend {self.backend.__class__.__name__}"
104102
)

veadk/memory/long_term_memory.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class LongTermMemory(BaseMemoryService, BaseModel):
8080
"""Long term memory backend type"""
8181

8282
backend_config: dict = Field(default_factory=dict)
83-
"""Long term memory backend configuration"""
83+
"""Deprecated. Long term memory backend configuration"""
8484

8585
top_k: int = 5
8686
"""Number of top similar documents to retrieve during search."""
@@ -104,9 +104,10 @@ def model_post_init(self, __context: Any) -> None:
104104
# Check index
105105
self.index = self.index or self.app_name
106106
if not self.index:
107-
raise ValueError(
108-
"Attribute `index` or `app_name` must be provided one of both."
107+
logger.warning(
108+
"Attribute `index` or `app_name` not provided, use `default_app` instead."
109109
)
110+
self.index = "default_app"
110111

111112
# Forward compliance
112113
if self.backend == "viking_mem":
@@ -115,9 +116,7 @@ def model_post_init(self, __context: Any) -> None:
115116
)
116117
self.backend = "viking"
117118

118-
self._backend = _get_backend_cls(self.backend)(
119-
index=self.index, **self.backend_config if self.backend_config else {}
120-
)
119+
self._backend = _get_backend_cls(self.backend)(index=self.index)
121120

122121
def _filter_and_convert_events(self, events: list[Event]) -> list[str]:
123122
final_events = []

0 commit comments

Comments
 (0)