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
72 lines (58 loc) · 2.25 KB
/
Copy pathagent.py
File metadata and controls
72 lines (58 loc) · 2.25 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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.
"""Multi-agent setup demonstrating start_from_last_agent feature."""
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 .prompts import COORDINATOR_INSTRUCTION
from .prompts import SALES_INSTRUCTION
from .prompts import TECHNICAL_INSTRUCTION
from .tools import check_device_status
from .tools import get_product_info
def _create_model() -> LLMModel:
"""Create a model."""
api_key, url, model_name = get_model_config()
model = OpenAIModel(model_name=model_name, api_key=api_key, base_url=url)
return model
def create_agent():
"""Create a multi-agent customer service system.
This system demonstrates the start_from_last_agent feature:
- Coordinator routes initial requests to specialists
- With start_from_last_agent=True, follow-up questions go directly
to the last active specialist instead of back to the coordinator
"""
model = _create_model()
# Sales consultant sub-agent
sales_agent = LlmAgent(
name="sales_consultant",
model=model,
description="Sales consultant for product information and pricing",
instruction=SALES_INSTRUCTION,
tools=[FunctionTool(get_product_info)],
output_key="sales_result",
)
# Technical support sub-agent
technical_agent = LlmAgent(
name="technical_support",
model=model,
description="Technical support specialist for troubleshooting",
instruction=TECHNICAL_INSTRUCTION,
tools=[FunctionTool(check_device_status)],
output_key="technical_result",
)
# Coordinator (root agent)
coordinator = LlmAgent(
name="coordinator",
model=model,
description="Customer service coordinator that routes inquiries",
instruction=COORDINATOR_INSTRUCTION,
sub_agents=[sales_agent, technical_agent],
output_key="coordinator_result",
)
return coordinator
root_agent = create_agent()