Skip to content

Commit d98821c

Browse files
fix(agent): bootstrap latency caused by litellm network request (#293)
* fix(agent): bootstrap latency caused by litellm network request * fix test error * move import litellm to header * restore test
1 parent 31c4996 commit d98821c

File tree

4 files changed

+14
-62
lines changed

4 files changed

+14
-62
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: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
import os
1818
from typing import Optional, Union
1919

20+
# If user didn't set LITELLM_LOCAL_MODEL_COST_MAP, set it to True
21+
# to enable local model cost map.
22+
# This value is `false` by default, which brings heavy performance burden,
23+
# for instance, importing `Litellm` needs about 10s latency.
24+
if not os.getenv("LITELLM_LOCAL_MODEL_COST_MAP"):
25+
os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
26+
2027
from google.adk.agents import LlmAgent, RunConfig
2128
from google.adk.agents.base_agent import BaseAgent
2229
from google.adk.agents.llm_agent import InstructionProvider, ToolUnion
@@ -71,62 +78,6 @@ class Agent(LlmAgent):
7178
short_term_memory (Optional[ShortTermMemory]): Session-based memory for temporary context.
7279
long_term_memory (Optional[LongTermMemory]): Cross-session memory for persistent user context.
7380
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-
13081
"""
13182

13283
model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
@@ -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)