-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathagent.py
More file actions
72 lines (59 loc) · 2.08 KB
/
Copy pathagent.py
File metadata and controls
72 lines (59 loc) · 2.08 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.
"""CodeReviewAgent — LlmAgent for the code review pipeline.
Wraps the existing review_agent.run_review() pipeline as a FunctionTool,
enabling interactive multi-turn code review sessions via A2A or AG-UI.
"""
from __future__ import annotations
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 load_memory_tool
from .config import get_model_config
from .prompts import INSTRUCTION
from .tools import run_code_review_tool
# Try to load the knowledge search tool; gracefully handle missing deps
_knowledge_tool = None
try:
from ..knowledge import knowledge_search_tool as _kst
_knowledge_tool = _kst
except ImportError:
pass
def _create_model() -> LLMModel:
"""Create a model instance from environment variables."""
api_key, base_url, model_name = get_model_config()
return OpenAIModel(
model_name=model_name,
api_key=api_key,
base_url=base_url,
)
def create_agent() -> LlmAgent:
"""Create the CodeReviewAgent.
The agent wraps the existing review_agent.run_review() pipeline
as a FunctionTool, allowing the LLM to invoke it when the user
provides a diff for review.
Returns:
A configured LlmAgent instance.
"""
return LlmAgent(
name="CodeReviewAgent",
description=(
"A professional code review assistant that analyzes code changes, "
"detects security risks, resource leaks, and other issues, "
"and generates structured review reports."
),
model=_create_model(),
instruction=INSTRUCTION,
tools=[
run_code_review_tool,
load_memory_tool,
_knowledge_tool,
] if _knowledge_tool else [
run_code_review_tool,
load_memory_tool,
],
)
root_agent = create_agent()