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
41 lines (32 loc) · 1.21 KB
/
Copy pathagent.py
File metadata and controls
41 lines (32 loc) · 1.21 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
# 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 .config import get_model_config
from .prompts import INSTRUCTION
from .tools import StdioMCPToolset
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 MCP tools"""
# Uncomment ONE of the following lines to match the transport mode in mcp_server.py:
mcp_toolset = StdioMCPToolset()
# mcp_toolset = SseMCPToolset()
# mcp_toolset = StreamableHttpMCPToolset()
agent = LlmAgent(
name="mcp_assistant",
description="An assistant that uses MCP tools for weather and calculation",
model=_create_model(),
instruction=INSTRUCTION,
tools=[mcp_toolset],
)
return agent
root_agent = create_agent()