feat: add bounded marketplace research
This commit is contained in:
@@ -39,6 +39,13 @@ replacement = """ tool_call_iterations = 0
|
||||
max_single_tool_result_chars = 12000
|
||||
max_total_tool_result_chars = 64000
|
||||
tool_result_chars_used = 0
|
||||
marketplace_research = bool(
|
||||
(metadata or {}).get('mikeai_marketplace_research', False)
|
||||
)
|
||||
marketplace_search_executions = 0
|
||||
marketplace_fetch_executions = 0
|
||||
max_marketplace_search_executions = 3
|
||||
max_marketplace_fetch_executions = 5
|
||||
tool_execution_counts = {}
|
||||
tool_signature_counts = {}
|
||||
max_tool_call_iterations = getattr(
|
||||
@@ -61,6 +68,13 @@ replacement = """ response_tool_calls = tool_calls.pop(0)
|
||||
for candidate in response_tool_calls:
|
||||
function = candidate.get('function') or candidate
|
||||
tool_name = function.get('name') or candidate.get('name') or 'unknown'
|
||||
normalized_tool_name = tool_name.casefold()
|
||||
is_marketplace_search = normalized_tool_name in ('search', 'search_web', 'research') or normalized_tool_name.endswith(
|
||||
('web-general-local_search', 'web-general-local_research')
|
||||
)
|
||||
is_marketplace_fetch = normalized_tool_name in ('fetch_url', 'scrape_urls') or normalized_tool_name.endswith(
|
||||
'web-general-local_scrape_urls'
|
||||
)
|
||||
arguments = function.get('arguments') or candidate.get('arguments') or ''
|
||||
signature = f'{tool_name}:{arguments}'
|
||||
if tool_call_executions + len(accepted_tool_calls) >= max_tool_call_executions:
|
||||
@@ -75,7 +89,27 @@ replacement = """ response_tool_calls = tool_calls.pop(0)
|
||||
skipped_tool_calls.append(candidate)
|
||||
skip_reasons.append(f'repeated identical call suppressed for {tool_name}')
|
||||
continue
|
||||
if (
|
||||
marketplace_research
|
||||
and is_marketplace_search
|
||||
and marketplace_search_executions >= max_marketplace_search_executions
|
||||
):
|
||||
skipped_tool_calls.append(candidate)
|
||||
skip_reasons.append('marketplace search budget reached')
|
||||
continue
|
||||
if (
|
||||
marketplace_research
|
||||
and is_marketplace_fetch
|
||||
and marketplace_fetch_executions >= max_marketplace_fetch_executions
|
||||
):
|
||||
skipped_tool_calls.append(candidate)
|
||||
skip_reasons.append('marketplace fetch budget reached')
|
||||
continue
|
||||
accepted_tool_calls.append(candidate)
|
||||
if marketplace_research and is_marketplace_search:
|
||||
marketplace_search_executions += 1
|
||||
if marketplace_research and is_marketplace_fetch:
|
||||
marketplace_fetch_executions += 1
|
||||
tool_signature_counts[signature] = tool_signature_counts.get(signature, 0) + 1
|
||||
tool_execution_counts[tool_name] = tool_execution_counts.get(tool_name, 0) + 1
|
||||
response_tool_calls = accepted_tool_calls
|
||||
|
||||
Reference in New Issue
Block a user