Skip to content

Fix MCP usage in agent optimization loop#30

Open
peyron-amd wants to merge 7 commits intodevfrom
fix/mcp-essential
Open

Fix MCP usage in agent optimization loop#30
peyron-amd wants to merge 7 commits intodevfrom
fix/mcp-essential

Conversation

@peyron-amd
Copy link
Copy Markdown

@peyron-amd peyron-amd commented Mar 12, 2026

To make MCP available to and used by agent in optimization loop

  • Bridge ANTHROPIC_API_KEY and related env vars through to kernel-evolve and kernel-ercs MCP servers
  • Thread agent config (prompts, cost limits) through the orchestrator pipeline so the agent receives its configured prompt instead of the default
  • Register mutate_kernel, crossover_kernels, and get_optimization_strategies as agent-callable MCP tools
  • Add flexible MCP model selection with 4-level resolution: GEAK_MCP_MODEL env var > per-tool YAML (mcp.tools..model) > global YAML (mcp.default_model) > server hardcoded fallback (already existing)

Cherry-picked from 0ecbd17 (ck-test branch). call_llm() now supports
ANTHROPIC_API_KEY as direct Anthropic API fallback, giving a 3-tier
backend selection: AMD LLM Gateway -> direct Anthropic API -> litellm.

Without this, kernel-evolve tools fail when only ANTHROPIC_API_KEY is
available (e.g. running outside the AMD gateway).

Co-authored-by: Cursor
Same 3-tier fallback as kernel-evolve: AMD gateway -> direct Anthropic
API -> litellm. Fixes evaluate_kernel_quality and reflect_on_kernel_result
failing when only ANTHROPIC_API_KEY is set (no AMD_LLM_API_KEY).

Co-authored-by: Cursor
run_task_batch() was creating a minimal agent_config = {"save_patch": True},
discarding system_template, instance_template, cost_limit, and all other
agent settings from the merged YAML config. This meant custom configs
like commandment-config.yaml (which mandates MCP tool usage) never
reached the agent -- it always saw the default "You are a helpful
assistant that can do anything." prompt.

Add extra_agent_config parameter through:
  mini.py -> run_orchestrator() -> _run_homogeneous_orchestrator() ->
  run_task_batch() -> ParallelAgent

Co-authored-by: Cursor
These kernel-evolve MCP tools were defined on the server but not
registered in ToolRuntime or tools.json, making them invisible to the
agent. Now the agent can:
- mutate_kernel: explore variants of a promising kernel
- crossover_kernels: combine best aspects of two kernels
- get_optimization_strategies: get bottleneck-specific strategy list

Co-authored-by: Cursor
Replace hardcoded 'claude-sonnet-4.5' defaults in MCP servers with
configurable model selection via environment variable and YAML config.

Resolution order (highest to lowest priority):
  1. GEAK_MCP_MODEL env var
  2. YAML per-tool config (mcp.tools.<name>.model in geak.yaml)
  3. YAML global config (mcp.default_model in geak.yaml)
  4. Hardcoded fallback ('claude-sonnet-4.5')

Changes:
- kernel-evolve, kernel-ercs, automated-test-discovery servers: use
  _DEFAULT_MODEL = os.environ.get('GEAK_MCP_MODEL', 'claude-sonnet-4.5')
- kernel-evolve, kernel-ercs CLIs: read GEAK_MCP_MODEL for --model default
- MCPToolBridge._default_config: forward GEAK_MCP_MODEL and API keys from
  parent environment to MCP subprocess
- ToolRuntime: add mcp_config parameter, _resolve_mcp_model() for YAML
  config resolution, auto-load from geak.yaml when not provided
- geak.yaml: add commented-out mcp section with default_model and per-tool
  model override examples

Co-authored-by: Cursor
- Prerequisites: document ANTHROPIC_API_KEY as alternative to AMD gateway
- MCP Tool Servers: add Model Configuration subsection (GEAK_MCP_MODEL
  env var, YAML per-tool config, resolution order) and API Key Support
  subsection (3-tier backend: AMD gateway, Anthropic, litellm)
- Key Environment Variables: add ANTHROPIC_API_KEY, GEAK_MODEL,
  GEAK_MCP_MODEL to the table
- Branch changelog: per-commit description of all 5 fix/mcp-essential
  commits with what changed and why each is needed

Co-authored-by: Cursor
Co-authored-by: Cursor
@peyron-amd peyron-amd changed the title Fix/mcp essential Fix MCP usage Mar 12, 2026
@peyron-amd peyron-amd changed the title Fix MCP usage Fix MCP usage in agent optimization loop Mar 13, 2026
@peyron-amd peyron-amd requested a review from dongli12 March 18, 2026 09:25
@peyron-amd peyron-amd added bug Something isn't working labels Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant