The world's first agentic reverse engineer.
feat: add _get_effective_limits for custom model limit overrides
Amruth226bff7e9aa3
diff --git a/kong/agent/supervisor.py b/kong/agent/supervisor.pyindex 25d3c50..6bd7663 100644--- a/kong/agent/supervisor.py+++ b/kong/agent/supervisor.py@@ -18,12 +18,12 @@ from kong.agent.queue import WorkItem, WorkQueuefrom kong.agent.signatures import SignatureDBfrom kong.agent.triage import TriageAgent, TriageResultfrom kong.agent.type_recovery import StructAccumulator, apply_unified_structs-from kong.config import KongConfig+from kong.config import KongConfig, LLMProviderfrom kong.export.source import ExportData, export_sourcefrom kong.export.structured import export_jsonfrom kong.ghidra.client import GhidraClientfrom kong.ghidra.types import BinaryInfo, FunctionInfo, StringEntry-from kong.llm.limits import get_model_limits+from kong.llm.limits import ModelLimits, get_model_limitsfrom kong.llm.usage import TokenUsagefrom kong.normalizer.syntactic import normalizefrom kong.synthesis.semantic import SemanticSynthesizer, SynthesisResult@@ -295,6 +295,17 @@ class Supervisor:),))+ def _get_effective_limits(self) -> ModelLimits:+ cfg = self.config.llm+ base = get_model_limits(getattr(self.llm_client, "model", "") or "")+ if cfg.provider is not LLMProvider.CUSTOM:+ return base+ return ModelLimits(+ max_prompt_chars=cfg.max_prompt_chars or base.max_prompt_chars,+ max_chunk_functions=cfg.max_chunk_functions or base.max_chunk_functions,+ max_output_tokens=cfg.max_output_tokens or base.max_output_tokens,+ )+def _split_into_chunks(self,items: list[tuple[WorkItem, str]],@@ -302,8 +313,7 @@ class Supervisor:"""Split items into chunks by building the actual prompt and measuring size."""assert self.binary_info is not None- model_name = getattr(self.llm_client, "model", "") or ""- limits = get_model_limits(model_name)+ limits = self._get_effective_limits()overhead = self._build_chunk_prompt([])overhead_len = len(overhead)diff --git a/tests/test_agent_supervisor.py b/tests/test_agent_supervisor.pyindex 1a2d998..04ecce1 100644--- a/tests/test_agent_supervisor.py+++ b/tests/test_agent_supervisor.py@@ -8,7 +8,7 @@ from kong.agent.analyzer import LLMResponsefrom kong.agent.events import EventType, Phasefrom kong.agent.models import AnalysisStats, FunctionResultfrom kong.agent.supervisor import Supervisor-from kong.config import KongConfig, OutputConfig+from kong.config import KongConfig, LLMConfig, LLMProvider, OutputConfigfrom kong.ghidra.types import BinaryInfo, FunctionClassification, FunctionInfo@@ -474,3 +474,50 @@ class TestChunkedPipelineIntegration:sup.run()assert mock_llm.analyze_function_batch.call_count == 1+++class TestGetEffectiveLimits:+ def test_non_custom_returns_base_limits(self, tmp_path):+ from kong.llm.limits import _DEFAULT_LIMITS++ config = KongConfig(+ llm=LLMConfig(provider=LLMProvider.ANTHROPIC),+ output=OutputConfig(directory=tmp_path / "out"),+ )+ sup = Supervisor(_make_client(), config)+ limits = sup._get_effective_limits()+ assert limits == _DEFAULT_LIMITS++ def test_custom_with_overrides(self, tmp_path):+ config = KongConfig(+ llm=LLMConfig(+ provider=LLMProvider.CUSTOM,+ model="llama3:8b",+ max_prompt_chars=32000,+ max_chunk_functions=20,+ max_output_tokens=4096,+ ),+ output=OutputConfig(directory=tmp_path / "out"),+ )+ sup = Supervisor(_make_client(), config)+ limits = sup._get_effective_limits()+ assert limits.max_prompt_chars == 32000+ assert limits.max_chunk_functions == 20+ assert limits.max_output_tokens == 4096++ def test_custom_partial_overrides_fall_back(self, tmp_path):+ from kong.llm.limits import _DEFAULT_LIMITS++ config = KongConfig(+ llm=LLMConfig(+ provider=LLMProvider.CUSTOM,+ model="llama3:8b",+ max_prompt_chars=32000,+ ),+ output=OutputConfig(directory=tmp_path / "out"),+ )+ sup = Supervisor(_make_client(), config)+ limits = sup._get_effective_limits()+ assert limits.max_prompt_chars == 32000+ assert limits.max_chunk_functions == _DEFAULT_LIMITS.max_chunk_functions+ assert limits.max_output_tokens == _DEFAULT_LIMITS.max_output_tokens