forked from trpc-group/trpc-agent-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
43 lines (35 loc) · 1.36 KB
/
Copy pathagent.py
File metadata and controls
43 lines (35 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Tencent is pleased to support the open source community by making tRPC-Agent-Python available.
#
# Copyright (C) 2026 Tencent. All rights reserved.
#
# tRPC-Agent-Python is licensed under Apache-2.0.
"""Agent module for the model retry example."""
from trpc_agent_sdk.agents import LlmAgent
from trpc_agent_sdk.models import LLMModel
from trpc_agent_sdk.models import OpenAIModel
from trpc_agent_sdk.tools import FunctionTool
from .config import get_model_config
from .config import get_model_retry_config
from .prompts import INSTRUCTION
from .tools import get_weather_report
def _create_model() -> LLMModel:
"""Create an OpenAI-compatible model with SDK-managed retry enabled."""
api_key, base_url, model_name = get_model_config()
retry_config = get_model_retry_config()
print(f"Model retry enabled: {retry_config.model_dump()}")
return OpenAIModel(
model_name=model_name,
api_key=api_key,
base_url=base_url,
model_retry_config=retry_config,
)
def create_agent() -> LlmAgent:
"""Create a weather agent that uses model-level retry."""
return LlmAgent(
name="weather_retry_agent",
description="A weather assistant with SDK-managed model retry enabled.",
model=_create_model(),
instruction=INSTRUCTION,
tools=[FunctionTool(get_weather_report)],
)
root_agent = create_agent()