Skip to content

Commit 841bb9e

Browse files
committed
fix: CI compliance — yapf formatting and flake8 for all PR files
- YAPF formatting applied across all changed Python files in the PR - Remaining flake8 E501/W391/E126/E127/E302/E999 issues resolved - All safety module tests passing (126/126)
1 parent a9dd1df commit 841bb9e

35 files changed

Lines changed: 677 additions & 408 deletions

.github/code_review/scripts/post_inline_comments.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ def main():
148148
if position is not None:
149149
target_line = end_line
150150

151-
target = "%s:%s-%s" % (path, start_line, end_line) if end_line and end_line > start_line else "%s:%s" % (path, start_line)
151+
target = "%s:%s-%s" % (path, start_line,
152+
end_line) if end_line and end_line > start_line else "%s:%s" % (path, start_line)
152153

153154
if position is None:
154155
print("skip finding without diff position: %s" % target)

examples/dynamic_subagent/agent/agent.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def create_minimal_agent() -> LlmAgent:
4848
tools=workspace_tools + [
4949
DynamicSubAgentTool(
5050
# Stream the sub-agent's execution to the parent consumer.
51-
agent_config=SubAgentConfig(forward_events=True),
52-
),
51+
agent_config=SubAgentConfig(forward_events=True), ),
5352
],
5453
)
5554

examples/dynamic_subagent/agent/config.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ def get_model_config() -> tuple[str, str, str]:
1515
url = os.getenv('TRPC_AGENT_BASE_URL', '')
1616
model_name = os.getenv('TRPC_AGENT_MODEL_NAME', '')
1717
if not api_key or not url or not model_name:
18-
raise ValueError(
19-
'TRPC_AGENT_API_KEY, TRPC_AGENT_BASE_URL, and '
20-
'TRPC_AGENT_MODEL_NAME must be set in environment variables'
21-
)
18+
raise ValueError('TRPC_AGENT_API_KEY, TRPC_AGENT_BASE_URL, and '
19+
'TRPC_AGENT_MODEL_NAME must be set in environment variables')
2220
return api_key, url, model_name

examples/dynamic_subagent/run_agent.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ async def run_demo(mode: str):
120120
user_content = Content(parts=[Part.from_text(text=query)])
121121
print("\U0001F916 Assistant: ", end="", flush=True)
122122
async for event in runner.run_async(
123-
user_id=user_id,
124-
session_id=current_session_id,
125-
new_message=user_content,
123+
user_id=user_id,
124+
session_id=current_session_id,
125+
new_message=user_content,
126126
):
127127
# Forwarded sub-agent execution events (SubAgentConfig
128128
# forward_events=True). These are partial progress events carrying
@@ -146,15 +146,11 @@ async def run_demo(mode: str):
146146
if part.thought:
147147
continue
148148
if part.function_call:
149-
print(
150-
f"\n\n\U0001F527 [Invoke Tool:: {part.function_call.name}"
151-
f"{_truncate(part.function_call.args)}]\n"
152-
)
149+
print(f"\n\n\U0001F527 [Invoke Tool:: {part.function_call.name}"
150+
f"{_truncate(part.function_call.args)}]\n")
153151
elif part.function_response:
154-
print(
155-
f"\n\U0001F4CA [Tool Result: "
156-
f"{_truncate(part.function_response.response)}]\n"
157-
)
152+
print(f"\n\U0001F4CA [Tool Result: "
153+
f"{_truncate(part.function_response.response)}]\n")
158154

159155
print(f"\n{'─' * 60}\n")
160156

@@ -164,7 +160,9 @@ async def run_demo(mode: str):
164160
if __name__ == "__main__":
165161
parser = argparse.ArgumentParser(description="DynamicSubAgentTool demo")
166162
parser.add_argument(
167-
"--mode", choices=["minimal", "bounded"], default="minimal",
163+
"--mode",
164+
choices=["minimal", "bounded"],
165+
default="minimal",
168166
help="minimal: workspace tools + dynamic_subagent; bounded: only dynamic_subagent",
169167
)
170168
args = parser.parse_args()

examples/goal_tools/agent/agent.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,12 @@ def _create_model() -> LLMModel:
2929
def on_retry(event: RetryEvent) -> None:
3030
"""Observability callback: called every time the retry intercepts a premature final."""
3131
if event.reason == "blocked":
32-
print(
33-
f" ⚡ [Goal retry] Premature final intercepted "
34-
f"(attempt {event.attempt_number}/{event.max_retries}). "
35-
f"Objective: {event.goal.objective!r}"
36-
)
32+
print(f" ⚡ [Goal retry] Premature final intercepted "
33+
f"(attempt {event.attempt_number}/{event.max_retries}). "
34+
f"Objective: {event.goal.objective!r}")
3735
else:
38-
print(
39-
f" ⚠️ [Goal retry] Budget exhausted ({event.max_retries} retries). "
40-
f"Letting final response through."
41-
)
36+
print(f" ⚠️ [Goal retry] Budget exhausted ({event.max_retries} retries). "
37+
f"Letting final response through.")
4238

