"""The A2A agent card, derived from the dependency graph and settings.""" from __future__ import annotations from typing import Any from a2a.server.request_handlers.response_helpers import agent_card_to_dict from a2a.types import ( AgentCapabilities, AgentCard, AgentInterface, AgentProvider, AgentSkill, ) from execution_engine.config import Settings from execution_engine.workflows.workflow import CardText, Workflow A2A_PATH = "/a2a" def input_contract(workflow: Workflow) -> dict[str, Any]: """The fields every Execution starts from, as KAB reads them from a skill. KAB's workflow builder draws a step's inputs from `skills[0].inputSchema` and sends each as message metadata (`inputArrives: as_fields`). Neither is an A2A field, so they are added to the served card, not to the typed one. """ return { "inputArrives": "as_fields", "inputSchema": { "type": "object", "properties": { "request": { "type": "string", "description": f"What is wanted, in the customer's words: {workflow.subject}.", }, "customer_case": { "type": "string", "description": "The Customer case's short slug. A spec names its own.", }, "scope": { "type": "string", "uiFieldType": "textarea", "description": "The spec to start from, as a YAML or JSON document.", }, "pre_approved": { "type": "boolean", "default": True, "description": ( "Treat every Approval as granted. A platform step cannot " "answer the agent's questions, so leave it on there." ), }, }, "required": ["customer_case"], }, } def card_document(card: AgentCard, workflow: Workflow) -> dict[str, Any]: """The card as served: the A2A card, with the input contract on its skill.""" document = agent_card_to_dict(card) document["skills"][0].update(input_contract(workflow)) return document def build_agent_card(settings: Settings, workflow: Workflow) -> AgentCard: base_url = ( settings.A2A_PUBLIC_URL or f"http://{settings.A2A_HOST}:{settings.A2A_PORT}" ).rstrip("/") phases = "; ".join( f"{phase}: {', '.join(str(kind) for kind in workflow.deliverables_in(phase))}" for phase in workflow.phases ) text = workflow.card or CardText( description=f"Produces {workflow.subject} with you, Phase by Phase.", skill_id=workflow.name, skill_name=workflow.name, ) return AgentCard( name=settings.AGENT_NAME, description=f"{text.description} Cloud provider: {settings.CLOUD_PROVIDER}.", version=settings.AGENT_VERSION, provider=AgentProvider( organization="Kyndryl Agent Builder", url="https://www.kyndryl.com" ), supported_interfaces=[ AgentInterface( url=f"{base_url}{A2A_PATH}", protocol_binding="JSONRPC", protocol_version="1.0", ) ], capabilities=AgentCapabilities(streaming=True, push_notifications=False), default_input_modes=["text/plain", "application/json"], default_output_modes=["text/plain", "text/markdown", "application/json"], skills=[ AgentSkill( id=text.skill_id, name=text.skill_name, description=( "Interactive, multi-turn engagement. Phases and their Deliverables: " f"{phases}. Each Phase needs your approval, sent as data." ), tags=[*text.tags, settings.CLOUD_PROVIDER], examples=list(text.examples), input_modes=["text/plain", "application/json"], output_modes=["text/plain", "text/markdown", "application/json"], ) ], )