-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathagent.py
More file actions
55 lines (44 loc) · 1.83 KB
/
Copy pathagent.py
File metadata and controls
55 lines (44 loc) · 1.83 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
# 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"""
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 LongRunningFunctionTool
from .config import get_model_config
from .prompts import MAIN_AGENT_INSTRUCTION
from .prompts import SUB_AGENT_INSTRUCTION
from .tools import check_system_critical_operation
from .tools import human_approval_required
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() -> LlmAgent:
""" Create an agent with long-running function tools and sub-agents"""
model = _create_model()
approval_tool = LongRunningFunctionTool(human_approval_required)
critical_operation_tool = LongRunningFunctionTool(check_system_critical_operation)
system_operations_agent = LlmAgent(
name="system_operations_agent",
model=model,
description="System operations specialist that handles critical operations requiring human approval",
instruction=SUB_AGENT_INSTRUCTION,
tools=[critical_operation_tool],
disallow_transfer_to_parent=True,
output_key="system_ops_result",
)
agent = LlmAgent(
name="human_in_loop_agent",
description="Agent demonstrating long-running tools with human-in-the-loop and sub-agents",
model=model,
instruction=MAIN_AGENT_INSTRUCTION,
tools=[approval_tool],
sub_agents=[system_operations_agent],
)
return agent
root_agent = create_agent()