4339

4440
def create_goal_agent(work_dir: str | None = None) -> LlmAgent:

examples/goal_tools/agent/config.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ def get_model_config() -> tuple[str, str, str]:
1414
url = os.getenv("TRPC_AGENT_BASE_URL", "")
1515
model_name = os.getenv("TRPC_AGENT_MODEL_NAME", "")
1616
if not api_key or not url or not model_name:
17-
raise ValueError(
18-
"TRPC_AGENT_API_KEY, TRPC_AGENT_BASE_URL, and TRPC_AGENT_MODEL_NAME "
19-
"must be set in environment variables"
20-
)
17+
raise ValueError("TRPC_AGENT_API_KEY, TRPC_AGENT_BASE_URL, and TRPC_AGENT_MODEL_NAME "
18+
"must be set in environment variables")
2119
return api_key, url, model_name

examples/goal_tools/agent/prompts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
"""Prompts for the Goal tools demo agent."""
77

88
INSTRUCTION = """You are a rigorous engineering assistant that can work toward session goals. """
9-

examples/goal_tools/run_agent.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
APP_NAME = "goal_agent_demo"
4848
USER_ID = "demo_user"
4949

50-
5150
# ---------------------------------------------------------------------------
5251
# Shared helpers
5352
# ---------------------------------------------------------------------------
5453

54+
5555
def _summarise_tool_response(name: str, resp: object) -> str:
5656
if not isinstance(resp, dict):
5757
return str(resp)
@@ -97,14 +97,14 @@ async def _run_turn(
9797
# Tool calls/responses arrive as non-partial events and are printed immediately.
9898
# Model text may arrive as streaming partial chunks; we fall back to partial
9999
# collection so pure-text responses are always visible.
100-
streaming_text: list[str] = [] # accumulated from partial text chunks
101-
final_text: list[str] = [] # text from the last non-partial event
100+
streaming_text: list[str] = [] # accumulated from partial text chunks
101+
final_text: list[str] = [] # text from the last non-partial event
102102

103103
user_content = Content(parts=[Part.from_text(text=query)])
104104
async for event in runner.run_async(
105-
user_id=USER_ID,
106-
session_id=session_id,
107-
new_message=user_content,
105+
user_id=USER_ID,
106+
session_id=session_id,
107+
new_message=user_content,
108108
):
109109
if not event.content or not event.content.parts:
110110
continue
@@ -213,17 +213,13 @@ async def case1_model_sets_goal(work_dir: str) -> None:
213213
# 目标与 prompt 差异化,观察模型是否能够正确理解目标并执行任务
214214
"在当前目录创建 notes/ 目录,其中包含两个文件:\n"
215215
" - summary.txt:用三句话描述 Python 异步编程的核心概念\n"
216-
" - example.py:一个可运行的 asyncio 示例(包含 main 协程和 asyncio.run 调用)"
217-
)
216+
" - example.py:一个可运行的 asyncio 示例(包含 main 协程和 asyncio.run 调用)")
218217

219-
CASE2_TURNS = [
220-
(
221-
"执行任务(用户设置目标)",
222-
# 宿主已通过 start_goal() 设置了目标,消息里不提及任何 goal 工具。
223-
"请在当前目录创建 notes/ 目录,在其中写文件:\n"
224-
"summary.txt:用三句话描述 Python 异步编程的核心概念\n"
225-
)
226-
]
218+
CASE2_TURNS = [(
219+
"执行任务(用户设置目标)",
220+
# 宿主已通过 start_goal() 设置了目标,消息里不提及任何 goal 工具。
221+
"请在当前目录创建 notes/ 目录,在其中写文件:\n"
222+
"summary.txt:用三句话描述 Python 异步编程的核心概念\n")]
227223

228224

229225
async def case2_user_sets_goal(work_dir: str) -> None:
@@ -270,10 +266,8 @@ async def case2_user_sets_goal(work_dir: str) -> None:
270266
print(f"🎯 Goal pre-injected by host:")
271267
print(f" objective: {goal.objective!r}")
272268
print(f" status: {goal.status.value}")
273-
print(
274-
"\n📌 Note: goal is active from the first token.\n"
275-
" The agent does NOT call create_goal.\n"
276-
)
269+
print("\n📌 Note: goal is active from the first token.\n"
270+
" The agent does NOT call create_goal.\n")
277271

