Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
feat(vibey): name the Source a proxied search fell back from (hosted.fallback_from) (#2668)
Call White44db5177ad54
diff --git a/core/agent_core/ai/provider.py b/core/agent_core/ai/provider.pyindex 8c72c2c0f..e90a5b215 100644--- a/core/agent_core/ai/provider.py+++ b/core/agent_core/ai/provider.py@@ -46,18 +46,23 @@ class HostedToolRoute:The agent declares the tool natively exactly when Model Hub assumes the hop runs it (``native: assumed``), withthe wire ``declaration`` and the Responses ``include`` values; otherwise (``proxy``) as the same-named function,which the gateway's executor chain runs. ``replay`` is whether a hosted payload may go back verbatim to this hop.+ ``refused``: the hop's own Source would run the tool but refused it (a current refusal, C-6 ``refused``), so a call+ here is a fallback from that Source."""mode: Literal["native", "proxy"]replay: booldeclaration: Optional[Mapping[str, Any]] = Noneinclude: tuple[str, ...] = ()+ refused: bool = Falsedef __post_init__(self) -> None:if self.mode not in ("native", "proxy"):raise ValueError(f"unknown hosted tool mode: {self.mode!r}")- if not isinstance(self.replay, bool):- raise ValueError("hosted replay must be a boolean")+ if not isinstance(self.replay, bool) or not isinstance(self.refused, bool):+ raise ValueError("hosted replay and refused must be booleans")+ if self.refused and self.mode != "proxy":+ raise ValueError("a tool its Source refused runs as its function")if self.mode == "proxy":if self.declaration is not None or self.include:raise ValueError("a proxy hosted tool has no native declaration or include")diff --git a/core/agent_core/messages.py b/core/agent_core/messages.pyindex a3ec9e813..a71fd918d 100644--- a/core/agent_core/messages.py+++ b/core/agent_core/messages.py@@ -535,6 +535,19 @@ class ProxyExecution:_require(self.cost, HostedCost, "executor cost", optional=True)+@dataclass(frozen=True)+class HostedFallback:+ """The Source that refused to run a search tool natively, so the call ran as its function instead (C-6 ``refused``).+ Named by id only: a surface shows its current name."""++ source_id: str++ def __post_init__(self) -> None:+ _require(self.source_id, str, "fallback source id")+ if not _SOURCE_ID_RE.fullmatch(self.source_id):+ raise ValueError("a fallback names its Source by id")++@dataclass(frozen=True)class HostedResult:"""``ToolResultMessage.hosted``: the canonical record of a proxied search or an ``image_generate`` call.@@ -545,11 +558,15 @@ class HostedResult:record: HostedRecordexecution: Optional[ProxyExecution] = Noneaction: Optional[HostedAction] = None+ #: A search call that ran as its function only because the turn's own Source refused it natively; absent when it+ #: ran where it was declared, or where the vendor never offers the tool natively.+ fallback_from: Optional[HostedFallback] = Nonedef __post_init__(self) -> None:_require(self.record, HostedRecord, "hosted record")_require(self.execution, ProxyExecution, "proxy execution", optional=True)_require(self.action, HostedAction, "hosted result action", optional=True)+ _require(self.fallback_from, HostedFallback, "hosted fallback", optional=True)if self.execution is None and self.record.status != "failed":raise ValueError("a hosted result without an execution is a failed record")@@ -669,6 +686,8 @@ class ToolResultMessage:self.hosted.record.check_tool(self.tool_name)if self.hosted.action is not None and not self.hosted.action.fits(self.tool_name):raise ValueError(f"a {self.hosted.action.type} action does not belong to {self.tool_name}")+ if self.hosted.fallback_from is not None and self.tool_name not in HOSTED_TOOLS:+ raise ValueError(f"{self.tool_name} never falls back: only a search tool runs as its function")if self.is_error != (self.hosted.record.status in ("failed", "incomplete")):raise ValueError("a hosted result is an error exactly when its record failed or is incomplete")@@ -984,6 +1003,8 @@ def message_to_dict(message: Message) -> dict[str, Any]:]if message.hosted.action is not None:hosted_result["action"] = _action_to_dict(message.hosted.action)+ if message.hosted.fallback_from is not None:+ hosted_result["fallback_from"] = {"source_id": message.hosted.fallback_from.source_id}result["hosted"] = hosted_resultreturn resultraise TypeError(f"not a message: {type(message).__name__}")@@ -1027,7 +1048,9 @@ def message_from_dict(data: Mapping[str, Any]) -> Message:)hosted_result = Noneif "hosted" in f:- h = _read(f["hosted"], "hosted result", {"record": dict}, {"execution": dict, "action": dict})+ h = _read(+ f["hosted"], "hosted result", {"record": dict}, {"execution": dict, "action": dict, "fallback_from": dict}+ )execution = Noneif "execution" in h:e = _read(@@ -1059,10 +1082,14 @@ def message_from_dict(data: Mapping[str, Any]) -> Message:mode=e["mode"],failed_attempts=tuple(attempts),)+ fallback = None+ if "fallback_from" in h:+ fallback = HostedFallback(_read(h["fallback_from"], "hosted fallback", {"source_id": str})["source_id"])hosted_result = HostedResult(record=_record_from_dict(h["record"]),execution=execution,action=_action_from_dict(h["action"]) if "action" in h else None,+ fallback_from=fallback,)return ToolResultMessage(tool_call_id=f["tool_call_id"],diff --git a/core/handlers/model_hub/hosted_tools.py b/core/handlers/model_hub/hosted_tools.pyindex 4804a7c66..7009ecd33 100644--- a/core/handlers/model_hub/hosted_tools.py+++ b/core/handlers/model_hub/hosted_tools.py@@ -158,21 +158,25 @@ class HostedEvidence:class HostedToolFacts:"""What priors and evidence say about one search tool on one hop (§3.4).- ``declaration`` and ``include`` are set exactly when ``native`` is ``assumed``.+ ``declaration`` and ``include`` are set exactly when ``native`` is ``assumed``. ``refused`` says the tool runs on+ the hop but the hop's (Source, model) refused a call, the one ``unsupported`` a proxied call falls back from."""native: Assumptionreplay: Assumptiondeclaration: Optional[Mapping[str, Any]] = Noneinclude: tuple[str, ...] = ()+ refused: bool = Falsedef hosted_tool_facts(source: ModelHubSourceConfig, model_id: str, tool: str, *, evidence: HostedEvidence, spec_for: SpecLookup) -> HostedToolFacts:spec = runs_on(source, model_id, tool, spec_for=spec_for)- if spec is None or evidence.unsupported(source, model_id, EvidenceFeature.hosted(tool, "call")):+ if spec is None:return HostedToolFacts(native="unsupported", replay="unsupported")+ if evidence.unsupported(source, model_id, EvidenceFeature.hosted(tool, "call")):+ return HostedToolFacts(native="unsupported", replay="unsupported", refused=True)replay: Assumption = ("assumed"if "replay" in HOSTED_TOOL_ASPECTS[tool]@@ -380,6 +384,8 @@ def hop_hosted_tools(if facts.native == "assumed":entry["declaration"] = dict(facts.declaration or {})entry["include"] = list(facts.include)+ if facts.refused:+ entry["refused"] = Trueentries[tool] = entryif turn.images:entries[IMAGE_TOOL] = {diff --git a/docs/plans/agent-core-contracts/conversion-tables.md b/docs/plans/agent-core-contracts/conversion-tables.mdindex 4bb0f09ce..7b5d8e571 100644--- a/docs/plans/agent-core-contracts/conversion-tables.md+++ b/docs/plans/agent-core-contracts/conversion-tables.md@@ -680,7 +680,9 @@ These rows describe the wire mapping the `ai` lane implements.- **Proxy.** A search tool that a hop does not run natively is its canonical function, and a call to it runs on thegateway's executor chain, which the gateway resolves from the live Turn. The result keeps the record on- `ToolResultMessage.hosted`, with `execution.mode: proxy`. An `image_generate` call is an ordinary tool call and+ `ToolResultMessage.hosted`, with `execution.mode: proxy`. A call on a hop whose facts say the hop's own Source refused+ the tool natively (C-6 `refused`) also records that Source as `hosted.fallback_from: {source_id}`, by id only, so+ a surface can say where the tool fell back from; a tool the vendor never offers natively records none. An `image_generate` call is an ordinary tool call andresult everywhere, with `execution.mode: direct`; its images are files the record lists.An Anthropic citation covers its whole text block, so it carries no range.diff --git a/docs/plans/agent-core-contracts/hop-resolution.schema.json b/docs/plans/agent-core-contracts/hop-resolution.schema.jsonindex 5dab974f0..ce47eec1b 100644--- a/docs/plans/agent-core-contracts/hop-resolution.schema.json+++ b/docs/plans/agent-core-contracts/hop-resolution.schema.json@@ -135,7 +135,7 @@},"hosted_tools": {"type": "object",- "description": "One entry per hosted tool the turn declares (vibey-hosted-tools.md §3.4). A search tool's entry is the primary hop's facts: `native` is `assumed` when the tool runs on the hop (`runs_on`) and no current negative `call` evidence exists, else `unsupported`; `declaration` and `include` (the overlay's wire declaration and Responses include values) are present exactly when `native` is `assumed`; `replay` is `assumed` when `native` is, the protocol replays natively and no current negative `replay` evidence exists. `image_generate` lists the image models the user's Sources make available, default first, and is absent when the tool is off or no model is available. The turn's first resolution freezes the tool set and the image models; later hops change only `native` and `replay`. A request carrying native content is pinned with x-avibe-pin-source: source_id.",+ "description": "One entry per hosted tool the turn declares (vibey-hosted-tools.md §3.4). A search tool's entry is the primary hop's facts: `native` is `assumed` when the tool runs on the hop (`runs_on`) and no current negative `call` evidence exists, else `unsupported`; `refused` is `true` exactly when that negative `call` evidence, not `runs_on`, is why; `declaration` and `include` (the overlay's wire declaration and Responses include values) are present exactly when `native` is `assumed`; `replay` is `assumed` when `native` is, the protocol replays natively and no current negative `replay` evidence exists. `image_generate` lists the image models the user's Sources make available, default first, and is absent when the tool is off or no model is available. The turn's first resolution freezes the tool set and the image models; later hops change only `native`, `replay` and `refused`. A request carrying native content is pinned with x-avibe-pin-source: source_id.","additionalProperties": false,"properties": {"web_search": {@@ -176,6 +176,10 @@"assumed","unsupported"]+ },+ "refused": {+ "const": true,+ "description": "Present exactly when the tool runs on the hop but current negative `call` evidence for the hop's (Source, model) makes `native` `unsupported`: this Source refused it, so a proxied call is a fallback from it."}},"if": {@@ -189,7 +193,12 @@"required": ["declaration","include"- ]+ ],+ "not": {+ "required": [+ "refused"+ ]+ }},"else": {"not": {@@ -246,6 +255,10 @@"assumed","unsupported"]+ },+ "refused": {+ "const": true,+ "description": "Present exactly when the tool runs on the hop but current negative `call` evidence for the hop's (Source, model) makes `native` `unsupported`: this Source refused it, so a proxied call is a fallback from it."}},"if": {@@ -259,7 +272,12 @@"required": ["declaration","include"- ]+ ],+ "not": {+ "required": [+ "refused"+ ]+ }},"else": {"not": {diff --git a/docs/plans/agent-core-contracts/message.schema.json b/docs/plans/agent-core-contracts/message.schema.jsonindex a5c33ddf9..cf9a1ac23 100644--- a/docs/plans/agent-core-contracts/message.schema.json+++ b/docs/plans/agent-core-contracts/message.schema.json@@ -445,6 +445,20 @@},"action": {"$ref": "#/definitions/HostedAction"+ },+ "fallback_from": {+ "type": "object",+ "required": [+ "source_id"+ ],+ "additionalProperties": false,+ "description": "A search call that ran as its function only because the turn's own Source refused it natively (C-6 `refused`): that Source, by id only. Absent when the call ran where it was declared, or where the vendor never offers the tool natively.",+ "properties": {+ "source_id": {+ "type": "string",+ "pattern": "^src_[a-z0-9]{8,}$"+ }+ }}},"if": {@@ -633,6 +647,29 @@}}}+ },+ {+ "if": {+ "required": [+ "hosted"+ ],+ "properties": {+ "tool_name": {+ "const": "image_generate"+ }+ }+ },+ "then": {+ "properties": {+ "hosted": {+ "not": {+ "required": [+ "fallback_from"+ ]+ }+ }+ }+ }}]},diff --git a/docs/plans/agent-core-contracts/model-hub-consumer.md b/docs/plans/agent-core-contracts/model-hub-consumer.mdindex 41539ca23..bc1c82c76 100644--- a/docs/plans/agent-core-contracts/model-hub-consumer.md+++ b/docs/plans/agent-core-contracts/model-hub-consumer.md@@ -77,11 +77,14 @@ consumer's requirements, and the Model Hub lane lands the change in both places.exactly when `native` is `assumed`;- `replay` is `assumed` when `native` is, the protocol replays natively (`anthropic`, `openai_responses`),and no current negative `replay` evidence exists; otherwise `unsupported`;+ - `refused: true`, present exactly when the tool runs on the hop but current negative `call` evidence for the+ hop's (Source, model) makes `native` `unsupported`: that Source refused the tool, so a proxied call is a+ fallback from it. It is absent when the tool does not run on the hop;- **`image_generate`** gives `{models: [{source_id, model_id, description, params, size_forms}], default:{source_id, model_id}}`: the image models the user's Sources make available, default first. It is absent whenthe tool is off or no image model is available, so `models` is never empty.- The turn's first resolution freezes the tool set, each search tool's executor order and the image models on- the turn trace; later hops of the turn change only `native` and `replay`. A settings change applies from the+ the turn trace; later hops of the turn change only `native`, `replay` and `refused`. A settings change applies from thenext turn.- **The gateway never rewrites hosted content.** Vibey pins every request that carries a native declaration, anative hosted payload or an in-flight continuation, with `x-avibe-pin-source`.diff --git a/docs/plans/model-hub-contracts/hop-resolution.schema.json b/docs/plans/model-hub-contracts/hop-resolution.schema.jsonindex 16c3f95e5..6de2f7bfb 100644--- a/docs/plans/model-hub-contracts/hop-resolution.schema.json+++ b/docs/plans/model-hub-contracts/hop-resolution.schema.json@@ -42,7 +42,7 @@},"hosted_tools": {"type": "object",- "description": "One entry per hosted tool the turn declares (vibey-hosted-tools.md §3.4). A search tool's entry is the primary hop's facts: `native` is `assumed` when the tool runs on the hop (`runs_on`) and no current negative `call` evidence exists, else `unsupported`; `declaration` and `include` (the overlay's wire declaration and Responses include values) are present exactly when `native` is `assumed`; `replay` is `assumed` when `native` is, the protocol replays natively and no current negative `replay` evidence exists. `image_generate` lists the image models the user's Sources make available, default first, and is absent when the tool is off or no model is available. The turn's first resolution freezes the tool set and the image models; later hops change only `native` and `replay`. A request carrying native content is pinned with x-avibe-pin-source: source_id.",+ "description": "One entry per hosted tool the turn declares (vibey-hosted-tools.md §3.4). A search tool's entry is the primary hop's facts: `native` is `assumed` when the tool runs on the hop (`runs_on`) and no current negative `call` evidence exists, else `unsupported`; `refused` is `true` exactly when that negative `call` evidence, not `runs_on`, is why; `declaration` and `include` (the overlay's wire declaration and Responses include values) are present exactly when `native` is `assumed`; `replay` is `assumed` when `native` is, the protocol replays natively and no current negative `replay` evidence exists. `image_generate` lists the image models the user's Sources make available, default first, and is absent when the tool is off or no model is available. The turn's first resolution freezes the tool set and the image models; later hops change only `native`, `replay` and `refused`. A request carrying native content is pinned with x-avibe-pin-source: source_id.","additionalProperties": false,"properties": {"web_search": {@@ -83,6 +83,10 @@"assumed","unsupported"]+ },+ "refused": {+ "const": true,+ "description": "Present exactly when the tool runs on the hop but current negative `call` evidence for the hop's (Source, model) makes `native` `unsupported`: this Source refused it, so a proxied call is a fallback from it."}},"if": {@@ -96,7 +100,12 @@"required": ["declaration","include"- ]+ ],+ "not": {+ "required": [+ "refused"+ ]+ }},"else": {"not": {@@ -153,6 +162,10 @@"assumed","unsupported"]+ },+ "refused": {+ "const": true,+ "description": "Present exactly when the tool runs on the hop but current negative `call` evidence for the hop's (Source, model) makes `native` `unsupported`: this Source refused it, so a proxied call is a fallback from it."}},"if": {@@ -166,7 +179,12 @@"required": ["declaration","include"- ]+ ],+ "not": {+ "required": [+ "refused"+ ]+ }},"else": {"not": {diff --git a/modules/agents/vibey/models.py b/modules/agents/vibey/models.pyindex 5878efcc4..e80d161b5 100644--- a/modules/agents/vibey/models.py+++ b/modules/agents/vibey/models.py@@ -56,6 +56,8 @@ def _optional(value: Any, kind: type, what: str) -> Any:#: include values are present exactly when the tool is assumed to run natively._FACTS = ("assumed", "unsupported")_SEARCH_KEYS = {"assumed": {"native", "replay", "declaration", "include"}, "unsupported": {"native", "replay"}}+#: A key an ``unsupported`` entry may carry: the hop's own Source refused the tool (C-6 ``refused``).+_REFUSED_KEY = "refused"_IMAGE_KEYS = {"source_id", "model_id", "description", "params", "size_forms"}_IMAGE_PARAMS = {"size", "images", "n"}_SIZE_FORMS = {"pixels", "ratio"}@@ -88,7 +90,10 @@ def _hosted_route(tool: Any, entry: Any) -> HostedToolRoute:native, replay = entry.get("native"), entry.get("replay")if native not in _FACTS or replay not in _FACTS:raise ValueError("native and replay are each assumed or unsupported")- if set(entry) != _SEARCH_KEYS[native]:+ refused = _REFUSED_KEY in entry+ if refused and (native != "unsupported" or entry[_REFUSED_KEY] is not True):+ raise ValueError("refused is true, and only on an unsupported entry")+ if set(entry) - {_REFUSED_KEY} != _SEARCH_KEYS[native]:raise ValueError(f"a {native} entry has exactly {', '.join(sorted(_SEARCH_KEYS[native]))}")include = entry.get("include", [])if not isinstance(include, list):@@ -98,6 +103,7 @@ def _hosted_route(tool: Any, entry: Any) -> HostedToolRoute:replay=replay == "assumed",declaration=entry.get("declaration"),include=tuple(include),+ refused=refused,)diff --git a/modules/agents/vibey/tools.py b/modules/agents/vibey/tools.pyindex 36ba3cd0c..0f2bd583e 100644--- a/modules/agents/vibey/tools.py+++ b/modules/agents/vibey/tools.py@@ -30,6 +30,7 @@ from core.agent_core.ai.hosted import failure, generate_action, image_dimensionsfrom core.agent_core.ai.provider import ImageModel, ImageModels, MediaSink, ModelEndpointfrom core.agent_core.messages import (HostedAction,+ HostedFallback,HostedImage,HostedRecord,HostedResult,@@ -134,7 +135,13 @@ class HostedTool:async def execute(self, arguments: Mapping[str, Any], ctx: ToolContext) -> ToolResult:del ctx- hosted, _ = await _gateway_call(self.route(), self.client, self.spec.name, dict(arguments))+ endpoint = self.route()+ hosted, _ = await _gateway_call(endpoint, self.client, self.spec.name, dict(arguments))+ route = endpoint.hosted_tools.get(self.spec.name)+ if route is not None and route.refused and endpoint.source_id:+ # The hop's own Source would run the tool but refused it, so this call is a fallback from it (C-6+ # ``refused``): the card and the IM line say so.+ hosted = replace(hosted, fallback_from=HostedFallback(endpoint.source_id))query = arguments.get("query")return _result(self.spec.name, hosted, query=query if isinstance(query, str) else None)diff --git a/tests/agent_core/test_hosted_messages.py b/tests/agent_core/test_hosted_messages.pyindex 59e90c033..4d56aa3ff 100644--- a/tests/agent_core/test_hosted_messages.py+++ b/tests/agent_core/test_hosted_messages.py@@ -22,6 +22,7 @@ from core.agent_core.messages import (FailedAttempt,HostedAction,HostedCost,+ HostedFallback,HostedImage,HostedNative,HostedRecord,@@ -128,6 +129,8 @@ def _produced() -> list:cost=HostedCost(basis="list", usd=0.03),failed_attempts=(FailedAttempt("src_o9p8q7r6s5", "metered", HostedCost(basis="list", usd=0.01)),),),+ # The turn's own Source refused X search natively, so the call ran as its function.+ fallback_from=HostedFallback("src_relaygpt01"),),)included = ToolResultMessage(@@ -306,6 +309,10 @@ VIOLATIONS = {"proxy-billing": _set(PROXIED, ("hosted", "execution", "executor_billing"), "free"),"failed-attempt-billing": _set(PROXIED, ("hosted", "execution", "failed_attempts", 0, "billing"), "free"),"proxy-images-on-x-search": _set(PROXIED, ("hosted", "record", "images"), []),+ # Only a search tool runs as its function; an image call is always direct.+ "fallback-on-image-generate": _set(IMAGE, ("hosted", "fallback_from"), {"source_id": "src_relaygpt01"}),+ "fallback-names-no-source-id": _set(PROXIED, ("hosted", "fallback_from", "source_id"), "relay-gpt"),+ "fallback-with-a-name": _set(PROXIED, ("hosted", "fallback_from", "name"), "relay-gpt"),}diff --git a/tests/scenarios/model_hub/catalog.yaml b/tests/scenarios/model_hub/catalog.yamlindex 3d962bdd8..22799379a 100644--- a/tests/scenarios/model_hub/catalog.yaml+++ b/tests/scenarios/model_hub/catalog.yaml@@ -384,6 +384,8 @@ scenarios:test: tests/test_vibey_agent.py::test_a_proxied_hosted_call_runs_on_the_turns_executor_chain_and_keeps_its_recordrelated_tests:- tests/test_vibey_agent.py::test_a_proxied_call_after_the_turn_moved_to_another_source_runs_on_the_hop_it_now_holds+ - tests/test_vibey_agent.py::test_a_proxied_search_names_the_source_that_refused_it+ - tests/test_vibey_agent.py::test_a_search_its_source_refused_names_that_source_through_the_real_gateway- id: MH-HOSTED-VIBEY-005name: A hosted call goes back verbatim and pinned only to the Source that served it, within its turn while the hop still declares the tool natively or with current replay evidence; a refusal before any output (pin_unavailable, xAI's decrypt refusal) ends the send, and the loop renders the request again for a fresh hop within its bounds, portable only as the last resortstatus: covereddiff --git a/tests/test_model_hub_hosted_tools_resolution.py b/tests/test_model_hub_hosted_tools_resolution.pyindex 543241f4c..3d0ca4891 100644--- a/tests/test_model_hub_hosted_tools_resolution.py+++ b/tests/test_model_hub_hosted_tools_resolution.py@@ -140,25 +140,31 @@ def _evidence(tmp_path, *refused) -> HostedEvidence:@pytest.mark.parametrize(- "primary,tool,refused,native,replay",+ "primary,tool,refused,native,replay,fallback",[# The overlay offers it and nothing refused it: assumed, with no evidence at all.- (XAI, "web_search", (), "assumed", "assumed"),- (XAI, "web_search", ((XAI, "grok-4.6", "web_search", "replay"),), "assumed", "unsupported"),- (XAI, "web_search", ((XAI, "grok-4.6", "web_search", "call"),), "unsupported", "unsupported"),- # OpenAI offers no X search: the function, whatever the evidence.- (OPENAI, "x_search", (), "unsupported", "unsupported"),- (CLAUDE_SUB, "web_search", (), "unsupported", "unsupported"),- (GEMINI, "web_search", (), "unsupported", "unsupported"),+ (XAI, "web_search", (), "assumed", "assumed", False),+ (XAI, "web_search", ((XAI, "grok-4.6", "web_search", "replay"),), "assumed", "unsupported", False),+ # This Source refused it: a proxied call falls back from it.+ (XAI, "web_search", ((XAI, "grok-4.6", "web_search", "call"),), "unsupported", "unsupported", True),+ # OpenAI offers no X search: the function, whatever the evidence, and never a fallback.+ (OPENAI, "x_search", (), "unsupported", "unsupported", False),+ (OPENAI, "x_search", ((OPENAI, "gpt-6-astra", "x_search", "call"),), "unsupported", "unsupported", False),+ (CLAUDE_SUB, "web_search", (), "unsupported", "unsupported", False),+ (GEMINI, "web_search", (), "unsupported", "unsupported", False),+ ],+ ids=[+ "assumed", "replay-refused", "call-refused", "not-offered", "not-offered-refused",+ "claude-subscription-never", "translated-never",],- ids=["assumed", "replay-refused", "call-refused", "not-offered", "claude-subscription-never", "translated-never"],)-def test_a_hops_facts_come_from_priors_and_refusals(tmp_path, primary, tool, refused, native, replay):- """MH-HOSTED-001: nothing is probed; a tool is assumed where offered until a real request refuses it."""+def test_a_hops_facts_come_from_priors_and_refusals(tmp_path, primary, tool, refused, native, replay, fallback):+ """MH-HOSTED-001: nothing is probed; a tool is assumed where offered until a real request refuses it, and only+ that refusal marks the hop as the one a proxied call falls back from."""facts = hosted_tool_facts(primary, primary.models[0].id, tool, evidence=_evidence(tmp_path, *refused), spec_for=_spec_for,)- assert (facts.native, facts.replay) == (native, replay)+ assert (facts.native, facts.replay, facts.refused) == (native, replay, fallback)assert (facts.declaration is not None) is (native == "assumed")@@ -232,6 +238,11 @@ def test_a_turn_freezes_its_tools_executors_and_image_enum_and_each_hop_states_i"default": {"source_id": "src_xai00001", "model_id": "grok-imagine-image"},},}+ # A hop whose Source refused a tool says so; the image enum stays the turn's.+ refused = _evidence(tmp_path / "r", (XAI, "grok-4.6", "web_search", "call"))+ assert hop_hosted_tools(turn, XAI, "grok-4.6", evidence=refused, spec_for=_spec_for)["web_search"] == {+ "native": "unsupported", "replay": "unsupported", "refused": True,+ }# Off, or with no image model available, a tool is not declared at all.off = _config({"x_search": ModelHubHostedToolConfig(enabled=False)}, sources=[CLAUDE_SUB, OPENAI, GEMINI])turn = freeze_turn_tools(diff --git a/tests/test_vibey_agent.py b/tests/test_vibey_agent.pyindex b4ecd6632..e0df49756 100644--- a/tests/test_vibey_agent.py+++ b/tests/test_vibey_agent.py@@ -3100,6 +3100,8 @@ def _without(entry: dict, key: str) -> dict:{"web_search": {**_NATIVE_SEARCH, "native": []}},{"web_search": {**_NATIVE_SEARCH, "include": "web_search_call.action.sources"}},{"web_search": {**_PROXY_SEARCH, "executor": None}},+ {"web_search": {**_PROXY_SEARCH, "refused": False}},+ {"web_search": {**_NATIVE_SEARCH, "refused": True}},{"image_generate": {**_IMAGES, "models": []}},{"image_generate": {**_IMAGES, "default": {"source_id": "src_executor01", "model_id": "grok-imagine"}}},{"image_generate": {**_IMAGES, "models": [{**_IMAGES["models"][0], "params": ["quality"]}]}},@@ -3107,7 +3109,8 @@ def _without(entry: dict, key: str) -> dict:],ids=["absent", "unknown-tool", "assumed-without-declaration", "unsupported-with-include", "extra-field",- "no-replay", "unknown-fact", "unhashable-fact", "include-not-a-list", "v1-executor", "no-image-models",+ "no-replay", "unknown-fact", "unhashable-fact", "include-not-a-list", "v1-executor", "refused-not-true",+ "refused-on-a-native-tool", "no-image-models","default-not-first", "unknown-image-param", "image-source-not-a-source-id",],)@@ -3126,6 +3129,80 @@ def test_a_hop_with_an_invalid_hosted_tool_entry_is_refused(hosted_tools) -> Nonselection_from_hop(hop)[email protected]("refused", [True, False], ids=["refused-by-its-source", "never-offered-natively"])+async def test_a_proxied_search_names_the_source_that_refused_it(refused) -> None:+ """MH-HOSTED-VIBEY-004 (vibey-hosted-tools.md §3.5): a search call runs as its function either because the turn's+ own Source refused the tool natively (C-6 ``refused``) or because its vendor never offers it. Only the first is a+ fallback: the result names that Source by id, which the card and the IM line show by its current name."""+ import httpx++ from core.agent_core.messages import HostedFallback+ from core.agent_core.tools.hosted import hosted_tool_spec+ from modules.agents.vibey.models import selection_from_hop+ from modules.agents.vibey.tools import HostedTool++ hop = ModelHubLaunch(+ backend="vibey", channel="hub", requested_model="relay-gpt", target_model="relay-gpt",+ runtime_model="gpt-6-astra", context_window=200000, max_output_tokens=4096, supports_tools=True,+ source_id="src_relaygpt01", source_identity="sha256:relay-identity",+ gateway_base_url="http://hub.invalid/vibey", gateway_token="hub-token",+ protocol="openai_responses", provider="openai",+ ).to_hop_resolution()+ hop["hosted_tools"] = {"web_search": {"native": "unsupported", "replay": "unsupported", **({"refused": True} if refused else {})}}+ endpoint = selection_from_hop(hop).endpoint+ answer = {"record": {"status": "completed", "sources": []}, "execution": {+ "mode": "proxy", "executor_origin": {"provider": "anthropic", "api": "anthropic", "model": "claude-haiku-5-5"},+ "executor_source_id": "src_relayclaude1", "executor_billing": "metered",+ }}+ async with httpx.AsyncClient(transport=httpx.MockTransport(lambda _: httpx.Response(200, json=answer))) as client:+ result = await HostedTool(hosted_tool_spec("web_search"), lambda: endpoint, client).execute({"query": "q"}, None) # type: ignore[arg-type]++ assert result.hosted.fallback_from == (HostedFallback("src_relaygpt01") if refused else None)+ assert result.hosted.execution.executor_source_id == "src_relayclaude1"+++async def test_a_search_its_source_refused_names_that_source_through_the_real_gateway(tmp_path, monkeypatch) -> None:+ """MH-HOSTED-VIBEY-004, closed loop at the seam: the gateway holds a current refusal of web search natively on the+ turn's Source, so the hop it resolves says ``refused``; Vibey's proxied search runs on the executor chain and names+ that Source as where it fell back from (``hosted.fallback_from``), by id."""+ import httpx++ from core.handlers.model_hub import hosted_tools as hosted_tools_module+ from core.handlers.model_hub.capability_evidence import EvidenceFeature+ from core.handlers.model_hub.turn_gateway import ModelHubTurnGateway+ from core.agent_core.messages import HostedFallback+ from config.v2_config import ModelHubHostedToolConfig+ from modules.agents.model_hub import ModelHubRuntimeRouter+ from modules.agents.vibey.models import HubModelRouter, selection_from_hop+ from modules.agents.vibey.tools import hosted_tools+ from tests.test_model_hub_hosted_executor import OPENAI, XAI, _served_by_openai, _sources+ from tests.test_model_hub_vibey_consumer import _vibey_service++ monkeypatch.setattr(hosted_tools_module, "provider_executor_model", {"openai": "gpt-6-astra"}.get)+ service = _vibey_service(tmp_path, _sources(), handles=[_served_by_openai()])+ service.store.config.hosted_tools["web_search"] = ModelHubHostedToolConfig(enabled=True, executor_order=(OPENAI,))+ xai = next(source for source in service.store.config.sources if source.id == XAI)+ await service.record_hosted_refusals(xai, [("grok-4.6", EvidenceFeature.hosted("web_search", "call"), "refused")])+ gateway = ModelHubTurnGateway(service)+ hub = ModelHubRuntimeRouter(service=service, turn_gateway=gateway)++ async def resolve():+ return selection_from_hop(await hub.resolve_hop("menu-alias", process_scope="vibey:fallback", turn_id="turn-fb"))++ try:+ router = HubModelRouter(resolve, lambda protocol: None, first=await resolve())+ assert router.preflight.endpoint.source_id == XAI and router.preflight.endpoint.hosted_tools["web_search"].refused+ async with httpx.AsyncClient(trust_env=False) as client:+ (search,) = [tool for tool in hosted_tools(router, client) if tool.spec.name == "web_search"]+ result = await search.execute({"query": "q"}, None) # type: ignore[arg-type]+ finally:+ await gateway.close()++ assert not result.is_error, result.content[0].text+ assert result.hosted.fallback_from == HostedFallback(XAI)+ assert result.hosted.execution.executor_source_id == OPENAI++# How a stream breaks off: the connection simply ends, or CLIProxyAPI (Model Hub's engine) reports the upstream# closing before its terminal in its own frame, byte for byte, which Model Hub forwards as it is._THINKING_DROPS = {