Skip to content

Commit 70fdefd

Browse files
committed
fix(agent): bootstrap latency caused by litellm network request
1 parent 31c4996 commit 70fdefd

File tree

4 files changed

+15
-63
lines changed

4 files changed

+15
-63
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "veadk-python"
3-
version = "0.2.20"
3+
version = "0.2.21"
44
description = "Volcengine agent development kit, integrations with Volcengine cloud services."
55
readme = "README.md"
66
requires-python = ">=3.10"

veadk/agent.py

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from google.adk.agents.base_agent import BaseAgent
2222
from google.adk.agents.llm_agent import InstructionProvider, ToolUnion
2323
from google.adk.agents.run_config import StreamingMode
24-
from google.adk.models.lite_llm import LiteLlm
2524
from google.adk.runners import Runner
2625
from google.genai import types
2726
from pydantic import ConfigDict, Field
@@ -71,62 +70,6 @@ class Agent(LlmAgent):
7170
short_term_memory (Optional[ShortTermMemory]): Session-based memory for temporary context.
7271
long_term_memory (Optional[LongTermMemory]): Cross-session memory for persistent user context.
7372
tracers (list[BaseTracer]): List of tracers used for telemetry and monitoring.
74-
75-
Notes:
76-
Before creating your agent, you should get the API Key for your model.
77-
78-
Examples:
79-
### Simple agent
80-
81-
Create a simplest agent without any extra settings. All agent attributes are come from environment variables and default values. Like:
82-
83-
```python
84-
import asyncio
85-
86-
from veadk import Agent, Runner
87-
88-
root_agent = Agent()
89-
90-
runner = Runner(agent=root_agent)
91-
92-
response = asyncio.run(runner.run("hello"))
93-
print(response)
94-
```
95-
96-
You can set some agent metadata attributes by the following code:
97-
98-
```python
99-
from veadk import Agent
100-
101-
from veadk import Agent, Runner
102-
103-
root_agent = Agent(
104-
name="meeting_assistant",
105-
description="An assistant that helps user to make meetings.",
106-
# system prompt
107-
instruction="First learn about user's meeting time, location, and other key informations, and give out a meeting plan.",
108-
)
109-
```
110-
111-
Or, once you want to use your local-serving model or models from other provider, you can specify some model-related configurations in initiation arguments:
112-
113-
```python
114-
agent = Agent(model_name="", model_api_key="", model_api_base="")
115-
```
116-
117-
Besides, you can specify some extra options by ARK requirements, such as:
118-
119-
```python
120-
# disable thinking
121-
model_extra_config = {}
122-
```
123-
124-
In some systems, mulitple-agent based design is necessary, you can implement a multiple-agent system by `sub_agent` argument:
125-
126-
```python
127-
from veadk import Agent
128-
```
129-
13073
"""
13174

13275
model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
@@ -198,6 +141,14 @@ def model_post_init(self, __context: Any) -> None:
198141
logger.info(f"Model extra config: {self.model_extra_config}")
199142

200143
if not self.model:
144+
# If user didn't set LITELLM_LOCAL_MODEL_COST_MAP, set it to True
145+
# to enable local model cost map.
146+
# This value is `false` by default, which brings heavy performance burden,
147+
# for instance, about 10s latency.
148+
if not os.getenv("LITELLM_LOCAL_MODEL_COST_MAP"):
149+
os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
150+
from google.adk.models.lite_llm import LiteLlm
151+
201152
self.model = LiteLlm(
202153
model=f"{self.model_provider}/{self.model_name}",
203154
api_key=self.model_api_key,
@@ -227,9 +178,10 @@ def model_post_init(self, __context: Any) -> None:
227178
if self.long_term_memory is not None:
228179
from google.adk.tools import load_memory
229180

230-
if not load_memory.custom_metadata:
231-
load_memory.custom_metadata = {}
232-
load_memory.custom_metadata["backend"] = self.long_term_memory.backend
181+
if hasattr(load_memory, "custom_metadata"):
182+
if not load_memory.custom_metadata:
183+
load_memory.custom_metadata = {}
184+
load_memory.custom_metadata["backend"] = self.long_term_memory.backend
233185
self.tools.append(load_memory)
234186

235187
logger.info(f"VeADK version: {VERSION}")

veadk/tracing/telemetry/exporters/apmplus_exporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def record_tool_call(
402402
operation_type = "tool"
403403
operation_name = tool.name
404404
operation_backend = ""
405-
if tool.custom_metadata:
405+
if hasattr(tool, "custom_metadata") and tool.custom_metadata:
406406
operation_backend = tool.custom_metadata.get("backend", "")
407407

408408
attributes = {

veadk/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
VERSION = "0.2.20"
15+
VERSION = "0.2.21"

0 commit comments

Comments
 (0)