278272
for label, query in CASE2_TURNS:
279273
await _run_turn(runner, session_id=session_id, label=label, query=query, agent_name=agent.name)
@@ -285,6 +279,7 @@ async def case2_user_sets_goal(work_dir: str) -> None:
285279
# Entry point
286280
# ---------------------------------------------------------------------------
287281

282+
288283
async def main() -> None:
289284
work_dir = os.getcwd()
290285
await case1_model_sets_goal(work_dir)

examples/spawn_subagent/agent/agent.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,27 @@ def create_default_agent() -> LlmAgent:
5353
description="Coding assistant with spawn_subagent in zero-config mode.",
5454
model=_create_model(),
5555
instruction=INSTRUCTION,
56-
tools=[ReadTool(), GlobTool(), GrepTool(),
57-
SpawnSubAgentTool(
58-
# Stream the sub-agent's execution to the parent consumer.
59-
agent_config=SubAgentConfig(forward_events=True),
60-
)],
56+
tools=[
57+
ReadTool(),
58+
GlobTool(),
59+
GrepTool(),
60+
SpawnSubAgentTool(
61+
# Stream the sub-agent's execution to the parent consumer.
62+
agent_config=SubAgentConfig(forward_events=True), )
63+
],
6164
)
6265

6366

6467
_SECURITY_AUDITOR = SubAgentArchetype(
6568
name="security-auditor",
66-
description=(
67-
"Specialized security auditor for code vulnerability analysis. "
68-
"Use this for ANY security-related task: code audits, secret "
69-
"detection, auth review. Checks for OWASP Top 10 risks, CWE "
70-
"patterns, rates severity, and produces structured reports."
71-
),
72-
instruction=(
73-
"You are a security auditor. Review the relevant code for security "
74-
"issues: injection risks, hardcoded secrets, unsafe API usage, "
75-
"missing authentication/authorization checks. Report findings "
76-
"concisely with severity (low/medium/high/critical). Do NOT modify files."
77-
),
69+
description=("Specialized security auditor for code vulnerability analysis. "
70+
"Use this for ANY security-related task: code audits, secret "
71+
"detection, auth review. Checks for OWASP Top 10 risks, CWE "
72+
"patterns, rates severity, and produces structured reports."),
73+
instruction=("You are a security auditor. Review the relevant code for security "
74+
"issues: injection risks, hardcoded secrets, unsafe API usage, "
75+
"missing authentication/authorization checks. Report findings "
76+
"concisely with severity (low/medium/high/critical). Do NOT modify files."),
7877
tools=(ReadTool, GlobTool, GrepTool),
7978
)
8079

@@ -92,7 +91,9 @@ def create_code_agent() -> LlmAgent:
9291
model=_create_model(),
9392
instruction=INSTRUCTION,
9493
tools=[
95-
ReadTool(), GlobTool(), GrepTool(),
94+
ReadTool(),
95+
GlobTool(),
96+
GrepTool(),
9697
SpawnSubAgentTool(
9798
agents=[_SECURITY_AUDITOR, EXPLORE_AGENT, PLAN_AGENT],
9899
# Stream the sub-agent's execution to the parent consumer.
@@ -117,9 +118,12 @@ def create_md_agent() -> LlmAgent:
117118
model=_create_model(),
118119
instruction=INSTRUCTION,
119120
tools=[
120-
ReadTool(), GlobTool(), GrepTool(),
121+
ReadTool(),
122+
GlobTool(),
123+
GrepTool(),
121124
SpawnSubAgentTool(
122-
agents=[EXPLORE_AGENT, PLAN_AGENT], agent_paths=[_AGENTS_PATH],
125+
agents=[EXPLORE_AGENT, PLAN_AGENT],
126+
agent_paths=[_AGENTS_PATH],
123127
# Stream the sub-agent's execution to the parent consumer.
124128
agent_config=SubAgentConfig(forward_events=True),
125129
),

examples/spawn_subagent/agent/config.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ def get_model_config() -> tuple[str, str, str]:
1515
url = os.getenv('TRPC_AGENT_BASE_URL', '')
1616
model_name = os.getenv('TRPC_AGENT_MODEL_NAME', '')
1717
if not api_key or not url or not model_name:
18-
raise ValueError(
19-
'TRPC_AGENT_API_KEY, TRPC_AGENT_BASE_URL, and '
20-
'TRPC_AGENT_MODEL_NAME must be set in environment variables'
21-
)
18+
raise ValueError('TRPC_AGENT_API_KEY, TRPC_AGENT_BASE_URL, and '
19+
'TRPC_AGENT_MODEL_NAME must be set in environment variables')
2220
return api_key, url, model_name

0 commit comments

Comments
 (0)