# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/where-must-an-instance-reject-a-capability-claim-the-a2a-v1-0-agent-card-skills-inputmodes-outputmodes-intersection-gap-during-cross-vendor-task-deleg.md # Remnant Warrant: https://corpusfetch.com/c/where-must-an-instance-reject-a-capability-claim-the-a2a-v1-0-agent-card-skills-inputmodes-outputmodes-intersection-gap-during-cross-vendor-task-deleg.warrant.json # Markdown SHA-256: 390ba4d20747ad2000b6832ec854ce14231e223fe3cec2db1705d27d8090c4aa # Code AST SHA-256: 5f81d235bf56c2c7320f7ed9f88ed9fa7d8fdd2bdfba43ff7190059ad4c5e1b9 # Verified Classes: CapabilityNegotiationError, Skill, AgentCard # Defensive Guards: 6 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) from dataclasses import dataclass, field from typing import Any class CapabilityNegotiationError(RuntimeError): """Raised when an A2A delegation violates the input/output mode contract of the single skill the client negotiated against.""" pass @dataclass class Skill: id: str input_modes: list[str] output_modes: list[str] @dataclass class AgentCard: skills: list[Skill] def skill(self, skill_id: str) -> Skill: for s in self.skills: if s.id == skill_id: return s raise CapabilityNegotiationError(f"skill {skill_id!r} not present in card") def negotiate_and_send( card: AgentCard, selected_skill_id: str, outbound_part_kinds: list[str], acceptable_response_kinds: list[str], ) -> dict[str, Any]: """Pre-send negotiation. Refuses to construct a Message when the input or output mode intersection against the *selected* skill is empty, or when the payload kind diverges from the selected skill's input modes. """ skill = card.skill(selected_skill_id) in_intersection = set(outbound_part_kinds) & set(skill.input_modes) if not in_intersection: raise CapabilityNegotiationError( f"outbound kinds {outbound_part_kinds} do not intersect " f"skill {skill.id!r} inputModes {skill.input_modes}" ) out_intersection = set(acceptable_response_kinds) & set(skill.output_modes) if not out_intersection: raise CapabilityNegotiationError( f"acceptable response kinds {acceptable_response_kinds} do not " f"intersect skill {skill.id!r} outputModes {skill.output_modes}" ) # Guard against semantic-match routing to a skill whose modes the payload # does not actually satisfy for *this* request. mismatched = set(outbound_part_kinds) - set(skill.input_modes) if mismatched: raise CapabilityNegotiationError( f"payload kinds {sorted(mismatched)} fall outside skill " f"{skill.id!r} inputModes; server may re-dispatch to a different skill" ) return { "metadata": { "x-client.skillId": skill.id, "x-client.expectOutputModes": sorted(out_intersection), }, "parts": [{"kind": k} for k in outbound_part_kinds], } def verify_response( negotiated: dict[str, Any], server_echoed_skill_id: str, response_part_kinds: list[str], ) -> None: """Post-response invariant. A task may only be marked completed if the server echoed the negotiated skill id and the response kinds intersect the negotiated output modes. Otherwise raise; do not write to memory.""" expected_skill = negotiated["metadata"]["x-client.skillId"] if server_echoed_skill_id != expected_skill: raise CapabilityNegotiationError( f"server executed skill {server_echoed_skill_id!r} but client " f"negotiated {expected_skill!r}; response shape is unverified" ) expected_out = set(negotiated["metadata"]["x-client.expectOutputModes"]) actual_out = set(response_part_kinds) if not (actual_out & expected_out): raise CapabilityNegotiationError( f"response kinds {sorted(actual_out)} do not intersect negotiated " f"output modes {sorted(expected_out)}; refusing to mark completed" )