mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-15 03:12:21 +02:00
Consolidate Odysseus agent harness and tool contracts
This commit is contained in:
@@ -16,6 +16,8 @@ MODEL_CHOICE_MODEL = 'odysseus-qwen3.5-tools-pre-heretic'
|
||||
WEB_REFERENCE = re.compile(
|
||||
r'https?://[^\s<>]+'
|
||||
r'|(?<![\w@./-])(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+'
|
||||
r'(?!(?:txt|md|json|csv|tsv|ya?ml|xml|log|pdf|docx?|xlsx?|pptx?|'
|
||||
r'png|jpe?g|gif|webp|svg|py|js|ts|css|html?)(?![a-z]))'
|
||||
r'[a-z]{2,63}(?![\w@.-])', re.I,
|
||||
)
|
||||
|
||||
@@ -68,18 +70,125 @@ def select_experiment_inventory(inventory, routed, history, mode, *, user_text='
|
||||
families.update(url_family)
|
||||
research_family = {'research'} if mode == MODEL_CHOICE_MODE and has_research_hint(user_text) else set()
|
||||
families.update(research_family)
|
||||
families.update(recently_executed_families(
|
||||
history, user_turns=6, maximum=3,
|
||||
include_failed_attempts=mode == MODEL_CHOICE_MODE,
|
||||
))
|
||||
explicit_image_edit = (
|
||||
mode == MODEL_CHOICE_MODE
|
||||
and routed.capabilities == frozenset({'image_editing'})
|
||||
and routed.required_read_operation is None
|
||||
and any(canonical_tool(name) == 'edit_image' for name in routed.required)
|
||||
)
|
||||
if not explicit_image_edit:
|
||||
families.update(recently_executed_families(
|
||||
history, user_turns=6, maximum=3,
|
||||
include_failed_attempts=mode == MODEL_CHOICE_MODE,
|
||||
))
|
||||
names = set().union(*(FAMILY_TOOLS.get(f, ()) for f in families))
|
||||
offered = frozenset(n for n in inventory.offered
|
||||
if mode == 'all' or canonical_tool(n) in names)
|
||||
# The model-choice rollout was intentionally launched without lexical
|
||||
# tool forcing so we could observe the fine-tuned model's own selection.
|
||||
# Replays now show a narrower failure boundary: the model sometimes
|
||||
# ignores an already-resolved, read-only list/search/repeat operation and
|
||||
# fabricates or emits an empty lead-in. Preserve only the router's sealed
|
||||
# safe-read operation in this model-specific mode. Ambiguous requests still
|
||||
# have no operation and remain model-selected; mutation authority is
|
||||
# unchanged.
|
||||
sealed_read = (
|
||||
routed.required_read_operation if mode == MODEL_CHOICE_MODE else None
|
||||
)
|
||||
sealed_read_required = frozenset(
|
||||
name for name in offered
|
||||
if sealed_read is not None
|
||||
and canonical_tool(name) == canonical_tool(sealed_read.tool)
|
||||
)
|
||||
if sealed_read is not None and not sealed_read_required:
|
||||
# Never retain an operation whose own tool was removed by permissions.
|
||||
# A different required action cannot satisfy this invariant.
|
||||
sealed_read = None
|
||||
sealed_required = sealed_read_required
|
||||
explicit_cookbook_action = (
|
||||
mode == MODEL_CHOICE_MODE
|
||||
and routed.capabilities == frozenset({'cookbook_admin'})
|
||||
and {
|
||||
canonical_tool(name) for name in routed.required
|
||||
} <= {'download_model', 'serve_preset', 'stop_served_model'}
|
||||
and bool(routed.required)
|
||||
)
|
||||
if explicit_cookbook_action:
|
||||
sealed_required |= frozenset(
|
||||
name for name in offered
|
||||
if canonical_tool(name) in {
|
||||
canonical_tool(required) for required in routed.required
|
||||
}
|
||||
)
|
||||
if explicit_image_edit:
|
||||
# An explicit supported image edit has one execution owner. Preserve
|
||||
# that typed requirement so prose cannot fabricate or refuse an
|
||||
# operation the user clearly requested and the backend can perform.
|
||||
sealed_required |= frozenset(
|
||||
name for name in offered if canonical_tool(name) == 'edit_image'
|
||||
)
|
||||
explicit_web_read = (
|
||||
mode == MODEL_CHOICE_MODE
|
||||
and routed.capabilities == frozenset({'search_browser'})
|
||||
and bool(routed.required)
|
||||
and {
|
||||
canonical_tool(name) for name in routed.required
|
||||
} <= {'web_search', 'web_fetch'}
|
||||
)
|
||||
if explicit_web_read:
|
||||
# Search discovery and page retrieval are distinct read-only
|
||||
# operations. Once the turn router resolves one exactly, retaining
|
||||
# the whole warm web family lets the model substitute browser
|
||||
# navigation or repeat an old search. Preserve the resolved read while
|
||||
# leaving genuinely ambiguous web turns model-selected.
|
||||
required_web_names = {
|
||||
canonical_tool(required) for required in routed.required
|
||||
}
|
||||
# Keep one immutable recovery-capable set. The resolved reader still
|
||||
# executes first, but a failed/empty brokered read may recover through
|
||||
# page fetch or the private browser without rebuilding the contract.
|
||||
# This avoids both premature abandonment and mid-turn permission
|
||||
# expansion.
|
||||
recovery_names = set(required_web_names) | {'private_browser'}
|
||||
if 'web_search' in required_web_names:
|
||||
recovery_names.add('web_fetch')
|
||||
offered = frozenset(
|
||||
name for name in offered
|
||||
if canonical_tool(name) in recovery_names
|
||||
)
|
||||
sealed_required |= frozenset(
|
||||
name for name in offered
|
||||
if canonical_tool(name) in required_web_names
|
||||
)
|
||||
explicit_model_call = (
|
||||
mode == MODEL_CHOICE_MODE
|
||||
and bool(routed.required)
|
||||
and {
|
||||
canonical_tool(name) for name in routed.required
|
||||
} == {'chat_with_model'}
|
||||
)
|
||||
if explicit_model_call:
|
||||
offered = frozenset(
|
||||
name for name in offered if canonical_tool(name) == 'chat_with_model'
|
||||
)
|
||||
sealed_required |= offered
|
||||
explicit_chat_history_search = (
|
||||
mode == MODEL_CHOICE_MODE
|
||||
and bool(routed.required)
|
||||
and {
|
||||
canonical_tool(name) for name in routed.required
|
||||
} == {'search_chats'}
|
||||
)
|
||||
if explicit_chat_history_search:
|
||||
offered = frozenset(
|
||||
name for name in offered if canonical_tool(name) == 'search_chats'
|
||||
)
|
||||
sealed_required |= offered
|
||||
return replace(
|
||||
inventory, offered=offered, required=frozenset(),
|
||||
inventory, offered=offered, required=sealed_required,
|
||||
schema_json=tuple(s for s in inventory.schema_json
|
||||
if json.loads(s)['function']['name'] in offered),
|
||||
required_read_operation=None, routing_experiment=mode,
|
||||
required_read_operation=sealed_read, routing_experiment=mode,
|
||||
# Available families are not mutation authorization. Keep the original
|
||||
# request's authority; selection only changes what the model can see.
|
||||
active_capabilities=routed.active_capabilities | frozenset(url_family | research_family),
|
||||
|
||||
Reference in New Issue
Block a user