-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathagent.py
More file actions
48 lines (38 loc) · 1.53 KB
/
agent.py
File metadata and controls
48 lines (38 loc) · 1.53 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
# 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 FunctionTool
from trpc_agent_sdk.tools import get_tool
from .config import get_model_config
from .prompts import INSTRUCTION
from .tools import calculate
from .tools import get_postal_code
from .tools import get_weather
def _create_model() -> LLMModel:
"""Create a model"""
api_key, url, model_name = get_model_config()
return OpenAIModel(model_name=model_name, api_key=api_key, base_url=url)
def create_agent() -> LlmAgent:
"""Create an agent with function tools.
Tools are created in two ways:
- FunctionTool wrapping: get_weather, calculate, get_postal_code
- Registry lookup: get_session_info (registered via @register_tool)
"""
weather_tool = FunctionTool(get_weather)
calculate_tool = FunctionTool(calculate)
postal_code_tool = FunctionTool(get_postal_code)
session_tool = get_tool("get_session_info")
return LlmAgent(
name="function_tool_demo_agent",
description="An assistant demonstrating FunctionTool usage",
model=_create_model(),
instruction=INSTRUCTION,
tools=[weather_tool, calculate_tool, postal_code_tool, session_tool],
)
root_agent = create_agent()