Skip to content

Commit 6900faf

Browse files
refactor: remove explanation subagent and implement dynamic thinking level configuration for agents
1 parent fbf3c70 commit 6900faf

10 files changed

Lines changed: 29 additions & 157 deletions

File tree

MaxKernel/auto_agent/config.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@
2020
top_k=TOP_K,
2121
)
2222

23-
# Planner configuration with thinking/reasoning traces
24-
thinking_planner = BuiltInPlanner(
25-
thinking_config=types.ThinkingConfig(
26-
include_thoughts=INCLUDE_THOUGHTS,
27-
thinking_level="high",
23+
24+
def get_thinking_planner(level: str = "high") -> BuiltInPlanner:
25+
"""Returns a BuiltInPlanner configured with the specified thinking level.
26+
27+
Args:
28+
level: The thinking level to use. Can be 'high', 'medium', or 'low'.
29+
"""
30+
return BuiltInPlanner(
31+
thinking_config=types.ThinkingConfig(
32+
include_thoughts=INCLUDE_THOUGHTS,
33+
thinking_level=level,
34+
)
2835
)
29-
)

MaxKernel/auto_agent/subagents/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
- kernel_writing: Planning, implementation, and compilation validation
55
- testing: Test generation, validation, and execution
66
- profiling: Performance profiling and analysis
7-
- explanation: Explanations for the kernel generation process
87
"""
98

10-
from . import explanation, kernel_writing, profiling, testing
9+
from . import kernel_writing, profiling, testing
1110

1211
__all__ = [
1312
"kernel_writing",
1413
"testing",
1514
"profiling",
16-
"explanation",
1715
]

MaxKernel/auto_agent/subagents/autotuning/agent.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from google.adk.agents.invocation_context import InvocationContext
1010
from google.adk.events import Event, EventActions
1111

12-
from auto_agent.config import model_config, thinking_planner
12+
from auto_agent.config import get_thinking_planner, model_config
1313
from auto_agent.constants import MODEL_NAME
1414
from auto_agent.custom_types import CustomLlmAgent
1515
from auto_agent.subagents.autotuning.autotune_tool import autotune_kernel
@@ -32,7 +32,7 @@
3232
name="AutotunePlannerAgent",
3333
model=MODEL_NAME,
3434
generate_content_config=model_config,
35-
planner=thinking_planner,
35+
planner=get_thinking_planner("high"),
3636
instruction=autotune_prompt.PROMPT,
3737
description="Prepares code template and search space for auto-tuning Pallas kernels.",
3838
tools=[filesystem_tool_r, write_autotune_specs_tool, search_api_tool],
@@ -165,7 +165,7 @@ async def _run_async_impl(
165165
name="ApplyBestConfigAgent",
166166
model=MODEL_NAME,
167167
generate_content_config=model_config,
168-
planner=thinking_planner,
168+
planner=get_thinking_planner("high"),
169169
instruction=apply_best_config_prompt.PROMPT,
170170
description="Applies autotuning results to the optimized kernel file.",
171171
tools=[filesystem_tool_r, write_optimized_kernel_tool],
@@ -178,7 +178,6 @@ async def _run_async_impl(
178178
name="AutotuneSummaryAgent",
179179
model=MODEL_NAME,
180180
generate_content_config=model_config,
181-
planner=thinking_planner,
182181
instruction=summary_prompt.PROMPT,
183182
description="Summarizes autotuning results.",
184183
tools=[filesystem_tool_r],

MaxKernel/auto_agent/subagents/explanation/__init__.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

MaxKernel/auto_agent/subagents/explanation/agent.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

MaxKernel/auto_agent/subagents/explanation/prompts/__init__.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

MaxKernel/auto_agent/subagents/explanation/prompts/explanation_prompt.py

Lines changed: 0 additions & 76 deletions
This file was deleted.

MaxKernel/auto_agent/subagents/kernel_writing/agent.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
load_kernel_and_plan_to_state,
1616
load_single_kernel_to_state,
1717
)
18-
from auto_agent.config import model_config, thinking_planner
18+
from auto_agent.config import get_thinking_planner, model_config
1919
from auto_agent.constants import MODEL_NAME
2020
from auto_agent.custom_types import CustomLlmAgent
2121
from auto_agent.subagents.kernel_writing.kernel_compilation import (
@@ -267,7 +267,7 @@ async def _run_async_impl(
267267
name="PlanKernelAgent",
268268
model=MODEL_NAME,
269269
generate_content_config=model_config,
270-
planner=thinking_planner,
270+
planner=get_thinking_planner("high"),
271271
instruction=kernel_planning_prompt.PROMPT,
272272
description="Creates or revises a detailed optimization plan for a Pallas kernel.",
273273
tools=(
@@ -287,7 +287,6 @@ async def _run_async_impl(
287287
name="ReadFileForValidationAgent",
288288
model=MODEL_NAME,
289289
generate_content_config=model_config,
290-
planner=thinking_planner,
291290
instruction=read_file_prompt.PROMPT,
292291
description="Reads the kernel file mentioned by the user or from state for validation.",
293292
tools=[filesystem_tool_r],
@@ -297,7 +296,7 @@ async def _run_async_impl(
297296
name="FixKernelCompilationAgent",
298297
model=MODEL_NAME,
299298
generate_content_config=model_config,
300-
planner=thinking_planner,
299+
planner=get_thinking_planner("high"),
301300
instruction=fix_kernel_compilation.PROMPT,
302301
description="Fixes compilation errors in the generated kernel while preserving optimization strategy.",
303302
tools=(
@@ -319,7 +318,7 @@ async def _run_async_impl(
319318
name="AddDebugStatementsAgent",
320319
model=MODEL_NAME,
321320
generate_content_config=model_config,
322-
planner=thinking_planner,
321+
planner=get_thinking_planner("medium"),
323322
instruction=add_debug_statements.PROMPT,
324323
description="Adds strategic debugging statements to diagnose persistent compilation issues.",
325324
tools=[filesystem_tool_r, write_optimized_kernel_tool],
@@ -331,7 +330,7 @@ async def _run_async_impl(
331330
name="CleanupDebugStatementsAgent",
332331
model=MODEL_NAME,
333332
generate_content_config=model_config,
334-
planner=thinking_planner,
333+
planner=get_thinking_planner("low"),
335334
instruction=cleanup_debug_statements.PROMPT,
336335
description="Removes debugging statements from successfully compiled kernel.",
337336
tools=[filesystem_tool_r, write_optimized_kernel_tool],
@@ -358,7 +357,6 @@ async def _run_async_impl(
358357
name="KernelCompilationSummaryAgent",
359358
model=MODEL_NAME,
360359
generate_content_config=model_config,
361-
planner=thinking_planner,
362360
instruction=kernel_compilation_summary.PROMPT,
363361
description="Summarizes kernel compilation validation results with full trace on failure.",
364362
include_contents="none",
@@ -379,7 +377,7 @@ async def _run_async_impl(
379377
name="ImplementKernelAgent",
380378
model=MODEL_NAME,
381379
generate_content_config=model_config,
382-
planner=thinking_planner,
380+
planner=get_thinking_planner("high"),
383381
instruction=kernel_implementation_prompt.PROMPT,
384382
description="Implements the optimized Pallas kernel following the plan.",
385383
tools=(

MaxKernel/auto_agent/subagents/profiling/agent.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
load_profiling_script_to_state,
1212
load_single_kernel_to_state,
1313
)
14-
from auto_agent.config import model_config, thinking_planner
14+
from auto_agent.config import get_thinking_planner, model_config
1515
from auto_agent.constants import MODEL_NAME
1616
from auto_agent.custom_types import CustomLlmAgent
1717
from auto_agent.subagents.profiling import offline_tools
@@ -32,7 +32,7 @@
3232
name="GenerateProfilingScriptAgent",
3333
model=MODEL_NAME,
3434
generate_content_config=model_config,
35-
planner=thinking_planner,
35+
planner=get_thinking_planner("medium"),
3636
instruction=gen_profiling_script.PROMPT,
3737
description="Generates a profiling script to identify performance bottlenecks in the kernel code and writes it to a file.",
3838
tools=[filesystem_tool_r, write_profiling_script_tool],
@@ -44,7 +44,6 @@
4444
name="ReadProfilingScriptAgent",
4545
model=MODEL_NAME,
4646
generate_content_config=model_config,
47-
planner=thinking_planner,
4847
instruction=read_profiling_script_prompt.PROMPT,
4948
description="Loads the generated profiling script file contents from disk into memory for execution.",
5049
before_agent_callback=load_profiling_script_to_state,
@@ -110,7 +109,7 @@ async def _run_async_impl(
110109
name="SummarizeProfileAgent",
111110
model=MODEL_NAME,
112111
generate_content_config=model_config,
113-
planner=thinking_planner,
112+
planner=get_thinking_planner("high"),
114113
instruction=analyze_profile_prompt.PROMPT,
115114
description=(
116115
"Summarizes the profiling results of the kernel and performs deep"

MaxKernel/auto_agent/subagents/testing/agent.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from google.adk.events import Event, EventActions
1717

1818
from auto_agent.client_utils.eval_client import call_eval_server_async
19-
from auto_agent.config import model_config, thinking_planner
19+
from auto_agent.config import get_thinking_planner, model_config
2020
from auto_agent.constants import EVAL_SERVER_PORT, MODEL_NAME, REQUEST_TIMEOUT
2121
from auto_agent.custom_types import CustomLlmAgent
2222
from auto_agent.subagents.testing.prompts import (
@@ -860,7 +860,6 @@ async def _run_async_impl(
860860
name="ValidationSummaryAgent",
861861
model=MODEL_NAME,
862862
generate_content_config=model_config,
863-
planner=thinking_planner,
864863
instruction=validation_summary.PROMPT,
865864
description="Summarizes validation results and provides next steps to the user.",
866865
)
@@ -870,7 +869,7 @@ async def _run_async_impl(
870869
name="GenerateTestFileAgent",
871870
model=MODEL_NAME,
872871
generate_content_config=model_config,
873-
planner=thinking_planner,
872+
planner=get_thinking_planner("high"),
874873
instruction=gen_test_file.PROMPT,
875874
description="Generates a comprehensive pytest test file.",
876875
tools=(
@@ -914,7 +913,7 @@ async def _run_async_impl(
914913
name="FixTestScriptAgent",
915914
model=MODEL_NAME,
916915
generate_content_config=model_config,
917-
planner=thinking_planner,
916+
planner=get_thinking_planner("high"),
918917
instruction=fix_test_script.PROMPT,
919918
description="Fixes validation errors in the generated test file.",
920919
tools=[filesystem_tool_r, write_test_file_tool, search_api_tool],
@@ -954,7 +953,7 @@ async def _run_async_impl(
954953
name="SummarizeTestResultsAgent",
955954
model=MODEL_NAME,
956955
generate_content_config=model_config,
957-
planner=thinking_planner,
956+
planner=get_thinking_planner("medium"),
958957
instruction=summarize_test_results_prompt.PROMPT,
959958
description="Analyzes pytest test results and provides recommendations.",
960959
tools=(

0 commit comments

Comments
 (0)